use of com.revolsys.io.MapReaderFactory in project com.revolsys.open by revolsys.
the class LineSegmentUtilTest method intersection.
@Test
public void intersection() throws Throwable {
Resource resource = new ClassPathResource(getClass().getName().replaceAll("\\.", "/") + ".intersection.csv");
final IoFactoryRegistry registry = IoFactoryRegistry.INSTANCE;
final String filename = resource.getFilename();
final String extension = FileUtil.getFileNameExtension(filename);
final MapReaderFactory factory = registry.getFactoryByFileExtension(MapReaderFactory.class, extension);
final Reader<Map<String, Object>> reader = factory.createMapReader(new InputStreamResource(filename, resource.getInputStream()));
for (Map<String, Object> testCase : reader) {
String name = (String) testCase.get("name");
Point line1C1 = getCoordinates(testCase, "line1", "1");
Point line1C2 = getCoordinates(testCase, "line1", "2");
Point line2C1 = getCoordinates(testCase, "line2", "1");
Point line2C2 = getCoordinates(testCase, "line2", "2");
final GeometryFactory precisionModel = new SimpleGeometryFactory(1, 1);
List<Point> expectedResult = getResults(testCase);
List<Point> reverseExpectedResult = new ArrayList<Point>(expectedResult);
Collections.reverse(reverseExpectedResult);
// Start -> Start
List<Point> result1 = LineSegmentUtil.intersection(precisionModel, line1C1, line1C2, line2C1, line2C2);
Assert.assertEquals(name + " start -> start", expectedResult, result1);
// Start -> End
List<Point> result2 = LineSegmentUtil.intersection(precisionModel, line1C1, line1C2, line2C2, line2C1);
Assert.assertEquals(name + " start -> end", expectedResult, result2);
// End -> Start
List<Point> result3 = LineSegmentUtil.intersection(precisionModel, line1C2, line1C1, line2C1, line2C2);
Assert.assertEquals(name + " end -> start", reverseExpectedResult, result3);
// End -> End
List<Point> result4 = LineSegmentUtil.intersection(precisionModel, line1C2, line1C1, line2C2, line2C1);
Assert.assertEquals(name + " end -> end", reverseExpectedResult, result4);
}
}
Aggregations