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

Matt Juntunen commented on GEOMETRY-146:
----------------------------------------

bq. Discussion can continue on the latter; that does not preclude committing 
the former (but please include "WIP" in the commit message, and mark the 
relevant codes with "TBD", with a link to here).

Good to know. I'll keep everything on my working branch for now so that we 
don't have a bunch of renaming of classes/methods in master.

bq. You did not comment about what was wrong with my proposed API, i.e. one 
that would keep iteration an internal part of the "result set".

I agree with your thought of separating these operations into two parts: a 
"subset selection" part and an "iteration" part. My main objection to the APi 
example you gave is that I didn't see a way to specify the order of iteration. 
In your example above, how would one specify that the results should be 
returned in order of increasing distance?
{code:java}
PointMap.EntrySetSelector<Vector2D, Double> selector = 
map.withinDistance(resolution);
// ...
PointMap.EntrySet<Vector2D, Double> subSet = selector.apply(v);

// how do I iterate over subSet from near to far?
{code}
Also, the subset selection here seems to be split into two parts: the first to 
specify the distance and the second to specify the reference point. I don't see 
a reason to separate these.

In my most recent API proposal, I do have a separation between subset selection 
and iteration.
{code:java}
PointSet<Vector3D> set = EuclideanCollectionUtils.pointSet3D(precision);

// select the subset of points within 1 unit from the origin
DistanceOrdering<Vector3D> subset = set.withinDistance(Vector3D.ZERO, 1);

// iterate over the subset from near to far
List<Vector3D> subset.nearToFar().stream()
    .collect(Collectors.toList());

// get the farthest entry from the origin but still within the maximum distance
Vector3D nearest = subset.nearest();
{code} 

bq. You intentionally hid the internal implementation of PointMap, yet the 
"near"/"far" methods make one assume that such an implementation must support 
specific iteration "modes"; hence I'm feeling uncomfortable with the 
(apparent?) inconsistency, at the "public" level. 

Yes, I would expect all {{PointMap/Set}} implementations to provide these 
near/far iteration modes. I picture this as similar to the iteration order 
methods provided by {{java.util.NavigableMap}} but applying to all spaces and 
dimensions. Computing distance between points is one of the few things that all 
spaces and dimensions provide so I feel that placing these methods in the 
public API is appropriate.

bq. Out of curiosity, could you document (in the "examples" module) the actual 
use cases that require one or the other iteration direction? That would also 
help us test alternative APIs and where to draw the line between "public" and 
"internal".

Yes, I am planning on adding examples in the user guide as part of this ticket. 
In general, it frequently happens that distance from a certain point is part of 
the point selection criteria for geometric algorithms. For example, the first 
step in the quickhull algorithm is typically construction of a maximally 
spanning tetrahedron. The first edge in this tetrahedron could be constructed 
by selecting a point with a minimum x,y, and/or z coordinate and then selecting 
the point from the set farthest from that point. 

As a more concrete example, consider that a {{PointMap}} is used to represent 
geographic locations and meta data. A near-to-far ordering could be used to 
locate the nearest city from a specified location with a population of at least 
X without requiring all points to be examined. Similarly, a far-to-near 
ordering could be used to determine the worst-case distance a package would 
need to travel when being shipped to a location from one of a number of cities 
containing distribution centers.

In general, I consider that this near/far qualification is important enough to 
warrant inclusion in the top-level public API.


> PointSet/Map closest points
> ---------------------------
>
>                 Key: GEOMETRY-146
>                 URL: https://issues.apache.org/jira/browse/GEOMETRY-146
>             Project: Commons Geometry
>          Issue Type: New Feature
>            Reporter: Matt Juntunen
>            Priority: Major
>             Fix For: 1.1
>
>
> Add methods to the new {{PointSet}} and {{PointMap}} interfaces to allow 
> querying of points in order of distance from a query point.
> {code:java}
> PointSet<P> {
>     // find the closest point to pt or null if empty 
>     P closest(P pt);
>     // iterate through points in order, with points closest to pt coming first
>     Iterable<P> closestFirst(P pt);
>     // find the farthest point from pt or null if emtpy
>     P farthest(P pt);
>     // iterate through point in order, with points farthest from pt coming 
> first
>     Iterable<P> farthestFirst(P pt);
> }
> {code}
> {{PointMap}} should have similar methods providing access to the map keys and 
> entries.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to