From 9feafcfc30c073d43bebb417b8a08528719d8992 Mon Sep 17 00:00:00 2001 From: sk89q Date: Tue, 15 Jul 2014 20:10:14 -0700 Subject: [PATCH] Convert newer API from radians to degrees. --- .../sk89q/worldedit/bukkit/BukkitAdapter.java | 12 +++++------ .../sk89q/worldedit/bukkit/BukkitPlayer.java | 4 ++-- .../sk89q/worldedit/forge/ForgeEntity.java | 4 ++-- .../sk89q/worldedit/forge/ForgePlayer.java | 4 ++-- .../com/sk89q/worldedit/forge/ForgeWorld.java | 2 +- src/main/java/com/sk89q/worldedit/Vector.java | 7 +++---- .../java/com/sk89q/worldedit/Vector2D.java | 3 +-- .../worldedit/command/ClipboardCommands.java | 6 +++--- .../extent/clipboard/io/SchematicWriter.java | 4 ++-- .../math/transform/AffineTransform.java | 3 +++ .../com/sk89q/worldedit/util/Location.java | 20 +++++++++---------- .../world/storage/NBTConversions.java | 2 +- 12 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index 970136368..c9de48b73 100644 --- a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -78,8 +78,8 @@ final class BukkitAdapter { return new com.sk89q.worldedit.util.Location( adapt(location.getWorld()), position, - (float) Math.toRadians(location.getYaw()), - (float) Math.toRadians(location.getPitch())); + location.getYaw(), + location.getPitch()); } /** @@ -94,8 +94,8 @@ final class BukkitAdapter { return new org.bukkit.Location( adapt((World) location.getExtent()), position.getX(), position.getY(), position.getZ(), - (float) Math.toDegrees(location.getYaw()), - (float) Math.toDegrees(location.getPitch())); + location.getYaw(), + location.getPitch()); } /** @@ -126,8 +126,8 @@ final class BukkitAdapter { return new org.bukkit.Location( world, location.getX(), location.getY(), location.getZ(), - (float) Math.toDegrees(location.getYaw()), - (float) Math.toDegrees(location.getPitch())); + location.getYaw(), + location.getPitch()); } /** diff --git a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 8f82aa371..519aee885 100644 --- a/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -183,8 +183,8 @@ public class BukkitPlayer extends LocalPlayer { return new com.sk89q.worldedit.util.Location( getWorld(), position, - (float) Math.toRadians(nativeLocation.getYaw()), - (float) Math.toRadians(nativeLocation.getPitch())); + nativeLocation.getYaw(), + nativeLocation.getPitch()); } @Nullable diff --git a/src/forge/java/com/sk89q/worldedit/forge/ForgeEntity.java b/src/forge/java/com/sk89q/worldedit/forge/ForgeEntity.java index cf96d9400..44ca0a666 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/ForgeEntity.java +++ b/src/forge/java/com/sk89q/worldedit/forge/ForgeEntity.java @@ -65,8 +65,8 @@ class ForgeEntity implements Entity { @Override public Location getLocation() { Vector position = new Vector(entity.posX, entity.posY, entity.posZ); - float yaw = (float) Math.toRadians(entity.rotationYaw); - float pitch = (float) Math.toRadians(entity.rotationPitch); + float yaw = entity.rotationYaw; + float pitch = entity.rotationPitch; return new Location(ForgeAdapter.adapt(entity.worldObj), position, yaw, pitch); } diff --git a/src/forge/java/com/sk89q/worldedit/forge/ForgePlayer.java b/src/forge/java/com/sk89q/worldedit/forge/ForgePlayer.java index 10e4af4a5..327b03602 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/ForgePlayer.java +++ b/src/forge/java/com/sk89q/worldedit/forge/ForgePlayer.java @@ -63,8 +63,8 @@ public class ForgePlayer extends AbstractPlayerActor { return new Location( ForgeWorldEdit.inst.getWorld(this.player.worldObj), position, - (float) Math.toRadians(this.player.cameraYaw), - (float) Math.toRadians(this.player.cameraPitch)); + this.player.cameraYaw, + this.player.cameraPitch); } public WorldVector getPosition() { diff --git a/src/forge/java/com/sk89q/worldedit/forge/ForgeWorld.java b/src/forge/java/com/sk89q/worldedit/forge/ForgeWorld.java index 8b1f2c563..ac63f7818 100644 --- a/src/forge/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/src/forge/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -414,7 +414,7 @@ public class ForgeWorld extends AbstractWorld { createdEntity.readFromNBT(tag); } - createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), (float) Math.toDegrees(location.getYaw()), (float) Math.toDegrees(location.getPitch())); + createdEntity.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); world.spawnEntityInWorld(createdEntity); return new ForgeEntity(createdEntity); diff --git a/src/main/java/com/sk89q/worldedit/Vector.java b/src/main/java/com/sk89q/worldedit/Vector.java index 5585e9961..c1fd0475e 100644 --- a/src/main/java/com/sk89q/worldedit/Vector.java +++ b/src/main/java/com/sk89q/worldedit/Vector.java @@ -600,8 +600,7 @@ public class Vector implements Comparable { * @param translateZ what to add after rotation * @return */ - public Vector transform2D(double angle, - double aboutX, double aboutZ, double translateX, double translateZ) { + public Vector transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { angle = Math.toRadians(angle); double x = this.x - aboutX; double z = this.z - aboutZ; @@ -667,7 +666,7 @@ public class Vector implements Comparable { double x2 = x * x; double z2 = z * z; double xz = Math.sqrt(x2 + z2); - return (float) Math.atan(-getY() / xz); + return (float) Math.toDegrees(Math.atan(-getY() / xz)); } } @@ -683,7 +682,7 @@ public class Vector implements Comparable { double t = Math.atan2(-x, z); double _2pi = 2 * Math.PI; - return (float) ((t + _2pi) % _2pi); + return (float) Math.toDegrees(((t + _2pi) % _2pi)); } /** diff --git a/src/main/java/com/sk89q/worldedit/Vector2D.java b/src/main/java/com/sk89q/worldedit/Vector2D.java index 6bb9d7eed..77ba862a1 100644 --- a/src/main/java/com/sk89q/worldedit/Vector2D.java +++ b/src/main/java/com/sk89q/worldedit/Vector2D.java @@ -517,8 +517,7 @@ public class Vector2D { * @param translateZ what to add after rotation * @return */ - public Vector2D transform2D(double angle, - double aboutX, double aboutZ, double translateX, double translateZ) { + public Vector2D transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { angle = Math.toRadians(angle); double x = this.x - aboutX; double z = this.z - aboutZ; diff --git a/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index a2330ac06..a5980cdc2 100644 --- a/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -190,9 +190,9 @@ public class ClipboardCommands { ClipboardHolder holder = session.getClipboard(); AffineTransform transform = new AffineTransform(); - transform = transform.rotateY(-Math.toRadians(yRotate != null ? yRotate : 0)); - transform = transform.rotateX(-Math.toRadians(xRotate != null ? xRotate : 0)); - transform = transform.rotateZ(-Math.toRadians(zRotate != null ? zRotate : 0)); + transform = transform.rotateY(-(yRotate != null ? yRotate : 0)); + transform = transform.rotateX(-(xRotate != null ? xRotate : 0)); + transform = transform.rotateZ(-(zRotate != null ? zRotate : 0)); holder.setTransform(holder.getTransform().combine(transform)); player.print("The clipboard copy has been rotated."); } diff --git a/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java b/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java index d5bf31e4f..6e907cb0e 100644 --- a/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java +++ b/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SchematicWriter.java @@ -206,8 +206,8 @@ public class SchematicWriter implements ClipboardWriter { private Tag writeRotation(Location location, String name) { List list = new ArrayList(); - list.add(new FloatTag("", (float) Math.toDegrees(location.getYaw()))); - list.add(new FloatTag("", (float) Math.toDegrees(location.getPitch()))); + list.add(new FloatTag("", location.getYaw())); + list.add(new FloatTag("", location.getPitch())); return new ListTag(name, FloatTag.class, list); } diff --git a/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java b/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java index fe1709fa4..3540daa77 100644 --- a/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java +++ b/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java @@ -244,6 +244,7 @@ public class AffineTransform implements Transform { } public AffineTransform rotateX(double theta) { + theta = Math.toRadians(theta); double cot = Math.cos(theta); double sit = Math.sin(theta); return concatenate( @@ -254,6 +255,7 @@ public class AffineTransform implements Transform { } public AffineTransform rotateY(double theta) { + theta = Math.toRadians(theta); double cot = Math.cos(theta); double sit = Math.sin(theta); return concatenate( @@ -264,6 +266,7 @@ public class AffineTransform implements Transform { } public AffineTransform rotateZ(double theta) { + theta = Math.toRadians(theta); double cot = Math.cos(theta); double sit = Math.sin(theta); return concatenate( diff --git a/src/main/java/com/sk89q/worldedit/util/Location.java b/src/main/java/com/sk89q/worldedit/util/Location.java index 90ec405be..f1fbcc8ce 100644 --- a/src/main/java/com/sk89q/worldedit/util/Location.java +++ b/src/main/java/com/sk89q/worldedit/util/Location.java @@ -97,8 +97,8 @@ public class Location { * @param x the X coordinate * @param y the Y coordinate * @param z the Z coordinate - * @param yaw the yaw, in radians - * @param pitch the pitch, in radians + * @param yaw the yaw, in degrees + * @param pitch the pitch, in degrees */ public Location(Extent extent, double x, double y, double z, float yaw, float pitch) { this(extent, new Vector(x, y, z), yaw, pitch); @@ -122,8 +122,8 @@ public class Location { * * @param extent the extent * @param position the position vector - * @param yaw the yaw, in radians - * @param pitch the pitch, in radians + * @param yaw the yaw, in degrees + * @param pitch the pitch, in degrees */ public Location(Extent extent, Vector position, float yaw, float pitch) { checkNotNull(extent); @@ -154,9 +154,9 @@ public class Location { } /** - * Get the yaw in radians. + * Get the yaw in degrees. * - * @return the yaw in radians + * @return the yaw in degrees */ public float getYaw() { return yaw; @@ -173,9 +173,9 @@ public class Location { } /** - * Get the pitch in radians. + * Get the pitch in degrees. * - * @return the pitch in radians + * @return the pitch in degrees */ public float getPitch() { return pitch; @@ -208,8 +208,8 @@ public class Location { * @return the direction vector */ public Vector getDirection() { - double yaw = this.getYaw(); - double pitch = this.getPitch(); + double yaw = Math.toRadians(this.getYaw()); + double pitch = Math.toRadians(this.getPitch()); double xz = Math.cos(pitch); return new Vector( -xz * Math.sin(yaw), diff --git a/src/main/java/com/sk89q/worldedit/world/storage/NBTConversions.java b/src/main/java/com/sk89q/worldedit/world/storage/NBTConversions.java index 43b24c39a..ad10929ae 100644 --- a/src/main/java/com/sk89q/worldedit/world/storage/NBTConversions.java +++ b/src/main/java/com/sk89q/worldedit/world/storage/NBTConversions.java @@ -52,7 +52,7 @@ public final class NBTConversions { return new Location( extent, positionTag.asDouble(0), positionTag.asDouble(1), positionTag.asDouble(2), - ((float) Math.toRadians(directionTag.asDouble(0))), ((float) Math.toRadians(directionTag.asDouble(1)))); + (float) directionTag.asDouble(0), (float) directionTag.asDouble(1)); } }