CurveLinearizer { public LineStringSegment linearizeArc( Arc arc, LinearizationCriterion crit ) { LineStringSegment lineSegment = null; if ( areCollinear( arc.getPoint1(), arc.getPoint2(), arc.getPoint3() ) ) { Points points = null; if ( arc instanceof Circle ) { points = new PointsList( Arrays.asList( new Point[] { arc.getPoint1(), arc.getPoint2(), arc.getPoint1() } ) ); } else { points = new PointsList( Arrays.asList( new Point[] { arc.getPoint1(), arc.getPoint3() } ) ); } lineSegment = geomFac.createLineStringSegment( points ); } else if ( crit instanceof NumPointsCriterion ) { int numPoints = ( (NumPointsCriterion) crit ).getNumberOfPoints(); lineSegment = geomFac.createLineStringSegment( interpolate( arc.getPoint1(), arc.getPoint2(), arc.getPoint3(), numPoints, arc instanceof Circle ) ); } else if ( crit instanceof MaxErrorCriterion ) { double error = ( (MaxErrorCriterion) crit ).getMaxError(); int numPoints = calcNumPoints( arc.getPoint1(), arc.getPoint2(), arc.getPoint3(), arc instanceof Circle, error ); int maxNumPoints = ( (MaxErrorCriterion) crit ).getMaxNumPoints(); if ( maxNumPoints > 0 && maxNumPoints < numPoints ) { numPoints = maxNumPoints; } LOG.debug( "Using " + numPoints + " for segment linearization." ); lineSegment = geomFac.createLineStringSegment( interpolate( arc.getPoint1(), arc.getPoint2(), arc.getPoint3(), numPoints, arc instanceof Circle ) ); } else { String msg = "Handling of criterion '" + crit.getClass().getName() + "' is not implemented yet."; throw new IllegalArgumentException( msg ); } return lineSegment; } CurveLinearizer( GeometryFactory geomFac ); Curve linearize( Curve curve, LinearizationCriterion crit ); LineStringSegment linearize( CurveSegment segment, LinearizationCriterion crit ); LineStringSegment linearizeArc( Arc arc, LinearizationCriterion crit ); LineStringSegment linearizeArcString( ArcString arcString, LinearizationCriterion crit ); LineStringSegment linearizeCubicSpline( CubicSpline spline, LinearizationCriterion crit ); static boolean areCollinear( Point p0, Point p1, Point p2 );  }
@Test public void testLinearizeArc() { double[] p0 = new double[] { .5, 0.5 }; double[] p1 = new double[] { -.5, -.2 }; double[] p2 = new double[] { -2, -0.6 }; Points positions = createLinearArc( p0, p1, p2, false ); Point lastPoint = null; for ( Point point : positions ) { if ( lastPoint != null ) { double delta = Math.sqrt( ( point.get0() - lastPoint.get0() ) * ( point.get0() - lastPoint.get0() ) + ( point.get1() - lastPoint.get1() ) * ( point.get1() - lastPoint.get1() ) ); Assert.assertEquals( 0.199115, delta, 0.000001 ); } lastPoint = point; } Assert.assertEquals( 15, positions.size() ); Assert.assertEquals( p0[0], positions.get( 0 ).get0(), 1E-15 ); Assert.assertEquals( p0[1], positions.get( 0 ).get1(), 1E-15 ); Assert.assertEquals( p2[0], positions.get( positions.size() - 1 ).get0(), 1E-15 ); Assert.assertEquals( p2[1], positions.get( positions.size() - 1 ).get1(), 1E-15 ); }