Record Class Polygon

java.lang.Object
java.lang.Record
slash.navigation.common.Polygon

public record Polygon(List<List<NavigationPosition>> rings, List<Boolean> holes, BoundingBox boundingBox) extends Record
An area defined by one or more rings of NavigationPositions, e.g. a clip polygon of an extract. Rings flagged as hole cut out of the area. Containment uses the even-odd rule, which handles holes without looking at the flag. Deliberately no java.awt.geom: this module must stay free of GUI dependencies.
Author:
Christian Pesch
  • Constructor Details

    • Polygon

      public Polygon(List<List<NavigationPosition>> rings, List<Boolean> holes, BoundingBox boundingBox)
      Creates an instance of a Polygon record class.
      Parameters:
      rings - the value for the rings record component
      holes - the value for the holes record component
      boundingBox - the value for the boundingBox record component
  • Method Details

    • of

      public static Polygon of(List<List<NavigationPosition>> rings, List<Boolean> holes)
    • contains

      public boolean contains(NavigationPosition position)
    • intersects

      public boolean intersects(BoundingBox tile)
      A corner test alone misses a narrow polygon crossing the tile, a vertex test alone misses a tile fully inside the polygon, so all three cases are checked.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • rings

      public List<List<NavigationPosition>> rings()
      Returns the value of the rings record component.
      Returns:
      the value of the rings record component
    • holes

      public List<Boolean> holes()
      Returns the value of the holes record component.
      Returns:
      the value of the holes record component
    • boundingBox

      public BoundingBox boundingBox()
      Returns the value of the boundingBox record component.
      Returns:
      the value of the boundingBox record component