RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Distance.java
1package com.osroyale.game.world.pathfinding.distance;
2
3import com.osroyale.game.world.position.Position;
4
11public interface Distance {
12
21
28 final class Chebyshev implements Distance {
29
30 @Override
31 public int calculate(Position to, Position from) {
32 int dx = Math.abs(from.getX() - to.getX());
33 int dy = Math.abs(from.getX() - to.getY());
34 return dx >= dy ? dx : dy;
35 }
36 }
37
45 class Euclidean implements Distance {
46
47 @Override
48 public int calculate(Position to, Position from) {
49 int deltaX = from.getX() - to.getX();
50 int deltaY = from.getY() - to.getY();
51 return (int) Math.sqrt(deltaX * deltaX + deltaY * deltaY);
52 }
53
54 }
55
64 class Manhattan implements Distance {
65
66 @Override
67 public int calculate(Position to, Position from) {
68 int deltaX = Math.abs(from.getX() - to.getX());
69 int deltaY = Math.abs(from.getY() - to.getY());
70 return deltaX + deltaY;
71 }
72
73 }
74}