[
https://issues.apache.org/jira/browse/GEOMETRY-146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17508796#comment-17508796
]
Matt Juntunen commented on GEOMETRY-146:
----------------------------------------
The general iteration methods are required for the use cases I'm picturing.
Say, for example, you need to find the point closest to a query point that also
satisfies some other condition, such as being associated with a particular
value. This could be accomplished with a map as follows:
{code:java}
PointMap<Vector3D, Integer> map = EuclideanCollections.pointMap3D(precision);
// add points and values ...
Vector3D queryPt = Vector3D.of(1, 2, 3);
Vector3D resultPt = null;
for (Map.Entry<Vector3D, Integer> entry : map.closestFirst(queryPt)) {
if (entry.getValue() > 100) {
resultPt = entry.getKey();
break;
}
}
{code}
A similar use case for {{PointSet}} could look like this:
{code:java}
PointSet<Vector3D> set = EuclideanCollections.pointSet3D(precision);
// add points ...
Vector3D queryPt = Vector3D.of(1, 2, 3);
Vector3D resultPt = null;
for (Vector3D pt : entry) {
if (pt.getX() > queryPt.getX()) {
resultPt = pt;
break;
}
}
{code}
The {{closestInRange}} methods could actually be implemented using this general
approach.
{code:java}
public List<P> closestInRange(P pt, double dist) {
List<P> result = new ArrayList<>();
for (P setPt : set.closestFirst(pt)) {
if (setPt.distance(pt) > dist) {
break;
}
result.add(setPt);
}
return result;
}
{code}
I'm picturing the implemented iteration operations being lazy (as they are in
the {{RegionBSPTreeXD}} classes) and only pulling values as needed. There then
shouldn't be any wasted resources from this approach.
> 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)