Search in sources :

Example 1 with KdNode

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;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) KdNode(com.revolsys.geometry.index.kdtree.KdNode) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 2 with KdNode

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());
}
Also used : PointDouble(com.revolsys.geometry.model.impl.PointDouble) KdTree(com.revolsys.geometry.index.kdtree.KdTree) BoundingBox(com.revolsys.geometry.model.BoundingBox) KdNode(com.revolsys.geometry.index.kdtree.KdNode) List(java.util.List) BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)

Example 3 with KdNode

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());
}
Also used : KdTree(com.revolsys.geometry.index.kdtree.KdTree) BoundingBox(com.revolsys.geometry.model.BoundingBox) KdNode(com.revolsys.geometry.index.kdtree.KdNode) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) BoundingBoxDoubleXY(com.revolsys.geometry.model.impl.BoundingBoxDoubleXY) Test(org.junit.Test)

Aggregations

KdNode (com.revolsys.geometry.index.kdtree.KdNode)3 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 KdTree (com.revolsys.geometry.index.kdtree.KdTree)2 BoundingBoxDoubleXY (com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)2 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)2 List (java.util.List)2 Point (com.revolsys.geometry.model.Point)1 PointDouble (com.revolsys.geometry.model.impl.PointDouble)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Test (org.junit.Test)1