Skip to content

Commit 1e2af03

Browse files
committed
add bwmirror getDistance for points
1 parent 93cd972 commit 1e2af03

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/main/java/bwapi/Point.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public String toString() {
2929
return "[" + x + ", " + y + "]";
3030
}
3131

32+
protected double getDistance(final int x, final int y) {
33+
final int dx = x - this.x;
34+
final int dy = y - this.y;
35+
return Math.sqrt(dx * dx + dy * dy);
36+
}
37+
3238
public boolean equals(final Object o) {
3339
if (!(o instanceof Point)) {
3440
return false;

src/main/java/bwapi/Position.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,8 @@ public Position divide(final int divisor) {
5757
public Position multiply(final int multiplier) {
5858
return new Position(x * multiplier, y * multiplier);
5959
}
60+
61+
public double getDistance(final Position position) {
62+
return getDistance(position.x, position.y);
63+
}
6064
}

src/main/java/bwapi/TilePosition.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ public TilePosition divide(final int divisor) {
3535
public TilePosition multiply(final int multiplier) {
3636
return new TilePosition(x * multiplier, y * multiplier);
3737
}
38+
39+
public double getDistance(final TilePosition position) {
40+
return getDistance(position.x, position.y);
41+
}
3842
}

src/main/java/bwapi/WalkPosition.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ public WalkPosition divide(final int divisor) {
3535
public WalkPosition multiply(final int multiplier) {
3636
return new WalkPosition(x * multiplier, y * multiplier);
3737
}
38+
39+
public double getDistance(final WalkPosition position) {
40+
return getDistance(position.x, position.y);
41+
}
3842
}

0 commit comments

Comments
 (0)