From 8c68cdf4a8aa624acef7cdb17560cf6c8762a4d7 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Thu, 5 Jan 2012 15:57:54 +0100 Subject: [PATCH] Fixed Vector[2D].transform2D not using the aboutX/Z arguments properly. --- src/main/java/com/sk89q/worldedit/Vector.java | 21 +++++++++++-------- .../java/com/sk89q/worldedit/Vector2D.java | 18 +++++++++------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/Vector.java b/src/main/java/com/sk89q/worldedit/Vector.java index 90efecfe7..7d18af90c 100644 --- a/src/main/java/com/sk89q/worldedit/Vector.java +++ b/src/main/java/com/sk89q/worldedit/Vector.java @@ -577,22 +577,25 @@ public class Vector { * 2D transformation. * * @param angle in degrees - * @param aboutX - * @param aboutZ - * @param translateX - * @param translateZ + * @param aboutX about which x coordinate to rotate + * @param aboutZ about which z coordinate to rotate + * @param translateX what to add after rotation + * @param translateZ what to add after rotation * @return */ public Vector transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { angle = Math.toRadians(angle); - double x = this.x; - double z = this.z; + double x = this.x - aboutX; + double z = this.z - aboutZ; double x2 = x * Math.cos(angle) - z * Math.sin(angle); double z2 = x * Math.sin(angle) + z * Math.cos(angle); - return new Vector(x2 + aboutX + translateX, - y, - z2 + aboutZ + translateZ); + + return new Vector( + x2 + aboutX + translateX, + y, + z2 + aboutZ + translateZ + ); } /** diff --git a/src/main/java/com/sk89q/worldedit/Vector2D.java b/src/main/java/com/sk89q/worldedit/Vector2D.java index 8f251820c..a00e3ba95 100644 --- a/src/main/java/com/sk89q/worldedit/Vector2D.java +++ b/src/main/java/com/sk89q/worldedit/Vector2D.java @@ -503,21 +503,23 @@ public class Vector2D { * 2D transformation. * * @param angle in degrees - * @param aboutX - * @param aboutZ - * @param translateX - * @param translateZ + * @param aboutX about which x coordinate to rotate + * @param aboutZ about which z coordinate to rotate + * @param translateX what to add after rotation + * @param translateZ what to add after rotation * @return */ public Vector2D transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { angle = Math.toRadians(angle); - double x = this.x; - double z = this.z; + double x = this.x - aboutX; + double z = this.z - aboutZ; double x2 = x * Math.cos(angle) - z * Math.sin(angle); double z2 = x * Math.sin(angle) + z * Math.cos(angle); - return new Vector2D(x2 + aboutX + translateX, - z2 + aboutZ + translateZ); + return new Vector2D( + x2 + aboutX + translateX, + z2 + aboutZ + translateZ + ); } /**