[
https://issues.apache.org/jira/browse/GEOMETRY-146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17513593#comment-17513593
]
Matt Juntunen commented on GEOMETRY-146:
----------------------------------------
Here is another shot at the API. I've added a {{closestWithinDistance}} method
and the map names all contain the word "entry" in some form to indicate that an
entry is returned (similar to {{entrySet}}). I've also realized that we can
return full {{Collection}} instances from the view methods instead of just
{{Iterable}} since we already know the number of entries. This will make the
returned views easier to work with, especially since callers can convert to a
stream just by calling {{stream()}}.
I am still not sold on the method names. They feel kind of clunky to me so I'm
open to suggestions.
{code:java}
PointSet<P> {
// return the element closest to pt or null if empty
P closest(P pt);
// return the element closest to pt and within the specified
// distance or null if it does not exist
P closestWithinDistance(P pt, double dist);
// return the element farthest from pt or null if empty
P farthest(P pt);
// view of all elements in order of ascending distance from pt
Collection<P> distanceAscending(P pt);
// view of all elements in order of descending distance from pt
Collection<P> distanceDescending(P pt);
}
PointMap<P, V> {
// return the entry closest to pt or null if empty
Map.Entry<P, V> closestEntry(P pt);
// return the entry closest to pt and within the specified
// distance or null if it does not exist
Map.Entry<P, V> closeEntryWithinDistance(P pt, double dist);
// return the entry farthest from pt or null if empty
Map.Entry<P, V> farthestEntry(P pt);
// view of all entries in order of ascending distance from pt
Collection<Map.Entry<P, V>> entriesByDistanceAscending(P pt);
// view of all entries in order of descending distance from pt
Collection<Map.Entry<P, V>> entriesByDistanceDescending(P pt);
}
{code}
Thoughts?
> 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)