use of com.revolsys.geometry.index.kdtree.KdNode in project com.revolsys.open by revolsys.
the class ConformingDelaunayTriangulator method findNonGabrielPoint.
/**
* Given a set of points stored in the kd-tree and a line segment defined by
* two points in this set, finds a {@link Coordinates} in the circumcircle of
* the line segment, if one exists. This is called the Gabriel point - if none
* exists then the segment is said to have the Gabriel condition. Uses the
* heuristic of finding the non-Gabriel point closest to the midpoint of the
* segment.
*
* @param p
* start of the line segment
* @param q
* end of the line segment
* @return a point which is non-Gabriel
* or null if no point is non-Gabriel
*/
private Point findNonGabrielPoint(final LineSegmentDoubleData seg) {
final Point p = seg.getPoint(0);
final Point q = seg.getPoint(1);
// Find the mid point on the line and compute the radius of enclosing circle
final Point midPt = new PointDoubleXY((p.getX() + q.getX()) / 2.0, (p.getY() + q.getY()) / 2.0);
final double segRadius = p.distancePoint(midPt);
// compute envelope of circumcircle
final BoundingBox env = midPt.getBoundingBox().expand(segRadius);
// Find all points in envelope
final List result = this.pointIndex.getItems(env);
// For each point found, test if it falls strictly in the circle
// find closest point
Point closestNonGabriel = null;
double minDist = Double.MAX_VALUE;
for (final Iterator i = result.iterator(); i.hasNext(); ) {
final KdNode nextNode = (KdNode) i.next();
final Point testPt = nextNode;
// ignore segment endpoints
if (testPt.equals(2, p) || testPt.equals(2, q)) {
continue;
}
final double testRadius = midPt.distancePoint(testPt);
if (testRadius < segRadius) {
// double testDist = seg.distance(testPt);
final double testDist = testRadius;
if (closestNonGabriel == null || testDist < minDist) {
closestNonGabriel = testPt;
minDist = testDist;
}
}
}
return closestNonGabriel;
}
use of com.revolsys.geometry.index.kdtree.KdNode in project com.revolsys.open by revolsys.
the class KdTreeTest method testSinglePoint.
public void testSinglePoint() {
final KdTree index = new KdTree(GeometryFactory.fixed2d(0, 1000, 1000));
final KdNode node1 = index.insertPoint(new PointDouble(1, 1));
final KdNode node2 = index.insertPoint(new PointDouble(1, 1));
assertTrue("Inserting 2 identical points should create one node", node1 == node2);
final BoundingBox queryEnv = new BoundingBoxDoubleXY(0, 0, 10, 10);
final List result = index.getItems(queryEnv);
assertTrue(result.size() == 1);
final KdNode node = (KdNode) result.get(0);
assertTrue(node.getCount() == 2);
assertTrue(node.isRepeated());
}
use of com.revolsys.geometry.index.kdtree.KdNode in project com.revolsys.open by revolsys.
the class KdTreeTest method testSinglePoint.
@Test
public void testSinglePoint() {
final KdTree index = new KdTree();
final KdNode node1 = index.insertPoint(1, 1);
final KdNode node2 = index.insertPoint(new PointDoubleXY(1, 1));
Assert.assertSame("Inserting 2 identical points should create one node", node1, node2);
final BoundingBox queryEnv = new BoundingBoxDoubleXY(0, 0, 10, 10);
final List<KdNode> result = index.getItems(queryEnv);
Assert.assertEquals(1, result.size());
final KdNode node = result.get(0);
Assert.assertEquals(2, node.getCount());
Assert.assertTrue(node.isRepeated());
}
Aggregations