class OsmNogoPolygon extends OsmNodeNamed {

  public boolean intersects(int lon0, int lat0, int lon1, int lat1)
  {
    final Point p0 = new Point (lon0,lat0);
    final Point p1 = new Point (lon1,lat1);
    int i_last = points.size()-1;
    Point p2 = points.get(isClosed ? i_last : 0 );
    for (int i = isClosed ? 0 : 1 ; i <= i_last; i++)
    {
      Point p3 = points.get(i);
      // does it intersect with at least one of the polygon's segments?
      if (intersect2D_2Segments(p0,p1,p2,p3) > 0)
      {
        return true;
      }
      p2 = p3;
    }
    return false;
  }

}

class OsmNogoPolygonTest {

  static final int OFFSET_X;
  static final int OFFSET_Y;
  static OsmNogoPolygon polygon;
  static OsmNogoPolygon polyline;
  static final double[] lons;
  static final double[] lats;

  @Test
  public void testIntersectsPolyline() {

    double[] p0lons  = {   0.0,   1.0,  -0.5,  0.5,  0.7,  0.7,  0.7,  -1.5, -1.5,   0.0 };
    double[] p0lats  = {   0.0,   0.0,   0.5,  0.5,  0.5,  0.05, 0.05, -1.5,  0.2,   0.0 };
    double[] p1lons  = {   0.0,   1.0,   0.5,  1.0,  0.7,  0.7,  0.7,  -0.5, -0.2,   0.5 };
    double[] p1lats  = {   0.0,   0.0,   0.5,  0.5, -0.5, -0.5, -0.05, -0.5,  1.5,  -1.5 };
    boolean[] within = { false, false, false, true, true, true, false, true, true, false };

    for (int i=0; i<p0lons.length; i++) {
      assertEquals("("+p0lons[i]+","+p0lats[i]+")-("+p1lons[i]+","+p1lats[i]+")",within[i],polyline.intersects(toOsmLon(p0lons[i], OFFSET_X), toOsmLat(p0lats[i], OFFSET_Y), toOsmLon(p1lons[i], OFFSET_X), toOsmLat(p1lats[i], OFFSET_Y)));
    }
  }

}