return new CurveImpl( positionA.getCoordinateReferenceSystem(), segments );
}
private void _testCurve(GeometryBuilder builder) {
GeometryFactoryImpl tCoordFactory = (GeometryFactoryImpl) builder.getGeometryFactory();
PrimitiveFactoryImpl tPrimFactory = (PrimitiveFactoryImpl) builder.getPrimitiveFactory();
PositionImpl p1 = new PositionImpl(tCoordFactory.createDirectPosition(new double[]{-50, 0}));
PositionImpl p2 = new PositionImpl(tCoordFactory.createDirectPosition(new double[]{-30, 30}));
PositionImpl p3 = new PositionImpl(tCoordFactory.createDirectPosition(new double[]{0, 50}));
PositionImpl p4 = new PositionImpl(tCoordFactory.createDirectPosition(new double[]{30, 30}));
PositionImpl p5 = new PositionImpl(tCoordFactory.createDirectPosition(new double[]{50, 0}));
LineStringImpl line1 = null;
ArrayList<Position> positionList = new ArrayList<Position>();
positionList .add(p1);
positionList.add(p2);
positionList.add(p3);
positionList.add(p4);
positionList.add(p5);
line1 = tCoordFactory.createLineString(positionList);
/* Set parent curve for LineString */
ArrayList<CurveSegment> tLineList = new ArrayList<CurveSegment>();
tLineList.add(line1);
// PrimitiveFactory.createCurve(List<CurveSegment>)
CurveImpl curve1 = tPrimFactory.createCurve(tLineList);
//System.out.println("\nCurve1: " + curve1);
assertTrue(curve1.isCycle() == false);
// Set curve for further LineString tests
line1.setCurve(curve1);
//System.out.println("\n*** TEST: Curve\n" + curve1);
// ***** getStartPoint()
//System.out.println("\n*** TEST: .getStartPoint()\n" + curve1.getStartPoint());
assertTrue(curve1.getStartPoint().getOrdinate(0) == -50);
assertTrue(curve1.getStartPoint().getOrdinate(1) == 0);
// ***** getEndPoint()
//System.out.println("\n*** TEST: .getEndPoint()\n" + curve1.getEndPoint());
assertTrue(curve1.getEndPoint().getOrdinate(0) == 50);
assertTrue(curve1.getEndPoint().getOrdinate(1) == 0);
// ***** getStartParam()
//System.out.println("\n*** TEST: .getStartParam()\n" + curve1.getStartParam());
assertTrue(curve1.getStartParam() == 0.0);
// ***** getEndParam()
//System.out.println("\n*** TEST: .getEndParam()\n" + curve1.getEndParam());
assertTrue(Math.round(line1.getEndParam()) == 144.0);
// ***** getStartConstructiveParam()
//System.out.println("\n*** TEST: .getStartConstructiveParam()\n" + curve1.getStartConstructiveParam());
assertTrue(curve1.getStartConstructiveParam() == 0.0);
// ***** getEndConstructiveParam()
//System.out.println("\n*** TEST: .getEndConstructiveParam()\n" + curve1.getEndConstructiveParam());
assertTrue(curve1.getEndConstructiveParam() == 1.0);
// ***** getBoundary()
//System.out.println("\n*** TEST: .getBoundary()\n" + curve1.getBoundary());
CurveBoundary cb = curve1.getBoundary();
assertTrue(cb != null);
double[] dp = cb.getStartPoint().getDirectPosition().getCoordinate();
assertTrue(dp[0] == -50);
assertTrue(dp[1] == 0);
dp = cb.getEndPoint().getDirectPosition().getCoordinate();
assertTrue(dp[0] == 50);
assertTrue(dp[1] == 0);
// ***** getEnvelope()
//System.out.println("\n*** TEST: .getEnvelope()\n" + curve1.getEnvelope());
assertTrue(curve1.getEnvelope() != null);
dp = curve1.getEnvelope().getLowerCorner().getCoordinate();
assertTrue(dp[0] == -50);
assertTrue(dp[1] == 0);
dp = curve1.getEnvelope().getUpperCorner().getCoordinate();
assertTrue(dp[0] == 50);
assertTrue(dp[1] == 50);
// ***** forParam(double distance) : DirectPosition
dp = curve1.forParam(0).getCoordinate();
assertTrue(dp[0] == -50);
assertTrue(dp[1] == 0.0);
dp = curve1.forParam(curve1.length()).getCoordinate();
assertTrue(dp[0] == 50);
assertTrue(dp[1] == 0.0);
dp = curve1.forParam(50).getCoordinate();
////System.out.println("forParam: " + dp[0] + "," + dp[1]);
assertTrue(Math.round(dp[0]*1000) == -18397);
assertTrue(Math.round(dp[1]*1000) == 37735);
// ***** forConstructiveParam(double distance)
dp = curve1.forConstructiveParam(0.0).getCoordinate();
assertTrue(dp[0] == -50);
assertTrue(dp[1] == 0.0);
dp = curve1.forConstructiveParam(1.0).getCoordinate();
assertTrue(dp[0] == 50);
assertTrue(dp[1] == 0.0);
dp = curve1.forConstructiveParam(50 / curve1.length()).getCoordinate();
assertTrue(Math.round(dp[0]*1000) == -18397);
assertTrue(Math.round(dp[1]*1000) == 37735);
// ***** getTangent(double distance)
dp = curve1.getTangent(0);
////System.out.println("tangent: " + dp[0] + "," + dp[1]);
assertTrue(Math.round(dp[0]*1000) == -49445);
assertTrue(Math.round(dp[1]*1000) == 832);
dp = curve1.getTangent(40);
assertTrue(Math.round(dp[0]*100) == -2589);
assertTrue(Math.round(dp[1]*100) == 3274);
dp = curve1.getTangent(curve1.getEndParam());
//System.out.println("tangent: " + dp[0] + "," + dp[1]);
assertTrue(Math.round(dp[0]*100) == 5055);
assertTrue(Math.round(dp[1]*100) == -83);
// ***** getRepresentativePoint()
dp = curve1.getRepresentativePoint().getCoordinate();
////System.out.print("REPRER" + dp);
assertTrue(dp[0] == 0);
assertTrue(dp[1] == 50);
// ***** Curve.Merge(Curve)
DirectPosition p6 = tCoordFactory.createDirectPosition(new double[]{80, 20});
DirectPosition p7 = tCoordFactory.createDirectPosition(new double[]{130, 60});
List<DirectPosition> directPositions = new ArrayList<DirectPosition>();
directPositions.add(p5.getDirectPosition());
directPositions.add(p6);