@Test public void testGetTime_threeSegments() throws ParseException { final S2Polyline lineString = (S2Polyline) wktReader.read("LINESTRING(2 5, 1 3, -1 1, -3 0)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(lineString), new Date(1000000000000L), new Date(1000001000000L)); final Point point = (Point) geometryFactory.parse("POINT(3 2)"); final Date time = timeAxis.getTime(point); assertEquals(1000000306224L, time.getTime()); }
@Test public void testGetIntersectionTime_noIntersection() { final Polygon polygon = (Polygon) geometryFactory.parse("POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))"); final S2Polyline polyline = (S2Polyline) wktReader.read("LINESTRING(0 -2,4 -2)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(polyline), new Date(100000000000L), new Date(100001000000L)); final TimeInterval timeInterval = timeAxis.getIntersectionTime(polygon); assertNull(timeInterval); }
@Test public void testGetTime_PointOnLine() throws ParseException { final S2Polyline polyline = (S2Polyline) wktReader.read("LINESTRING(0 0, 4 0)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(polyline), new Date(1000000000000L), new Date(1000001000000L)); final Point point = (Point) geometryFactory.parse("POINT(2 0)"); final Date time = timeAxis.getTime(point); assertEquals(1000000499999L, time.getTime()); }
@Test public void testGetIntersectionTime_StraightLineWithSquare_shifted() throws ParseException { final Polygon polygon = (Polygon) geometryFactory.parse("POLYGON((0 0, 0 4, 4 4, 4 0, 0 0))"); final S2Polyline polyline = (S2Polyline) wktReader.read("LINESTRING(-1 1,5 7)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(polyline), new Date(100000000000L), new Date(100001000000L)); final TimeInterval timeInterval = timeAxis.getIntersectionTime(polygon); assertNotNull(timeInterval); assertTimeIntervalEquals(100000167518L, 100000499493L, timeInterval); }
@Test public void testGetIntersectionTime_StraightLineWithSquare() { final Polygon polygon = (Polygon) geometryFactory.parse("POLYGON((0 0, 0 4, 4 4, 4 0, 0 0))"); final S2Polyline polyline = (S2Polyline) wktReader.read("LINESTRING(-2 0,4 6)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(polyline), new Date(100000000000L), new Date(100001000000L)); final TimeInterval timeInterval = timeAxis.getIntersectionTime(polygon); assertNotNull(timeInterval); assertTimeIntervalEquals(100000334421L, 100000666394L, timeInterval); }
@Test public void testGetGeometry() { final S2Polyline axisLine = (S2Polyline) wktReader.read("LINESTRING(6 2, 8 -1, 9 -4)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(axisLine), new Date(1000000000000L), new Date(1001000000000L)); final Geometry geometry = timeAxis.getGeometry(); assertEquals( "LINESTRING(6.0 2.0,7.999999999999998 -1.0,9.000000000000002 -4.0)", geometryFactory.format(geometry)); }
@Test public void testGetProjectionTime__almostNormalAngle() { final LineString lineString = (LineString) geometryFactory.parse("LINESTRING(4 -1, 5 1, 8 3)"); final S2Polyline axisLine = (S2Polyline) wktReader.read("LINESTRING(5 3, 7 0, 8 -3)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(axisLine), new Date(1000000000000L), new Date(1001000000000L)); final TimeInterval projectionTime = timeAxis.getProjectionTime(lineString); assertNotNull(projectionTime); assertEquals(1000245367407L, projectionTime.getStartTime().getTime()); assertEquals(1000409968732L, projectionTime.getStopTime().getTime()); }
@Test public void testGetIntersectionTime_StraightLineWithRectangle_line_inside() throws ParseException { final Polygon polygon = (Polygon) geometryFactory.parse("POLYGON((0 0, 0 2, 5 2, 5 0, 0 0))"); final S2Polyline polyline = (S2Polyline) wktReader.read("LINESTRING(1 1,4 1)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(polyline), new Date(100000000000L), new Date(100001000000L)); final TimeInterval timeInterval = timeAxis.getIntersectionTime(polygon); assertNotNull(timeInterval); assertTimeIntervalEquals(100000000000L, 100001000000L, timeInterval); }
@Test public void testGetProjectionTime__angle_projectedLineLonger_andInverseDirection() { final LineString lineString = (LineString) geometryFactory.parse("LINESTRING(-3 -5, -2 -2, -1 1, 1 4)"); final S2Polyline axisLine = (S2Polyline) wktReader.read("LINESTRING(-1 3, -3 0, -4 -3)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(axisLine), new Date(1000000000000L), new Date(1001000000000L)); final TimeInterval projectionTime = timeAxis.getProjectionTime(lineString); assertNotNull(projectionTime); assertEquals(1000000000000L, projectionTime.getStartTime().getTime()); assertEquals(1000999999999L, projectionTime.getStopTime().getTime()); }
@Test public void testGetProjectionTime__angle_projectedLineShorter() { final LineString lineString = (LineString) geometryFactory.parse("LINESTRING(-3 2, -4 1, -5 -1)"); final S2Polyline axisLine = (S2Polyline) wktReader.read("LINESTRING(-1 3, -3 0, -4 -3)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(axisLine), new Date(1000000000000L), new Date(1001000000000L)); final TimeInterval projectionTime = timeAxis.getProjectionTime(lineString); assertNotNull(projectionTime); assertEquals(1000286702111L, projectionTime.getStartTime().getTime()); assertEquals(1000766383826L, projectionTime.getStopTime().getTime()); }
@Test public void testGetProjectionTime_sameLine_inverseDirection() { final LineString lineString = (LineString) geometryFactory.parse("LINESTRING(-1 -8, 0 -7.2, 1 -7.5)"); final S2Polyline axisLine = (S2Polyline) wktReader.read("LINESTRING(1 -7.5, 0 -7.2, -1 -8)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(axisLine), new Date(1000000000000L), new Date(1001000000000L)); final TimeInterval projectionTime = timeAxis.getProjectionTime(lineString); assertNotNull(projectionTime); assertEquals(1000000000000L, projectionTime.getStartTime().getTime()); assertEquals(1000999999999L, projectionTime.getStopTime().getTime()); }
@Test public void testGetIntersectionTime_SegmentedLineWithParallelogram() throws ParseException { final Polygon polygon = (Polygon) geometryFactory.parse("POLYGON((2 -2, 7 -2, 9 -5, 4 -5, 2 -2))"); final S2Polyline polyline = (S2Polyline) wktReader.read("LINESTRING(1 -6, 2 -4, 4 -3, 6 -3,8 -2)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(polyline), new Date(100000000000L), new Date(100001000000L)); final TimeInterval timeInterval = timeAxis.getIntersectionTime(polygon); assertNotNull(timeInterval); assertTimeIntervalEquals(100000384991L, 100000903592L, timeInterval); }
@Test public void testGetTime_threeSegments_noProjection_beforeLineStart() throws ParseException { final S2Polyline lineString = (S2Polyline) wktReader.read("LINESTRING(1 2, -1 2, -3 4, -5 4)"); final BcS2TimeAxis timeAxis = new BcS2TimeAxis( new BcS2LineString(lineString), new Date(1000000000000L), new Date(1000001000000L)); final Point point = (Point) geometryFactory.parse("POINT(4 6)"); final Date time = timeAxis.getTime(point); assertEquals(1000000000000L, time.getTime()); // note: this is exactly the line start point time as the S2 library automatically projects // points outside to // the last/first vertex. We hope that these points are filtered during execution by the // point-in-polygon tests tb 2016-02-29 }