Search in sources :

Example 1 with LineSegmentDouble

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

the class Buffer method findStabbedSegments.

/**
 * Finds all non-horizontal segments intersecting the stabbing line
 * in the input dirEdge.
 * The stabbing line is the ray to the right of stabbingRayLeftPt.
 *
 * @param stabbingRayLeftPt the left-hand origin of the stabbing line
 * @param stabbedSegments the current list of {@link DepthSegments} intersecting the stabbing line
 */
private static void findStabbedSegments(final Collection<BufferSubgraph> subgraphs, final Point stabbingRayLeftPt, final DirectedEdge dirEdge, final List<DepthSegment> stabbedSegments) {
    final Edge edge = dirEdge.getEdge();
    for (int i = 0; i < edge.getVertexCount() - 1; i++) {
        final Point p1 = edge.getPoint(i);
        LineSegment seg = new LineSegmentDouble(p1, edge.getPoint(i + 1));
        double y1 = seg.getY(0);
        double y2 = seg.getY(1);
        // ensure segment always points upwards
        if (y1 > y2) {
            seg = seg.reverse();
            y1 = seg.getY(0);
            y2 = seg.getY(1);
        }
        final double x1 = seg.getX(0);
        final double x2 = seg.getX(1);
        // skip segment if it is left of the stabbing line
        final double maxx = Math.max(x1, x2);
        if (maxx < stabbingRayLeftPt.getX()) {
            continue;
        }
        // the same depth info
        if (seg.isHorizontal()) {
            continue;
        }
        // skip if segment is above or below stabbing line
        if (stabbingRayLeftPt.getY() < y1 || stabbingRayLeftPt.getY() > y2) {
            continue;
        }
        // skip if stabbing ray is right of the segment
        if (CGAlgorithmsDD.orientationIndex(seg.getP0(), seg.getP1(), stabbingRayLeftPt) == CGAlgorithms.RIGHT) {
            continue;
        }
        // stabbing line cuts this segment, so record it
        int depth = dirEdge.getDepth(Position.LEFT);
        // if segment direction was flipped, use RHS depth instead
        if (!seg.getP0().equals(p1)) {
            depth = dirEdge.getDepth(Position.RIGHT);
        }
        final DepthSegment ds = new DepthSegment(seg, depth);
        stabbedSegments.add(ds);
    }
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) Point(com.revolsys.geometry.model.Point) Edge(com.revolsys.geometry.geomgraph.Edge) DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 2 with LineSegmentDouble

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

the class OffsetSegmentGenerator method addLimitedMitreJoin.

/**
 * Adds a limited mitre join connecting the two reflex offset segments.
 * A limited mitre is a mitre which is beveled at the distance
 * determined by the mitre ratio limit.
 *
 * @param offset0 the first offset segment
 * @param offset1 the second offset segment
 * @param distance the offset distance
 * @param mitreLimit the mitre limit ratio
 */
private void addLimitedMitreJoin(final LineSegment offset0, final LineSegment offset1, final double distance, final double mitreLimit) {
    final double basePtX = this.s1X;
    final double basePtY = this.s1Y;
    final double ang0 = Angle.angle2d(basePtX, basePtY, this.s0X, this.s0Y);
    final double ang2 = Angle.angle2d(basePtX, basePtY, this.s2X, this.s2Y);
    // oriented angle between segments
    final double angDiff = Angle.angleBetweenOriented(ang0, ang2);
    // half of the interior angle
    final double angDiffHalf = angDiff / 2;
    // angle for bisector of the interior angle between the segments
    final double midAng = Angle.normalize(ang0 + angDiffHalf);
    // rotating this by PI gives the bisector of the reflex angle
    final double mitreMidAng = Angle.normalize(midAng + Math.PI);
    // the miterLimit determines the distance to the mitre bevel
    final double mitreDist = mitreLimit * distance;
    // the bevel delta is the difference between the buffer distance
    // and half of the length of the bevel segment
    final double bevelDelta = mitreDist * Math.abs(Math.sin(angDiffHalf));
    final double bevelHalfLen = distance - bevelDelta;
    // compute the midpoint of the bevel segment
    final double bevelMidX = basePtX + mitreDist * Math.cos(mitreMidAng);
    final double bevelMidY = basePtY + mitreDist * Math.sin(mitreMidAng);
    // compute the mitre midline segment from the corner point to the bevel
    // segment midpoint
    final LineSegment mitreMidLine = new LineSegmentDouble(2, basePtX, basePtY, bevelMidX, bevelMidY);
    // finally the bevel segment endpoints are computed as offsets from
    // the mitre midline
    final Point bevelEndLeft = mitreMidLine.pointAlongOffset(1.0, bevelHalfLen);
    final Point bevelEndRight = mitreMidLine.pointAlongOffset(1.0, -bevelHalfLen);
    if (this.side == Position.LEFT) {
        this.segList.addPoint(bevelEndLeft);
        this.segList.addPoint(bevelEndRight);
    } else {
        this.segList.addPoint(bevelEndRight);
        this.segList.addPoint(bevelEndLeft);
    }
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 3 with LineSegmentDouble

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

the class LinearLocationTest method testGetSegmentMultiLineString.

public void testGetSegmentMultiLineString() throws Exception {
    final Geometry line = this.geometryFactory.geometry("MULTILINESTRING ((0 0, 10 0, 20 0), (20 0, 30 0))");
    final LocationIndexedLine indexedLine = new LocationIndexedLine(line);
    final LinearLocation loc0 = indexedLine.indexOf(new PointDoubleXY(0, 0));
    final LinearLocation loc0_5 = indexedLine.indexOf(new PointDoubleXY(5, 0));
    final LinearLocation loc1 = indexedLine.indexOf(new PointDoubleXY(10, 0));
    final LinearLocation loc2 = indexedLine.indexOf(new PointDoubleXY(20, 0));
    final LinearLocation loc2B = new LinearLocation(1, 0, 0.0);
    final LinearLocation loc2_5 = indexedLine.indexOf(new PointDoubleXY(25, 0));
    final LinearLocation loc3 = indexedLine.indexOf(new PointDoubleXY(30, 0));
    final LineSegment seg0 = new LineSegmentDouble(new PointDoubleXY(0, 0), new PointDoubleXY(10, 0));
    final LineSegment seg1 = new LineSegmentDouble(new PointDoubleXY(10, 0), new PointDoubleXY(20, 0));
    final LineSegment seg2 = new LineSegmentDouble(new PointDoubleXY(20, 0), new PointDoubleXY(30, 0));
    assertTrue(loc0.getSegment(line).equals(seg0));
    assertTrue(loc0_5.getSegment(line).equals(seg0));
    assertTrue(loc1.getSegment(line).equals(seg1));
    assertTrue(loc2.getSegment(line).equals(seg1));
    assertTrue(loc2_5.getSegment(line).equals(seg2));
    assertTrue(loc3.getSegment(line).equals(seg2));
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) LocationIndexedLine(com.revolsys.geometry.linearref.LocationIndexedLine) LinearLocation(com.revolsys.geometry.linearref.LinearLocation) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 4 with LineSegmentDouble

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

the class LineSegmentTest method checkOffset.

void checkOffset(final double x0, final double y0, final double x1, final double y1, final double segFrac, final double offset, final double expectedX, final double expectedY) {
    final LineSegment seg = new LineSegmentDouble(2, x0, y0, x1, y1);
    final Point p = seg.pointAlongOffset(segFrac, offset);
    assertTrue(equalsTolerance(new PointDoubleXY(expectedX, expectedY), p, 0.000001));
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 5 with LineSegmentDouble

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

the class LineSegmentTest method checkOrientationIndex.

void checkOrientationIndex(final double x0, final double y0, final double x1, final double y1, final double px, final double py, final int expectedOrient) {
    final LineSegment seg = new LineSegmentDouble(2, x0, y0, x1, y1);
    checkOrientationIndex(seg, px, py, expectedOrient);
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Aggregations

LineSegmentDouble (com.revolsys.geometry.model.segment.LineSegmentDouble)20 LineSegment (com.revolsys.geometry.model.segment.LineSegment)14 Point (com.revolsys.geometry.model.Point)10 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)5 LineString (com.revolsys.geometry.model.LineString)2 DirectedEdge (com.revolsys.geometry.geomgraph.DirectedEdge)1 Edge (com.revolsys.geometry.geomgraph.Edge)1 LinearLocation (com.revolsys.geometry.linearref.LinearLocation)1 LocationIndexedLine (com.revolsys.geometry.linearref.LocationIndexedLine)1 Geometry (com.revolsys.geometry.model.Geometry)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1