Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Battleroid/ae0eeeeca3ac88f0ff3e05072760b6a0 to your computer and use it in GitHub Desktop.
Save Battleroid/ae0eeeeca3ac88f0ff3e05072760b6a0 to your computer and use it in GitHub Desktop.
diff --git a/src/SNode.java b/src/SNode.java
index fcd7775..0554a07 100644
--- a/src/SNode.java
+++ b/src/SNode.java
@@ -49,17 +49,15 @@ public class SNode implements Comparable<SNode> {
}
static public double distanceTo(SNode f, SNode t) {
- double dx = Math.abs(f.x - t.x);
- double dy = Math.abs(f.y- t.y);
- return d * (dx + dy) + (d2 - 2 * d) * Math.min(dx, dy);
+ return Math.sqrt(Math.pow(t.x - f.x, 2.0) + Math.pow(t.y - f.y, 2.0));
}
public double distanceTo(SNode snode) {
- return Math.abs(x - snode.getX()) + Math.abs(y - snode.getY());
+ return Math.sqrt(Math.pow(snode.getX() - x, 2) + Math.pow(snode.getY() - y, 2));
}
public double distanceTo(double x, double y) {
- return Math.abs(this.x - x) + Math.abs(this.y - y);
+ return Math.sqrt(Math.pow(x - this.x, 2) + Math.pow(y - this.y, 2));
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment