Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public double distance(Location loc) {
- int sx = this.getSectorX() - loc.getSectorX();
- int sy = this.getSectorY() - loc.getSectorY();
- if (Math.abs(sx) > 2) {
- return (sx > 0)? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
- }
- if (Math.abs(sy) > 2) {
- return (sy > 0)? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
- }
- double dx, dy;
- double size = sectorXMax - sectorXMin;
- dx = Math.pow((((sx * size) + this.getX()) - loc.getX()),2);
- dy = Math.pow((((sy * size) + this.getY()) - loc.getY()),2);
- return Math.sqrt(Math.abs(dx) + Math.abs(dy));
- }
Advertisement
Add Comment
Please, Sign In to add comment