Search in sources :

Example 1 with MapReaderFactory

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);
    }
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) InputStreamResource(com.revolsys.spring.InputStreamResource) Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) ClassPathResource(org.springframework.core.io.ClassPathResource) IoFactoryRegistry(com.revolsys.io.IoFactoryRegistry) MapReaderFactory(com.revolsys.io.MapReaderFactory) Map(java.util.Map) InputStreamResource(com.revolsys.spring.InputStreamResource) Test(org.junit.Test)

Aggregations

IoFactoryRegistry (com.revolsys.io.IoFactoryRegistry)1 MapReaderFactory (com.revolsys.io.MapReaderFactory)1 InputStreamResource (com.revolsys.spring.InputStreamResource)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Test (org.junit.Test)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1