Search in sources :

Example 56 with LineSegment

use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.

the class TaggedLineStringSimplifier method simplifySection.

private void simplifySection(final int i, final int j, int depth) {
    depth += 1;
    final int[] sectionIndex = new int[2];
    if (i + 1 == j) {
        final LineSegment newSeg = this.taggedLine.getSegment(i);
        this.taggedLine.addToResult(newSeg);
        // leave this segment in the input index, for efficiency
        return;
    }
    boolean isValidToSimplify = true;
    /**
     * Following logic ensures that there is enough points in the output taggedLine.
     * If there is already more points than the minimum, there's nothing to check.
     * Otherwise, if in the worst case there wouldn't be enough points,
     * don't flatten this segment (which avoids the worst case scenario)
     */
    if (this.taggedLine.getResultSize() < this.taggedLine.getMinimumSize()) {
        final int worstCaseSize = depth + 1;
        if (worstCaseSize < this.taggedLine.getMinimumSize()) {
            isValidToSimplify = false;
        }
    }
    final double[] distance = new double[1];
    final int furthestPtIndex = findFurthestPoint(i, j, distance);
    // flattening must be less than distanceTolerance
    if (distance[0] > this.distanceTolerance) {
        isValidToSimplify = false;
    }
    // test if flattened section would cause intersection
    // final LineSegment candidateSeg = new LineSegmentDouble();
    final Point p0 = this.line.getVertex(i);
    final Point p1 = this.line.getVertex(j);
    final LineSegment candidateSeg = new LineSegmentDouble(p0, p1);
    sectionIndex[0] = i;
    sectionIndex[1] = j;
    if (hasBadIntersection(this.taggedLine, sectionIndex, candidateSeg)) {
        isValidToSimplify = false;
    }
    if (isValidToSimplify) {
        final LineSegment newSeg = flatten(i, j);
        this.taggedLine.addToResult(newSeg);
        return;
    }
    simplifySection(i, furthestPtIndex, depth);
    simplifySection(furthestPtIndex, j, depth);
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 57 with LineSegment

use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.

the class OffsetSegmentGenerator method addLineEndCap.

/**
 * Add an end cap around point p1, terminating a line segment coming from p0
 */
public void addLineEndCap(final double x1, final double y1, final double x2, final double y2) {
    final LineSegment offsetL = newOffsetSegment(x1, y1, x2, y2, Position.LEFT, this.distance);
    final LineSegment offsetR = newOffsetSegment(x1, y1, x2, y2, Position.RIGHT, this.distance);
    final double dx = x2 - x1;
    final double dy = y2 - y1;
    final double angle = Math.atan2(dy, dx);
    final double leftX2 = offsetL.getX(1);
    final double leftY2 = offsetL.getY(1);
    final double rightX2 = offsetR.getX(1);
    final double rightY2 = offsetR.getY(1);
    switch(this.bufParams.getEndCapStyle()) {
        case ROUND:
            // add offset seg points with a fillet between them
            this.segList.addPoint(leftX2, leftY2);
            addFillet(x2, y2, angle + Math.PI / 2, angle - Math.PI / 2, CGAlgorithms.CLOCKWISE, this.distance);
            this.segList.addPoint(rightX2, rightY2);
            break;
        case BUTT:
            // only offset segment points are added
            this.segList.addPoint(leftX2, leftY2);
            this.segList.addPoint(rightX2, rightY2);
            break;
        case SQUARE:
            final double absDistance = Math.abs(this.distance);
            // add a square defined by extensions of the offset segment endpoints
            final double squareCapSideOffsetX = absDistance * Math.cos(angle);
            final double squareCapSideOffsetY = absDistance * Math.sin(angle);
            final double lx = leftX2 + squareCapSideOffsetX;
            final double ly = leftY2 + squareCapSideOffsetY;
            this.segList.addPoint(lx, ly);
            final double rx = rightX2 + squareCapSideOffsetX;
            final double ry = rightY2 + squareCapSideOffsetY;
            this.segList.addPoint(rx, ry);
            break;
    }
}
Also used : LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 58 with LineSegment

use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.

the class KochSnowflakeBuilder method getGeometry.

@Override
public Geometry getGeometry() {
    final int level = recursionLevelForSize(this.numPts);
    final LineSegment baseLine = getSquareBaseLine();
    final Point[] pts = getBoundary(level, baseLine.getPoint(0), baseLine.getLength());
    return this.geometryFactory.polygon(this.geometryFactory.linearRing(pts));
}
Also used : Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 59 with LineSegment

use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.

the class RandomOffsetLineStringGenerator method computeRandomOffset.

private Point computeRandomOffset(final Point p0, final Point p1, final double segFrac) {
    final double len = p0.distancePoint(p1);
    final double len2 = len / 2;
    final double offsetLen = len * Math.random() - len2;
    final LineSegment seg = new LineSegmentDouble(p0, p1);
    return seg.pointAlongOffset(segFrac, offsetLen);
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 60 with LineSegment

use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.

the class LineSegmentTest method testOrientationIndexCoordinate.

public void testOrientationIndexCoordinate() {
    final LineSegment seg = new LineSegmentDouble(2, 0, 0, 10, 10);
    checkOrientationIndex(seg, 10, 11, 1);
    checkOrientationIndex(seg, 10, 9, -1);
    checkOrientationIndex(seg, 11, 11, 0);
    checkOrientationIndex(seg, 11, 11.0000001, 1);
    checkOrientationIndex(seg, 11, 10.9999999, -1);
    checkOrientationIndex(seg, -2, -1.9999999, 1);
    checkOrientationIndex(seg, -2, -2.0000001, -1);
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Aggregations

LineSegment (com.revolsys.geometry.model.segment.LineSegment)61 Point (com.revolsys.geometry.model.Point)34 Edge (com.revolsys.geometry.graph.Edge)19 LineSegmentDouble (com.revolsys.geometry.model.segment.LineSegmentDouble)14 LineSegmentDoubleGF (com.revolsys.geometry.model.segment.LineSegmentDoubleGF)13 Geometry (com.revolsys.geometry.model.Geometry)12 PointOnLineSegment (com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)11 ArrayList (java.util.ArrayList)10 LineString (com.revolsys.geometry.model.LineString)9 Node (com.revolsys.geometry.graph.Node)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)6 EdgeAttributeValueComparator (com.revolsys.geometry.graph.comparator.EdgeAttributeValueComparator)5 BoundingBox (com.revolsys.geometry.model.BoundingBox)4 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)4 List (java.util.List)4 EdgeObjectFilter (com.revolsys.geometry.graph.filter.EdgeObjectFilter)2 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)2 Polygon (com.revolsys.geometry.model.Polygon)2 Vertex (com.revolsys.geometry.model.vertex.Vertex)2 Shape (java.awt.Shape)2