[
https://issues.apache.org/jira/browse/GEOMETRY-146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17520056#comment-17520056
]
Matt Juntunen commented on GEOMETRY-146:
----------------------------------------
{quote}IOW, assuming "deep" access, can {{PointMap}} instantiate a {{List}}
view object that would *lazily* navigate the map's content?
{quote}
No, that is not feasible with the current implementations.
{quote}If the low-level API only provides navigation (in "natural"/near-to-far
and "reverse"/far-to-near ordering), wouldn't it be clearer to let any
additional filtering belong to a higher-level API
{quote}
Yes, that sounds like a good approach. Along those lines, what do you think of
the following simplified API?
{code:java}
interface PointSet<P> {
// get the element nearest to pt
P nearest(P pt);
// get the element farthest from pt
P farthest(P pt);
// get all elements in order of nearest to farthest relative to pt
Collection<P> nearToFar(P pt);
// get all elements in order of farthest to nearest relative to pt
Collection<P> farToNear(P pt);
// get a stream containing all elements neighboring pt, i.e.
// within maxDist of pt; the points may be in any order
Stream<P> neighbors(P pt, double maxDist);
}
// same methods as PointSet but with the words "entry"/"entries"
// added for consistency with other map methods
interface PointMap<P, V> {
Entry<P, V> nearestEntry(P pt);
Entry<P, V> farthestEntry(P pt);
Collection<Entry<P, V>> entriesNearToFar(P pt);
Collection<Entry<P, V>> entriesFarToNear(P pt);
Stream<Entry<P, V>> neighborEntries(P pt, double maxDist);
}
{code}
A few notes here:
- All iteration is internal to the implementing map/set.
- {{nearToFar}} and {{farToNear}} return {{Collection}} since the number of
elements is known (i.e. the Collection contains all of the elements in the
map/set). This lets us support access through both {{Iterable}} and {{Stream}}
without needing a new type like {{StreamingIterable}}.
- {{neighbors}} returns a {{Stream}} since the number of elements is not known
without enumerating all members (at least in the current implementations). The
elements may be returned in any order.
- {{nearest/farthest}} are present to allow optimized retrieval of single
values.
> 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)