You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2023/09/04 01:04:23 UTC

[commons-geometry] 22/25: GEOMETRY-144

This is an automated email from the ASF dual-hosted git repository.

mattjuntunen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-geometry.git

commit c7868412662bede8269e09d82cd7f6043f5fbd36
Author: Andreas <an...@gmail.com>
AuthorDate: Sat Aug 12 20:55:47 2023 +0200

    GEOMETRY-144
    
    The comparator guarantees, that the distance to the former point is
    always greater than to the last.
---
 .../commons/geometry/euclidean/twod/hull/ConvexHull2D.java  | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/ConvexHull2D.java b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/ConvexHull2D.java
index e6084e7e..711538e7 100644
--- a/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/ConvexHull2D.java
+++ b/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/twod/hull/ConvexHull2D.java
@@ -395,18 +395,11 @@ public final class ConvexHull2D implements ConvexHull<Vector2D> {
                 final double offset = Lines.fromPoints(p1, p2, precision).offset(point);
                 if (precision.eqZero(offset)) {
                     // the point is collinear to the line (p1, p2)
-                    // Calculate distance to both points.
-                    final double distanceToCurrent = p1.distance(point);
-                    final double distanceToLast = p1.distance(p2);
-
                     if (includeCollinearPoints) {
-                        final int index = distanceToCurrent < distanceToLast ? size - 1 : size;
-                        hull.add(index, point);
+                        hull.add(size, point);
                     } else {
-                        if (distanceToCurrent > distanceToLast) {
-                            hull.remove(size - 1);
-                            hull.add(point);
-                        }
+                        hull.remove(size - 1);
+                        hull.add(point);
                     }
                     return;
                 } else if (offset > 0) {