use of com.revolsys.geometry.algorithm.LineIntersector in project com.revolsys.open by revolsys.
the class SegmentIntersector method isBoundaryPoint.
private boolean isBoundaryPoint(final Collection<Node> boundaryNodes) {
final LineIntersector lineIntersector = this.lineIntersector;
for (final Node node : boundaryNodes) {
final double x = node.getX();
final double y = node.getY();
if (lineIntersector.isIntersection(x, y)) {
return true;
}
}
return false;
}
use of com.revolsys.geometry.algorithm.LineIntersector in project com.revolsys.open by revolsys.
the class Buffer method buffer.
/**
* Comutes the buffer for a geometry for a given buffer distance
* and accuracy of approximation.
*
* @param g the geometry to buffer
* @param distance the buffer distance
* @param parameters the buffer parameters to use
* @return the buffer of the input geometry
*/
@SuppressWarnings("unchecked")
public static <G extends Geometry> G buffer(final Geometry geometry, final double distance, final BufferParameters parameters) {
final GeometryFactory geometryFactory = geometry.getGeometryFactory();
try {
final MCIndexNoder noder = new MCIndexNoder();
final LineIntersector li = new RobustLineIntersector(geometryFactory.getScaleXY());
noder.setSegmentIntersector(new IntersectionAdder(li));
return (G) buffer(noder, geometryFactory, geometry, distance, parameters);
} catch (final RuntimeException e) {
if (geometryFactory.isFloating()) {
return (G) bufferReducedPrecision(geometry, distance, parameters);
} else {
return (G) bufferFixedPrecision(geometryFactory, geometry, distance, parameters);
}
}
}
use of com.revolsys.geometry.algorithm.LineIntersector in project com.revolsys.open by revolsys.
the class RobustLineIntersectionTest method checkIntersection.
/**
* Check that intersection of segment defined by points in pt array
* is equal to the expectedIntPt value (up to the given distanceTolerance).
*
* @param pt
* @param expectedIntersectionNum
* @param distanceTolerance tolerance to use for equality test
* @param expectedIntPt the expected intersection points (maybe null if not tested)
*/
void checkIntersection(final Point[] pt, final int expectedIntersectionNum, final double distanceTolerance, final Point... expectedIntPt) {
final LineIntersector li = new RobustLineIntersector();
li.computeIntersectionPoints(pt[0], pt[1], pt[2], pt[3]);
final int intNum = li.getIntersectionCount();
assertEquals("Number of intersections not as expected", expectedIntersectionNum, intNum);
if (expectedIntPt != null) {
assertEquals("Wrong number of expected int pts provided", intNum, expectedIntPt.length);
// test that both points are represented here
final boolean isIntPointsCorrect = true;
if (intNum == 1) {
checkIntPoints(expectedIntPt[0], li.getIntersection(0), distanceTolerance);
} else if (intNum == 2) {
checkIntPoints(expectedIntPt[1], li.getIntersection(0), distanceTolerance);
checkIntPoints(expectedIntPt[1], li.getIntersection(0), distanceTolerance);
if (!(equals(expectedIntPt[0], li.getIntersection(0), distanceTolerance) || equals(expectedIntPt[0], li.getIntersection(1), distanceTolerance))) {
checkIntPoints(expectedIntPt[0], li.getIntersection(0), distanceTolerance);
checkIntPoints(expectedIntPt[0], li.getIntersection(1), distanceTolerance);
} else if (!(equals(expectedIntPt[1], li.getIntersection(0), distanceTolerance) || equals(expectedIntPt[1], li.getIntersection(1), distanceTolerance))) {
checkIntPoints(expectedIntPt[1], li.getIntersection(0), distanceTolerance);
checkIntPoints(expectedIntPt[1], li.getIntersection(1), distanceTolerance);
}
}
}
}
use of com.revolsys.geometry.algorithm.LineIntersector in project com.revolsys.open by revolsys.
the class LineSegmentUtil method intersects.
public static boolean intersects(final Point line1p1, final Point line1p2, final Point line2p1, final Point line2p2) {
final LineIntersector li = new RobustLineIntersector();
li.computeIntersectionPoints(line1p1, line1p2, line2p1, line2p2);
return li.hasIntersection();
}
use of com.revolsys.geometry.algorithm.LineIntersector in project com.revolsys.open by revolsys.
the class LineString method isOnLine.
default boolean isOnLine(final double x, final double y) {
final LineIntersector lineIntersector = new RobustLineIntersector();
double x1 = getX(0);
double y1 = getY(0);
final int vertexCount = getVertexCount();
for (int i = 1; i < vertexCount; i++) {
final double x2 = getX(i);
final double y2 = getY(i);
if (lineIntersector.computeIntersection(x, y, x1, y1, x2, y2)) {
return true;
} else {
x1 = x2;
y1 = y2;
}
}
return false;
}
Aggregations