Search in sources :

Example 1 with NotRepresentableException

use of com.revolsys.geometry.algorithm.NotRepresentableException in project com.revolsys.open by revolsys.

the class OffsetSegmentGenerator method addMitreJoin.

/**
 * Adds a mitre join connecting the two reflex offset segments.
 * The mitre will be beveled if it exceeds the mitre ratio limit.
 *
 * @param offset0 the first offset segment
 * @param offset1 the second offset segment
 * @param distance the offset distance
 */
private void addMitreJoin(final double x, final double y, final LineSegment offset0, final LineSegment offset1, final double distance) {
    boolean isMitreWithinLimit = true;
    double intPtX = 0;
    double intPtY = 0;
    /**
     * This computation is unstable if the offset segments are nearly collinear.
     * Howver, this situation should have been eliminated earlier by the check for
     * whether the offset segment endpoints are almost coincident
     */
    try {
        final double line1x1 = offset0.getX(0);
        final double line1y1 = offset0.getY(0);
        final double line1x2 = offset0.getX(1);
        final double line1y2 = offset0.getY(1);
        final double line2x1 = offset1.getX(0);
        final double line2y1 = offset1.getY(0);
        final double line2x2 = offset1.getX(1);
        final double line2y2 = offset1.getY(1);
        final Point intersection = HCoordinate.intersection(line1x1, line1y1, line1x2, line1y2, line2x1, line2y1, line2x2, line2y2);
        intPtX = intersection.getX();
        intPtY = intersection.getY();
        final double mitreRatio;
        if (distance <= 0.0) {
            mitreRatio = 1;
        } else {
            mitreRatio = MathUtil.distance(intPtX, intPtY, x, y) / Math.abs(distance);
        }
        if (mitreRatio > this.bufParams.getMitreLimit()) {
            isMitreWithinLimit = false;
        }
    } catch (final NotRepresentableException ex) {
        isMitreWithinLimit = false;
    }
    if (isMitreWithinLimit) {
        this.segList.addPoint(intPtX, intPtY);
    } else {
        addLimitedMitreJoin(offset0, offset1, distance, this.bufParams.getMitreLimit());
    }
}
Also used : NotRepresentableException(com.revolsys.geometry.algorithm.NotRepresentableException) Point(com.revolsys.geometry.model.Point)

Aggregations

NotRepresentableException (com.revolsys.geometry.algorithm.NotRepresentableException)1 Point (com.revolsys.geometry.model.Point)1