[ 
https://issues.apache.org/jira/browse/GEOMETRY-140?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17426124#comment-17426124
 ] 

Matt Juntunen commented on GEOMETRY-140:
----------------------------------------

This will not work. The issue is that the returned instance cannot fulfill the 
following portion of the {{Comparator}} API contract:

bq. Finally, the implementor must ensure that compare(x, y)==0 implies that 
sgn(compare(x, z))==sgn(compare(y, z)) for all z.

For example, say that x=1, y=1.075, z = 1.15, and a precision is used with an 
epsilon of 0.1. In this case, compare(x, y) == 0 and compare(y, z) == 0 but 
compare(x, z) = -1. This causes issues when attempting to sort collections 
using this comparator, namely an {{IllegalArgumentException}} during the sort 
operation.

> Vector/Point EquivalenceComparator
> ----------------------------------
>
>                 Key: GEOMETRY-140
>                 URL: https://issues.apache.org/jira/browse/GEOMETRY-140
>             Project: Apache Commons Geometry
>          Issue Type: New Feature
>            Reporter: Matt Juntunen
>            Priority: Minor
>
> I propose adding the following static method to the VectorXD and PointXS 
> classes, where {{P}} is the Vector/Point type:
> {code:java}
> public static Comparator<P> equivalenceComparator(Precision.DoubleEquivalence 
> eq) {...}
> {code}
> The method would return a {{Comparator}} that delegates to the 
> {{Precision.DoubleEquivalence.compare()}} method of the argument, passing 
> each vector/point coordinate in order. This comparator could be used, for 
> example, to create {{TreeMap}} or {{TreeSet}} instances that loosely compare 
> vectors/points, as done currently in 
> [SimpleTriangleMesh|https://github.com/apache/commons-geometry/blob/master/commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/mesh/SimpleTriangleMesh.java#L679].



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to