GeometryFixer { public static Curve invertOrientation( Curve curve ) { Curve fixedCurve = null; switch ( curve.getCurveType() ) { case CompositeCurve: { CompositeCurve compositeCurve = (CompositeCurve) curve; List<Curve> fixedMemberCurves = new ArrayList<Curve>( compositeCurve.size() ); for ( Curve memberCurve : compositeCurve ) { fixedMemberCurves.add( invertOrientation( memberCurve ) ); } fixedCurve = new DefaultCompositeCurve( curve.getId(), curve.getCoordinateSystem(), curve.getPrecision(), fixedMemberCurves ); break; } case Curve: { List<CurveSegment> fixedSegments = new ArrayList<CurveSegment>( curve.getCurveSegments().size() ); for ( CurveSegment segment : curve.getCurveSegments() ) { fixedSegments.add( invertOrientation( segment ) ); } Collections.reverse( fixedSegments ); fixedCurve = new DefaultCurve( curve.getId(), curve.getCoordinateSystem(), curve.getPrecision(), fixedSegments ); break; } case LineString: { LineString lineString = (LineString) curve; fixedCurve = new DefaultLineString( curve.getId(), curve.getCoordinateSystem(), curve.getPrecision(), invertOrientation( lineString.getControlPoints() ) ); break; } case OrientableCurve: { OrientableCurve orientableCurve = (OrientableCurve) curve; fixedCurve = new DefaultOrientableCurve( curve.getId(), curve.getCoordinateSystem(), invertOrientation( orientableCurve.getBaseCurve() ), orientableCurve.isReversed() ); break; } case Ring: { fixedCurve = invertOrientation( (Ring) curve ); break; } } fixedCurve.setProperties( curve.getProperties() ); return fixedCurve; }  static Ring fixUnclosedRing( Ring ring ); static Curve invertOrientation( Curve curve ); static Ring forceOrientation( Ring ring, boolean ccw ); static Ring invertOrientation( Ring ring );  }
@Test public void testInvertOrientationOfACurveWithOneSegment() { Curve curve = createSimpleCurve(); Curve invertedCurve = GeometryFixer.invertOrientation( curve ); List<CurveSegment> curveSegments = invertedCurve.getCurveSegments(); assertThat( curveSegments.size(), is( 1 ) ); CurveSegment firstCurveSegment = curveSegments.get( 0 ); assertThat( firstCurveSegment.getSegmentType(), is( LINE_STRING_SEGMENT ) ); assertThat( firstCurveSegment.getStartPoint().get0(), is( 553976.438 ) ); assertThat( firstCurveSegment.getStartPoint().get1(), is( 5937165.552 ) ); assertThat( firstCurveSegment.getEndPoint().get0(), is( 553978.334 ) ); assertThat( firstCurveSegment.getEndPoint().get1(), is( 5937293.390 ) ); }
@Test public void testInvertOrientationOfACurveWithMultipleSegments() { Curve curve = createCurve(); Curve invertedCurve = GeometryFixer.invertOrientation( curve ); List<CurveSegment> curveSegments = invertedCurve.getCurveSegments(); assertThat( curveSegments.size(), is( 3 ) ); CurveSegment firstCurveSegment = curveSegments.get( 0 ); CurveSegment secondCurveSegment = curveSegments.get( 1 ); CurveSegment thirdCurveSegment = curveSegments.get( 2 ); assertThat( firstCurveSegment.getSegmentType(), is( LINE_STRING_SEGMENT ) ); assertThat( secondCurveSegment.getSegmentType(), is( ARC ) ); assertThat( thirdCurveSegment.getSegmentType(), is( LINE_STRING_SEGMENT ) ); assertTrue( invertedCurve.isClosed() ); }