@Test public void testBelongsToLine() { assertTrue(OsmNogoPolygon.isOnLine(10,10, 10,10, 10,20)); assertTrue(OsmNogoPolygon.isOnLine(10,10, 10,10, 20,10)); assertTrue(OsmNogoPolygon.isOnLine(10,10, 20,10, 10,10)); assertTrue(OsmNogoPolygon.isOnLine(10,10, 10,20, 10,10)); assertTrue(OsmNogoPolygon.isOnLine(10,15, 10,10, 10,20)); assertTrue(OsmNogoPolygon.isOnLine(15,10, 10,10, 20,10)); assertTrue(OsmNogoPolygon.isOnLine(10,10, 10,10, 20,30)); assertTrue(OsmNogoPolygon.isOnLine(20,30, 10,10, 20,30)); assertTrue(OsmNogoPolygon.isOnLine(15,20, 10,10, 20,30)); assertFalse(OsmNogoPolygon.isOnLine(11,11, 10,10, 10,20)); assertFalse(OsmNogoPolygon.isOnLine(11,11, 10,10, 20,10)); assertFalse(OsmNogoPolygon.isOnLine(15,21, 10,10, 20,30)); assertFalse(OsmNogoPolygon.isOnLine(15,19, 10,10, 20,30)); assertFalse(OsmNogoPolygon.isOnLine(0,-10, 10,10, 20,30)); assertFalse(OsmNogoPolygon.isOnLine(30,50, 10,10, 20,30)); }
public static boolean isOnLine( long px, long py, long p0x, long p0y, long p1x, long p1y ) { final double v10x = px-p0x; final double v10y = py-p0y; final double v12x = p1x-p0x; final double v12y = p1y-p0y; if ( v10x == 0 ) { if ( v10y == 0 ) { return true; } if ( v12x != 0 ) { return false; } return ( v12y / v10y ) >= 1; } if ( v10y == 0 ) { if ( v12y != 0 ) { return false; } return ( v12x / v10x ) >= 1; } final double kx = v12x / v10x; if ( kx < 1 ) { return false; } return kx == v12y / v10y; }
OsmNogoPolygon extends OsmNodeNamed { public static boolean isOnLine( long px, long py, long p0x, long p0y, long p1x, long p1y ) { final double v10x = px-p0x; final double v10y = py-p0y; final double v12x = p1x-p0x; final double v12y = p1y-p0y; if ( v10x == 0 ) { if ( v10y == 0 ) { return true; } if ( v12x != 0 ) { return false; } return ( v12y / v10y ) >= 1; } if ( v10y == 0 ) { if ( v12y != 0 ) { return false; } return ( v12x / v10x ) >= 1; } final double kx = v12x / v10x; if ( kx < 1 ) { return false; } return kx == v12y / v10y; } }
OsmNogoPolygon extends OsmNodeNamed { public static boolean isOnLine( long px, long py, long p0x, long p0y, long p1x, long p1y ) { final double v10x = px-p0x; final double v10y = py-p0y; final double v12x = p1x-p0x; final double v12y = p1y-p0y; if ( v10x == 0 ) { if ( v10y == 0 ) { return true; } if ( v12x != 0 ) { return false; } return ( v12y / v10y ) >= 1; } if ( v10y == 0 ) { if ( v12y != 0 ) { return false; } return ( v12x / v10x ) >= 1; } final double kx = v12x / v10x; if ( kx < 1 ) { return false; } return kx == v12y / v10y; } OsmNogoPolygon(boolean closed); }
OsmNogoPolygon extends OsmNodeNamed { public static boolean isOnLine( long px, long py, long p0x, long p0y, long p1x, long p1y ) { final double v10x = px-p0x; final double v10y = py-p0y; final double v12x = p1x-p0x; final double v12y = p1y-p0y; if ( v10x == 0 ) { if ( v10y == 0 ) { return true; } if ( v12x != 0 ) { return false; } return ( v12y / v10y ) >= 1; } if ( v10y == 0 ) { if ( v12y != 0 ) { return false; } return ( v12x / v10x ) >= 1; } final double kx = v12x / v10x; if ( kx < 1 ) { return false; } return kx == v12y / v10y; } OsmNogoPolygon(boolean closed); final void addVertex(int lon, int lat); void calcBoundingCircle(); boolean intersects(int lon0, int lat0, int lon1, int lat1); boolean isOnPolyline( long px, long py ); static boolean isOnLine( long px, long py, long p0x, long p0y, long p1x, long p1y ); boolean isWithin(final long px, final long py); double distanceWithinPolygon(int lon1, int lat1, int lon2, int lat2); }
OsmNogoPolygon extends OsmNodeNamed { public static boolean isOnLine( long px, long py, long p0x, long p0y, long p1x, long p1y ) { final double v10x = px-p0x; final double v10y = py-p0y; final double v12x = p1x-p0x; final double v12y = p1y-p0y; if ( v10x == 0 ) { if ( v10y == 0 ) { return true; } if ( v12x != 0 ) { return false; } return ( v12y / v10y ) >= 1; } if ( v10y == 0 ) { if ( v12y != 0 ) { return false; } return ( v12x / v10x ) >= 1; } final double kx = v12x / v10x; if ( kx < 1 ) { return false; } return kx == v12y / v10y; } OsmNogoPolygon(boolean closed); final void addVertex(int lon, int lat); void calcBoundingCircle(); boolean intersects(int lon0, int lat0, int lon1, int lat1); boolean isOnPolyline( long px, long py ); static boolean isOnLine( long px, long py, long p0x, long p0y, long p1x, long p1y ); boolean isWithin(final long px, final long py); double distanceWithinPolygon(int lon1, int lat1, int lon2, int lat2); final List<Point> points; final boolean isClosed; }