Beispiel #1
0
  @Test
  public void testGetDurationInMillis() {
    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));

    assertEquals(1000000000L, timeAxis.getDurationInMillis());
  }
Beispiel #2
0
  @Test
  public void testGetEndTime() {
    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 Date endTime = timeAxis.getEndTime();
    assertEquals(1001000000000L, endTime.getTime());
  }
Beispiel #3
0
  @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);
  }
Beispiel #4
0
  @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());
  }
Beispiel #5
0
  @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());
  }
Beispiel #6
0
  @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));
  }
Beispiel #7
0
  @Test
  public void testCreateSubLineTo_threePoints_secondSegment_closeToStart() {
    final S2Polyline polyline = (S2Polyline) wktReader.read("LINESTRING(-3 11, -1 13, 0 16)");
    final S2Point point = (S2Point) wktReader.read("POINT(-0.66667 14)");

    final BcS2TimeAxis timeAxis =
        new BcS2TimeAxis(new BcS2LineString(polyline), new Date(), new Date());
    final S2Polyline subLineTo = timeAxis.createSubLineTo(point);

    assertEqualPoints(subLineTo.vertex(0), polyline.vertex(0));
    assertEquals(0.06717461517369061, subLineTo.getArclengthAngle().radians(), 1e-8);
  }
Beispiel #8
0
  @Test
  public void testCreateSubLineTo_twoPoints_closeToEnd() {
    final S2Polyline polyline = (S2Polyline) wktReader.read("LINESTRING(5 3, 8 3)");
    final S2Point point = (S2Point) wktReader.read("POINT(7 3)");

    final BcS2TimeAxis timeAxis =
        new BcS2TimeAxis(new BcS2LineString(polyline), new Date(), new Date());
    final S2Polyline subLineTo = timeAxis.createSubLineTo(point);

    assertEqualPoints(subLineTo.vertex(0), polyline.vertex(0));
    assertEquals(0.034858741930189, subLineTo.getArclengthAngle().radians(), 1e-8);
  }
Beispiel #9
0
  @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);
  }
Beispiel #10
0
  @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);
  }
Beispiel #11
0
  @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());
  }
Beispiel #12
0
  @Test
  public void testCreateSubLineTo_threePoints_firstSegment_closeToEnd() {
    final S2Polyline polyline = (S2Polyline) wktReader.read("LINESTRING(-3 11, -1 13, 0 16)");
    final S2Point point = (S2Point) wktReader.read("POINT(-1.5 12.6667)");

    final BcS2TimeAxis timeAxis =
        new BcS2TimeAxis(new BcS2LineString(polyline), new Date(), new Date());
    final S2Polyline subLineTo = timeAxis.createSubLineTo(point);

    assertEquals(2, subLineTo.numVertices());
    assertEqualPoints(subLineTo.vertex(0), polyline.vertex(0));
    assertEquals(0.03871381307846636, subLineTo.getArclengthAngle().radians(), 1e-8);
  }
Beispiel #13
0
  @Test
  public void testCreateSubLineTo_threePoints_secondSegment_closeToEnd() {
    final S2Polyline polyline = (S2Polyline) wktReader.read("LINESTRING(-3 11, -1 13, 0 16)");
    final S2Point point = (S2Point) wktReader.read("POINT(-0.3333 15)");

    final BcS2TimeAxis timeAxis =
        new BcS2TimeAxis(new BcS2LineString(polyline), new Date(), new Date());
    final S2Polyline subLineTo = timeAxis.createSubLineTo(point);

    assertEquals(3, subLineTo.numVertices());
    assertEqualPoints(subLineTo.vertex(0), polyline.vertex(0));
    assertEquals(0.08551440716241719, subLineTo.getArclengthAngle().radians(), 1e-8);
  }
Beispiel #14
0
  @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);
  }
Beispiel #15
0
  @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());
  }
Beispiel #16
0
  @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());
  }
Beispiel #17
0
  @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);
  }
Beispiel #18
0
  @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());
  }
Beispiel #19
0
  @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
  }