src/main/java/de/blau/android/util/Geometry.java
/**
     * Check if Node lies inside a polygon
     * 
     * Based on the code and algorithm from
     * https://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/
     *
     * Note: assumes planar geometry
     * 
     * @param polygon a Array of Node defining the polygon
     * @param node the Node
     * @return true if the Node is in the polygon
     */
Check if Node lies inside a polygon



assumes planar geometry

@param polygon a Array of Node defining the polygon
@param node the Node
@return true if the Node is in the polygon
Check if Node lies inside a polygon assumes planar geometry @param polygon a Array of Node defining the polygon @param node the Node @return true if the Node is in the polygon
public static boolean isInside(@NonNull Node[] polygon, @NonNull Node node) {
        int n = polygon.length;
        if (n < 3) {
            throw new IllegalArgumentException("There must be at least 3 vertices in a polygon");
        }
        Node extreme = App.getDelegator().getFactory().createNodeWithNewId(node.getLat(), (int) (200 * 1E7));
        int intersections = 0;
        int i = 0;
        do {
            int next = (i + 1) % n;
            if (intersect(polygon[i], polygon[next], node, extreme)) {
                if (winding(polygon[i], node, polygon[next]) == COLINEAR) {
                    return onSegment(polygon[i], node, polygon[next]);
                }
                intersections++;
            }
            i = next;
        } while (i != 0);
        return (intersections % 2 == 1);
    }
public static boolean isInside ( @ NonNull Node [ ] polygon , @ NonNull Node node ) { int n = polygon . length ; if ( n < 3 ) { throw new IllegalArgumentException ( "There must be at least 3 vertices in a polygon" ) ; } Node extreme = App . getDelegator ( ) . getFactory ( ) . createNodeWithNewId ( node . getLat ( ) , ( int ) ( 200 * 1E7 ) ) ; int intersections = 0 ; int i = 0 ; do { int next = ( i + 1 ) % n ; if ( intersect ( polygon [ i ] , polygon [ next ] , node , extreme ) ) { if ( winding ( polygon [ i ] , node , polygon [ next ] ) == COLINEAR ) { return onSegment ( polygon [ i ] , node , polygon [ next ] ) ; } intersections ++ ; } i = next ; } while ( i != 0 ) ; return ( intersections % 2 == 1 ) ; }
Check if Node lies inside a polygon
Check if Node lies inside a polygon