use of com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator in project com.revolsys.open by revolsys.
the class PreparedPolygon method intersects.
@Override
public boolean intersects(final Geometry geometry) {
if (envelopesIntersect(geometry)) {
if (this.isRectangle) {
return RectangleIntersects.rectangleIntersects(this, geometry);
} else {
final PointOnGeometryLocator pointLocator = getPointLocator();
/**
* Do point-in-poly tests first, since they are cheaper and may result in a
* quick positive result.
*
* If a point of any test components lie in target, result is true
*/
final boolean isInPrepGeomArea = AbstractPreparedPolygonContains.isAnyTestComponentInTarget(pointLocator, geometry);
if (isInPrepGeomArea) {
return true;
}
/**
* If input contains only points, then at
* this point it is known that none of them are contained in the target
*/
if (geometry.getDimension() == 0) {
return false;
} else {
/**
* If any segments intersect, result is true
*/
final List<NodedSegmentString> lineSegStr = SegmentStringUtil.extractSegmentStrings(geometry);
// (i.e. NOT for point inputs)
if (lineSegStr.size() > 0) {
final boolean segsIntersect = getIntersectionFinder().intersects(lineSegStr);
if (segsIntersect) {
return true;
}
}
/**
* If the test has dimension = 2 as well, it is necessary to test for proper
* inclusion of the target. Since no segments intersect, it is sufficient to
* test representative points.
*/
if (geometry.getDimension() == 2) {
// TODO: generalize this to handle GeometryCollections
final boolean isPrepGeomInArea = AbstractPreparedPolygonContains.isAnyTargetComponentInAreaTest(geometry, this);
if (isPrepGeomInArea) {
return true;
}
}
return false;
}
}
} else {
return false;
}
}
use of com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator in project com.revolsys.open by revolsys.
the class PreparedLinearRing method isPointInRing.
@Override
public boolean isPointInRing(final double x, final double y) {
final PointOnGeometryLocator pointLocator = getPointLocator();
final Location location = pointLocator.locate(x, y);
return location != Location.EXTERIOR;
}
use of com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator in project com.revolsys.open by revolsys.
the class PointInAreaPerfTest method run.
public void run() {
final GeometryFactory geomFactory = GeometryFactory.DEFAULT_3D;
final SineStarFactory ssFact = new SineStarFactory();
ssFact.setSize(1000.0);
ssFact.setNumPoints(2000);
ssFact.setArmLengthRatio(0.1);
ssFact.setNumArms(100);
final Geometry area = ssFact.newSineStar();
// System.out.println(area);
final Stopwatch sw = new Stopwatch();
final PointOnGeometryLocator pia = new MCIndexedPointInAreaLocator(area);
// PointInAreaLocator pia = new IntervalIndexedPointInAreaLocator(area);
// PointInAreaLocator pia = new SimplePointInAreaLocator(area);
final PointInAreaPerfTester perfTester = new PointInAreaPerfTester(geomFactory, area);
perfTester.setNumPoints(50000);
perfTester.setPIA(pia);
perfTester.run();
// System.out.println("Overall time: " + sw.getTimeString());
}
use of com.revolsys.geometry.algorithm.locate.PointOnGeometryLocator in project com.revolsys.open by revolsys.
the class IndexedPointInAreaStressTest method testGrid.
public void testGrid() {
// Use fixed PM to try and get at least some points hitting the boundary
final GeometryFactory geomFactory = GeometryFactory.fixed2d(0, 1.0, 1.0);
// GeometryFactoryI geomFactory = new GeometryFactoryI();
final PerturbedGridPolygonBuilder gridBuilder = new PerturbedGridPolygonBuilder(geomFactory);
gridBuilder.setNumLines(20);
gridBuilder.setLineWidth(10.0);
gridBuilder.setSeed(1185072199562L);
final Geometry area = gridBuilder.getGeometry();
// PointInAreaLocator pia = new
// GeometryFactoryIndexedPointInAreaLocator(area);
final PointOnGeometryLocator pia = new IndexedPointInAreaLocator(area);
final PointInAreaStressTester gridTester = new PointInAreaStressTester(geomFactory, area);
gridTester.setNumPoints(100000);
gridTester.setPIA(pia);
final boolean isCorrect = gridTester.run();
assertTrue(isCorrect);
}
Aggregations