From a0e6d1ce43e62b5ed1f0d629b848d0b3c8ad9d7e Mon Sep 17 00:00:00 2001 From: Pierre-Alexandre Date: Tue, 13 Aug 2024 13:49:26 +0200 Subject: [PATCH] [#819] Geom getDistance of two Point added. --- .../java/com/b3dgs/lionengine/geom/Geom.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lionengine-core/src/main/java/com/b3dgs/lionengine/geom/Geom.java b/lionengine-core/src/main/java/com/b3dgs/lionengine/geom/Geom.java index 946138cef..f0affa9e9 100644 --- a/lionengine-core/src/main/java/com/b3dgs/lionengine/geom/Geom.java +++ b/lionengine-core/src/main/java/com/b3dgs/lionengine/geom/Geom.java @@ -103,6 +103,25 @@ public static boolean same(Localizable a, Localizable b) return Double.compare(a.getX(), b.getX()) == 0 && Double.compare(a.getY(), b.getY()) == 0; } + /** + * Get distance of two points. + * + * @param a The first point (must not be null). + * @param b The second point (must not be null). + * @return The distance between them. + * @throws LionEngineException If invalid argument. + */ + public static double getDistance(Point a, Point b) + { + Check.notNull(a); + Check.notNull(b); + + final double x = b.getX() - a.getX(); + final double y = b.getY() - a.getY(); + + return StrictMath.sqrt(x * x + y * y); + } + /** * Private constructor. */