Package org.joml

Class PolygonsIntersection


  • public class PolygonsIntersection
    extends java.lang.Object
    Class for polygon/point intersection tests when testing many points against one or many static concave or convex, simple polygons.

    This is an implementation of the algorithm described in http://alienryderflex.com and augmented with using a custom interval tree to avoid testing all polygon edges against a point, but only those that intersect the imaginary ray along the same y co-ordinate of the search point. This algorithm additionally also supports multiple polygons.

    This class is thread-safe and can be used in a multithreaded environment when testing many points against the same polygon concurrently.

    Reference: http://alienryderflex.com

    Author:
    Kai Burjack
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected float[] verticesXY  
    • Constructor Summary

      Constructors 
      Constructor Description
      PolygonsIntersection​(float[] verticesXY, int[] polygons, int count)
      Create a new PolygonsIntersection object with the given polygon vertices.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean testPoint​(float x, float y)
      Test whether the given point (x, y) lies inside any polygon stored in this PolygonsIntersection object.
      boolean testPoint​(float x, float y, java.util.BitSet inPolys)
      Test whether the given point (x, y) lies inside any polygon stored in this PolygonsIntersection object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • verticesXY

        protected final float[] verticesXY
    • Constructor Detail

      • PolygonsIntersection

        public PolygonsIntersection​(float[] verticesXY,
                                    int[] polygons,
                                    int count)
        Create a new PolygonsIntersection object with the given polygon vertices.

        The verticesXY array contains the x and y coordinates of all vertices. This array will not be copied so its content must remain constant for as long as the PolygonPointIntersection is used with it.

        Parameters:
        verticesXY - contains the x and y coordinates of all vertices
        polygons - defines the start vertices of a new polygon. The first vertex of the first polygon is always the vertex with index 0. In order to define a hole simply define a polygon that is completely inside another polygon
        count - the number of vertices to use from the verticesXY array, staring with index 0
    • Method Detail

      • testPoint

        public boolean testPoint​(float x,
                                 float y)
        Test whether the given point (x, y) lies inside any polygon stored in this PolygonsIntersection object.

        This method is thread-safe and can be used to test many points concurrently.

        In order to obtain the index of the polygon the point is inside of, use testPoint(float, float, BitSet)

        Parameters:
        x - the x coordinate of the point to test
        y - the y coordinate of the point to test
        Returns:
        true iff the point lies inside any polygon; false otherwise
        See Also:
        testPoint(float, float, BitSet)
      • testPoint

        public boolean testPoint​(float x,
                                 float y,
                                 java.util.BitSet inPolys)
        Test whether the given point (x, y) lies inside any polygon stored in this PolygonsIntersection object.

        This method is thread-safe and can be used to test many points concurrently.

        Parameters:
        x - the x coordinate of the point to test
        y - the y coordinate of the point to test
        inPolys - if not null then the i-th bit is set if the given point is inside the i-th polygon
        Returns:
        true iff the point lies inside the polygon and not inside a hole; false otherwise