Skip to content

Commit

Permalink
Optimizes square distance calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
KartikChugh committed Apr 16, 2020
1 parent 8afefa6 commit 58e77c1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/kc/ml/seeker/entities/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ private double getCenterY() {
}

final double squareDistanceFrom(Entity o) {
// TODO optimize center calculations
return Math.pow(getCenterX() - o.getCenterX(), 2) + Math.pow(getCenterY() - o.getCenterY(), 2);

final double dx = getCenterX() - o.getCenterX();
final double dy = getCenterY() - o.getCenterY();

return dx*dx + dy*dy;
}

final boolean isTouching(Entity o) {
Expand Down

0 comments on commit 58e77c1

Please sign in to comment.