use of com.revolsys.geometry.algorithm.LineIntersector in project com.revolsys.open by revolsys.
the class SegmentIntersector method addIntersections.
/**
* This method is called by clients of the EdgeIntersector class to test for and add
* intersections for two segments of the edges being intersected.
* Note that clients (such as MonotoneChainEdges) may choose not to intersect
* certain pairs of segments for efficiency reasons.
*/
public void addIntersections(final Edge edge1, final LineString line1, final int segIndex0, final Edge edge2, final LineString line2, final int segIndex1) {
if (edge1 == edge2 && segIndex0 == segIndex1) {
return;
} else {
this.numTests++;
final double line1x1 = line1.getX(segIndex0);
final double line1y1 = line1.getY(segIndex0);
final double line1x2 = line1.getX(segIndex0 + 1);
final double line1y2 = line1.getY(segIndex0 + 1);
final double line2x1 = line2.getX(segIndex1);
final double line2y1 = line2.getY(segIndex1);
final double line2x2 = line2.getX(segIndex1 + 1);
final double line2y2 = line2.getY(segIndex1 + 1);
final LineIntersector lineIntersector = this.lineIntersector;
lineIntersector.computeIntersection(line1x1, line1y1, line1x2, line1y2, line2x1, line2y1, line2x2, line2y2);
/**
* Always record any non-proper intersections.
* If includeProper is true, record any proper intersections as well.
*/
if (lineIntersector.hasIntersection()) {
if (this.recordIsolated) {
edge1.setIsolated(false);
edge2.setIsolated(false);
}
// if the segments are adjacent they have at least one trivial
// intersection,
// the shared endpoint. Don't bother adding it if it is the
// only intersection.
boolean trivialIntersection = false;
if (edge1 == edge2) {
if (lineIntersector.getIntersectionCount() == 1) {
if (Math.abs(segIndex0 - segIndex1) == 1) {
trivialIntersection = true;
} else if (line1.isClosed()) {
final int maxSegIndex = line1.getVertexCount() - 1;
if (segIndex0 == 0 && segIndex1 == maxSegIndex || segIndex1 == 0 && segIndex0 == maxSegIndex) {
trivialIntersection = true;
}
}
}
}
if (!trivialIntersection) {
this.hasIntersection = true;
if (this.includeProper || !lineIntersector.isProper()) {
edge1.addIntersections(lineIntersector, segIndex0, 0);
edge2.addIntersections(lineIntersector, segIndex1, 1);
}
if (lineIntersector.isProper()) {
this.properIntersectionPoint = lineIntersector.getIntersection(0);
this.hasProper = true;
if (!isBoundaryPoint()) {
this.hasProperInterior = true;
}
}
}
}
}
}
use of com.revolsys.geometry.algorithm.LineIntersector in project com.revolsys.open by revolsys.
the class IsValidOp method checkValidLinearRing.
/**
* Checks validity of a LinearRing.
*/
private boolean checkValidLinearRing(final LinearRing ring) {
boolean valid = true;
if (checkTooFewVertices(ring, 4)) {
valid &= checkClosedRing(ring);
if (isErrorReturn()) {
return false;
}
final GeometryGraph graph = new GeometryGraph(0, ring);
final LineIntersector li = new RobustLineIntersector();
graph.computeSelfNodes(li, true);
valid &= checkNoSelfIntersectingRings(graph);
return valid;
}
return false;
}
use of com.revolsys.geometry.algorithm.LineIntersector in project com.revolsys.open by revolsys.
the class NodingFunctions method MCIndexNodingWithPrecision.
public static Geometry MCIndexNodingWithPrecision(final Geometry geom, final double scaleFactor) {
final List segs = newNodedSegmentStrings(geom);
final LineIntersector li = new RobustLineIntersector(scaleFactor);
final Noder noder = new MCIndexNoder(new IntersectionAdder(li));
noder.computeNodes(segs);
final Collection nodedSegStrings = noder.getNodedSubstrings();
return fromSegmentStrings(nodedSegStrings);
}
Aggregations