use of com.revolsys.geometry.operation.simple.SelfIntersectionVertexError in project com.revolsys.open by revolsys.
the class Lineal method addIsSimpleErrors.
static boolean addIsSimpleErrors(final Lineal lineal, final List<GeometryValidationError> errors, final boolean shortCircuit) {
final LineSegmentIndex index = new LineSegmentIndex(lineal);
for (final Segment segment : lineal.segments()) {
final int segmentIndex = segment.getSegmentIndex();
final int partIndex = segment.getPartIndex();
if (segment.getLength() == 0) {
errors.add(new DuplicateVertexError(segment.getGeometryVertex(0)));
} else {
final List<LineSegment> segments = index.queryBoundingBox(segment);
for (final LineSegment lineSegment : segments) {
final Segment segment2 = (Segment) lineSegment;
final int partIndex2 = segment2.getPartIndex();
final int segmentIndex2 = segment2.getSegmentIndex();
if (partIndex2 > partIndex || partIndex == partIndex2 && segmentIndex2 > segmentIndex) {
if (segment.equals(lineSegment)) {
final SelfOverlapSegmentError error = new SelfOverlapSegmentError(segment);
errors.add(error);
if (shortCircuit) {
return false;
}
} else {
final Geometry intersection = segment.getIntersection(lineSegment);
if (intersection instanceof Point) {
final Point pointIntersection = (Point) intersection;
boolean isIntersection = true;
// Process segments on the same linestring part
if (partIndex == partIndex2) {
// segment
if (segmentIndex + 1 == segmentIndex2) {
if (lineSegment.equalsVertex(2, 0, pointIntersection)) {
isIntersection = false;
}
// A loop can touch itself at the start/end
} else if (segment.isLineClosed()) {
if (segment.isLineStart() && segment2.isLineEnd()) {
if (segment.equalsVertex(2, 0, pointIntersection)) {
isIntersection = false;
}
}
}
} else {
if (!segment.isLineClosed() && !segment2.isLineClosed()) {
final boolean segment1EndIntersection = segment.isEndIntersection(pointIntersection);
final boolean segment2EndIntersection = segment2.isEndIntersection(pointIntersection);
if (segment1EndIntersection && segment2EndIntersection) {
isIntersection = false;
}
}
}
if (isIntersection) {
GeometryValidationError error;
if (segment.equalsVertex(2, 0, pointIntersection)) {
final Vertex vertex = segment.getGeometryVertex(0);
error = new SelfIntersectionVertexError(vertex);
} else if (segment.equalsVertex(2, 1, pointIntersection)) {
final Vertex vertex = segment.getGeometryVertex(1);
error = new SelfIntersectionVertexError(vertex);
} else {
error = new SelfIntersectionPointError(lineal, pointIntersection);
}
errors.add(error);
if (shortCircuit) {
return false;
}
}
} else if (intersection instanceof LineSegment) {
final LineSegment lineIntersection = (LineSegment) intersection;
GeometryValidationError error;
if (segment.equals(lineIntersection)) {
error = new SelfOverlapSegmentError(segment);
} else if (lineSegment.equals(lineIntersection)) {
error = new SelfOverlapSegmentError(segment2);
} else {
error = new SelfOverlapLineSegmentError(lineal, lineIntersection);
}
errors.add(error);
if (shortCircuit) {
return false;
}
}
}
}
}
}
}
return errors.isEmpty();
}
Aggregations