Search in sources :

Example 16 with ArcByPoints

use of eu.esdihumboldt.util.geometry.interpolation.model.ArcByPoints in project hale by halestudio.

the class InterpolationUtil method isStraightLine.

/**
 * Determines if the Arc is very close to a straight line.
 *
 * @param arc the arc to check
 * @return if the arc closely represents a straight line
 */
public static boolean isStraightLine(Arc arc) {
    if (arc.isCircle()) {
        return false;
    }
    if (arc instanceof ArcByCenterPoint && Double.isInfinite(((ArcByCenterPoint) arc).getRadius())) {
        // treat as straight line if the radius is infinite
        return true;
    }
    ArcByPoints a = arc.toArcByPoints();
    double yDelta_a = a.getMiddlePoint().y - a.getStartPoint().y;
    double xDelta_a = a.getMiddlePoint().x - a.getStartPoint().x;
    double yDelta_b = a.getEndPoint().y - a.getMiddlePoint().y;
    double xDelta_b = a.getEndPoint().x - a.getMiddlePoint().x;
    double aSlope = yDelta_a / xDelta_a;
    double bSlope = yDelta_b / xDelta_b;
    if (round(aSlope, SLOPE_SCALE) == round(bSlope, SLOPE_SCALE)) {
        return true;
    }
    return false;
}
Also used : ArcByPoints(eu.esdihumboldt.util.geometry.interpolation.model.ArcByPoints) ArcByCenterPoint(eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)

Aggregations

ArcByCenterPoint (eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)16 ArcByPoints (eu.esdihumboldt.util.geometry.interpolation.model.ArcByPoints)16 Coordinate (com.vividsolutions.jts.geom.Coordinate)14 AbstractArcTest (eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest)13 Test (org.junit.Test)13 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 LineString (com.vividsolutions.jts.geom.LineString)1 ArcString (eu.esdihumboldt.util.geometry.interpolation.model.ArcString)1 HashMap (java.util.HashMap)1