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

Gilles Sadowski commented on GEOMETRY-146:
------------------------------------------

{quote}It would be helpful to me if you could respond to my latest API proposal 
from Mar 30. [...]
{quote}
I did comment:
{quote}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. Sorry that I cannot convey 
the feeling in a more concrete way at this moment...
{quote}
For example, from your answers above, I seem to understand that {{PointMap}} 
and {{DistanceOrdering}} are tightly coupled; hence an independent interface 
for the latter seems artificial: If one looks at
{code:java}
interface DistanceOrdering<T> {
        T nearest();
        T farthest();
        StreamingIterable<T> nearToFar();
        StreamingIterable<T> farToNear();
}
{code}
one wonders: "nearest"/farthest to {*}what{*}? The reference point is 
"out-of-scope" (so to speak)...

Rather than
{code:java}
interface PointMap<P, V> {
    DistanceOrdering<Entry<P, V>> entriesFrom(P pt);
    DistanceOrdering<Entry<P, V>> entriesWithinRadius(P pt, double radius);
}
{code}
why not make the coupling obvious, as in
{code:java}
interface PointMap<P, V> {
    public enum DistanceOrdering {
        ASCENDING,
        DESCENDING
    }

    Iterable<Entry<P, V>> entriesWithinRadius(P pt, double radius, 
DistanceOrdering order);
    default Iterable<Entry<P, V>> entries(P pt, DistanceOrdering order) {
        return entriesWithinRadius(pt, Double.POSITIVE_INFINITY, order);
    }
}
{code}
?

I'm also a bit wary of only returning a {{StreamableIterator}} interface rather 
than e.g. a {{{}List{}}}, because in the potential use case which I have in 
mind, the selected points are rather few (as compared to the map's contents) 
and the number of them should be known in order to, for example, compute an 
interpolation of the associated values.
One can easily call 
[{{stream()}}|https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html#stream--]
 on a {{{}Collection{}}}, but creating a {{Collection}} instance from a stream 
is a bit more cumbersome, but also potentially less efficient, depending on the 
whether the original data-structure has "privileged" access for creating the 
{{Collection}} instance.

> 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