}
private void _testLineString1(PicoContainer c) {
GeometryFactoryImpl tGeomFactory = (GeometryFactoryImpl) c.getComponentInstanceOfType(GeometryFactory.class);
PositionFactoryImpl tPosFactory = (PositionFactoryImpl) c.getComponentInstanceOfType(PositionFactory.class);
PrimitiveFactoryImpl tPrimFactory = (PrimitiveFactoryImpl) c.getComponentInstanceOfType(PrimitiveFactory.class);
PositionImpl p1 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{-50, 0}));
PositionImpl p2 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{-30, 30}));
PositionImpl p3 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{0, 50}));
PositionImpl p4 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{30, 30}));
PositionImpl p5 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{50, 0}));
LineStringImpl line1 = null;
/* Testing constructor of LineString with Array with size of 0 */
////System.out.println("\n***** TEST: Constructors");
//PositionImpl arrayOfPoints[] = new PositionImpl[0];
ArrayList<Position> positionList = new ArrayList<Position>();
try {
line1 = tGeomFactory.createLineString(positionList);
} catch (IllegalArgumentException e) {
//System.out.println("LineStringImpl - Number of Positions in array: 0 - Not accepted");
}
assertEquals(line1,null);
/* Testing constructor of LineString with Array with size of 1 */
positionList.add(p1);
try {
line1 = tGeomFactory.createLineString(positionList);
} catch (IllegalArgumentException e) {
//System.outprintln("LineStringImpl - Number of Positions in array: 1 - Not accepted");
}
assertEquals(line1 , null);
/* Testing constructor of LineString with Array with size of 2 */
positionList.add(p2);
try {
line1 = tGeomFactory.createLineString(positionList);
//System.outprintln("LineStringImpl - Number of Positions in array: 2 - accepted");
} catch (IllegalArgumentException e) {
//System.outprintln("LineStringImpl - Number of Positions in array: 2 - Not accepted");
}
assertNotNull(line1);
/* Testing constructor of LineString with Array with size of 5 */
positionList.add(p3);
positionList.add(p4);
positionList.add(p5);
try {
line1 = tGeomFactory.createLineString(positionList);
//System.outprintln("LineStringImpl - Number of Positions in array: 5 - accepted");
//System.outprintln("\n" + line1);
} catch (IllegalArgumentException e) {
//System.outprintln("\nLineStringImpl - Number of Positions in array: 5 - Not accepted");
}
assertNotNull(line1);
// ***** getEnvelope()
//System.outprintln("\n***** TEST: .envelope()");
//System.outprintln("Envelope of the LineString is " + line1.getEnvelope());
// ***** getStartPoint();
//System.outprintln("\n***** TEST: .startPoint()");
//System.outprintln("StartPoint: " + line1.getStartPoint());
assertEquals(line1.getStartPoint().getOrdinate(0) , -50.0);
assertEquals(line1.getStartPoint().getOrdinate(1) , 0.0);
// ***** getEndPoint();
//System.outprintln("\n***** TEST: .endPoint()");
//System.outprintln("EndPoint: " + line1.getEndPoint());
assertEquals(line1.getEndPoint().getOrdinate(0) , 50.0);
assertEquals(line1.getEndPoint().getOrdinate(1) , 0.0);
// Set curve for further LineString tests
ArrayList<CurveSegment> tLineList = new ArrayList<CurveSegment>();
tLineList.add(line1);
CurveImpl curve1 = tPrimFactory.createCurve(tLineList);
line1.setCurve(curve1);
// ***** length()
//System.outprintln("\n***** TEST: .length()");
//System.outprintln("Length of LineString is " + line1.length());
assertEquals(14422, Math.round(line1.length() * 100));
// ***** getStartParam();
//System.outprintln("\n***** TEST: .startParam()");
//System.outprintln("StartParam: " + line1.getStartParam());
assertEquals(line1.getStartParam() , 0.0);
// ***** getEndParam();
//System.outprintln("\n***** TEST: .endParam()");
//System.outprintln("EndParam: " + line1.getEndParam());
assertEquals(14422, Math.round(line1.getEndParam() * 100));
// ***** getStartConstructiveParam();
//System.outprintln("\n***** TEST: .startConstrParam()");
//System.outprintln("ConstrStartParam: " + line1.getStartConstructiveParam());
assertEquals(line1.getStartConstructiveParam() , 0.0);
// ***** getEndConstructiveParam();
//System.outprintln("\n***** TEST: .endConstrParam()");
//System.outprintln("ConstrEndParam: " + line1.getEndConstructiveParam());
assertEquals(line1.getEndConstructiveParam() , 1.0);
// Receive LineSegments from LineString
List<LineSegment> segments = line1.asLineSegments();
assertEquals(segments.size() , 4);
LineSegment seg1 = segments.get(0);
LineSegment seg2 = segments.get(1);
LineSegment seg3 = segments.get(2);
LineSegment seg4 = segments.get(3);
//System.outprintln("LineSegment: " + seg1);
//System.outprintln("LineSegment: " + seg2);
// ***** LineSegment.getStartParam()
//System.outprintln(seg1.getStartParam());
assertEquals(seg1.getStartParam() , 0.0);
// ***** LineSegment.getEndParam()
//System.outprintln(seg1.getEndParam());
assertEquals( 36, Math.round(seg1.getEndParam()) );
//System.outprintln(seg2.getStartParam());
assertEquals( 36, Math.round(seg2.getStartParam()) );
//System.outprintln(seg2.getEndParam());
assertEquals( 72, Math.round(seg2.getEndParam()) );
// ***** LineSegment.getStartConstructiveParam()
// ***** LineSegment.getEndConstructiveParam()
//System.outprintln(seg1.getStartConstructiveParam());
assertEquals(seg1.getStartConstructiveParam() , 0.0);
//System.outprintln(seg1.getEndConstructiveParam());
assertEquals(seg1.getEndConstructiveParam() , 0.25);
assertEquals(segments.get(1).getStartConstructiveParam() , 0.25);
assertEquals(segments.get(1).getEndConstructiveParam() , 0.50);
assertEquals(segments.get(2).getStartConstructiveParam() , 0.50);
assertEquals(segments.get(2).getEndConstructiveParam() , 0.75);
assertEquals(segments.get(3).getStartConstructiveParam() , 0.75);
assertEquals(segments.get(3).getEndConstructiveParam() , 1.0);
// ***** LineSegment.forParam(double)
// Parameter for forParam() is 0.0 (startparam)
DirectPosition resultPos = seg1.forParam(0.0);
//System.outprintln(resultPos);
assertEquals(resultPos.getOrdinate(0) , -50.0);
assertEquals(resultPos.getOrdinate(1) , 0.0);
// Parameter for forParam() is endparam
resultPos = seg1.forParam(seg1.getEndParam());
//System.outprintln(resultPos);
assertEquals(resultPos.getOrdinate(0) , -30.0);
assertEquals(resultPos.getOrdinate(1) , 30.0);
// Parameter for startParam out of param range
resultPos = null;
try {
resultPos = seg1.forParam(180);
} catch(IllegalArgumentException e) {
// Shall throw exception
}
//System.outprintln(resultPos);
assertEquals(resultPos , null);
resultPos = seg1.forParam(30);
//System.outprintln(resultPos);
// ***** LineSegment.getControlPoints()
assertEquals(seg1.getControlPoints().size() , 2);
// ***** LineSegment.asLineSegments()
assertEquals(seg2.asLineSegments().size() , 1);
// ***** forParam(double distance)
double[] dp = line1.forParam(0).getCoordinate();
assertEquals( -50.0, dp[0] );
assertEquals( 0.0, dp[1]);
dp = line1.forParam(line1.length()).getCoordinate();
assertEquals(50.0, dp[0]);
assertEquals(0.0, dp[1]);
dp = line1.forParam(seg1.getEndParam()).getCoordinate();
assertEquals(-30.0, dp[0]);
assertEquals(30.0, dp[1]);
dp = line1.forParam(50).getCoordinate();
////System.outprintln("forParam: " + dp[0] + "," + dp[1]);
assertEquals(Math.round(dp[0]*1000) , -18397);
assertEquals(Math.round(dp[1]*1000) , 37735);
// ***** forConstructiveParam(double distance)
dp = line1.forConstructiveParam(0.0).getCoordinate();
assertEquals(-50.0, dp[0] );
assertEquals(0.0, dp[1]);
dp = line1.forConstructiveParam(1.0).getCoordinate();
assertEquals(50.0, dp[0]);
assertEquals(0.0, dp[1]);
dp = line1.forConstructiveParam(50 / line1.length()).getCoordinate();
assertEquals(Math.round(dp[0]*1000) , -18397);
assertEquals(Math.round(dp[1]*1000) , 37735);
// ***** getTangent(double distance)
dp = line1.getTangent(0);
////System.outprintln("tangent: " + dp[0] + "," + dp[1]);
assertEquals(Math.round(dp[0]*1000) , -49445);
assertEquals(Math.round(dp[1]*1000) , 832);
dp = line1.getTangent(40);
assertEquals(Math.round(dp[0]*100) , -2589);
assertEquals(Math.round(dp[1]*100) , 3274);
dp = line1.getTangent(line1.getEndParam());
//System.outprintln("tangent: " + dp[0] + "," + dp[1]);
assertEquals(Math.round(dp[0]*100) , 5055);
assertEquals(Math.round(dp[1]*100) , -83);
// ***** merge(LineString)
PositionImpl p6 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{80, 40}));
PositionImpl p7 = new PositionImpl(tPosFactory.createDirectPosition(new double[]{130, 60}));
ArrayList<Position> positionList2 = new ArrayList<Position>();
positionList2.add(p5);
positionList2.add(p6);
positionList2.add(p7);
LineStringImpl line2 = tGeomFactory.createLineString(positionList2);