From c099ae5eb5f6c4c53589b370ba0fd28df0206c8f Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Tue, 3 Jan 2012 03:54:01 +0100 Subject: [PATCH] Added floor, ceil and round to Vector and Vector2D. --- src/main/java/com/sk89q/worldedit/Vector.java | 27 +++++++++++++++++++ .../java/com/sk89q/worldedit/Vector2D.java | 27 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/main/java/com/sk89q/worldedit/Vector.java b/src/main/java/com/sk89q/worldedit/Vector.java index 6fbcb4165..dcc36cc5d 100644 --- a/src/main/java/com/sk89q/worldedit/Vector.java +++ b/src/main/java/com/sk89q/worldedit/Vector.java @@ -546,6 +546,33 @@ public class Vector { return new Vector(x, Math.max(min, Math.min(max, y)), z); } + /** + * Rounds all components down. + * + * @return + */ + public Vector floor() { + return new Vector(Math.floor(x), Math.floor(y), Math.floor(z)); + } + + /** + * Rounds all components up. + * + * @return + */ + public Vector ceil() { + return new Vector(Math.ceil(x), Math.ceil(y), Math.ceil(z)); + } + + /** + * Rounds all components to the closest integer. + * + * @return + */ + public Vector round() { + return new Vector(Math.floor(x + 0.5), Math.floor(y + 0.5), Math.floor(z + 0.5)); + } + /** * 2D transformation. * diff --git a/src/main/java/com/sk89q/worldedit/Vector2D.java b/src/main/java/com/sk89q/worldedit/Vector2D.java index 0f2fb37fc..fc0cc2a0a 100644 --- a/src/main/java/com/sk89q/worldedit/Vector2D.java +++ b/src/main/java/com/sk89q/worldedit/Vector2D.java @@ -472,6 +472,33 @@ public class Vector2D { && getBlockZ() >= min.getBlockZ() && getBlockZ() <= max.getBlockZ(); } + /** + * Rounds all components down. + * + * @return + */ + public Vector2D floor() { + return new Vector2D(Math.floor(x), Math.floor(z)); + } + + /** + * Rounds all components up. + * + * @return + */ + public Vector2D ceil() { + return new Vector2D(Math.ceil(x), Math.ceil(z)); + } + + /** + * Rounds all components to the closest integer. + * + * @return + */ + public Vector2D round() { + return new Vector2D(Math.floor(x + 0.5), Math.floor(z + 0.5)); + } + /** * 2D transformation. *