Class CoordPolygon

java.lang.Object
org.rspeer.game.coord.shape.CoordPolygon
All Implemented Interfaces:
CoordShape

public class CoordPolygon extends Object implements CoordShape
Represents a polygonal region in world Coord space.

The polygon is defined by a list of vertex coordinates. Internally, a Polygon is used for point-in-polygon tests and iteration over the bounding box. All tiles within the filled polygon on the given floor level are included in this shape.

  • Method Details

    • from

      public static CoordPolygon from(Coord... vertices)
      Constructs a polygonal shape from the given vertices.

      The floor level is taken from the first vertex (or 0 if none are given).

      Parameters:
      vertices - the polygon vertices, in order
    • ignoreFloorLevel

      public CoordPolygon ignoreFloorLevel()
      Allows this polygon to match coordinates on any floor level instead of only floorLevel.
      Returns:
      this polygon (for chaining)
    • contains

      public boolean contains(SceneNode node)
      Description copied from interface: CoordShape
      Determines whether the given coordinate lies inside this shape.
      Specified by:
      contains in interface CoordShape
      Parameters:
      node - the node to test
      Returns:
      true if the shape contains the coordinate
    • getVertices

      public Set<Coord> getVertices()
      Description copied from interface: CoordShape
      Returns the set of vertices defining this shape.

      For a rectangle, this is the 4 corner coordinates. For polygons, this would be all defining polygon points.

      Specified by:
      getVertices in interface CoordShape
      Returns:
      an immutable set of shape-defining vertices
    • getBoundary

      public Set<Coord> getBoundary(boolean outer)
      Description copied from interface: CoordShape
      Returns all coordinates on the boundary (perimeter) of the shape.
      Specified by:
      getBoundary in interface CoordShape
      Parameters:
      outer - if true, returns the ring of tiles immediately surrounding the shape;
      if false, returns only the tiles forming the perimeter on the shape itself.
      Returns:
      a set of coordinates representing the boundary
    • getCoords

      public Set<Coord> getCoords()
      Description copied from interface: CoordShape
      Returns all coordinates contained within this shape.

      For large shapes, this may be a large collection.

      Specified by:
      getCoords in interface CoordShape
      Returns:
      a set of all coordinates inside the region
    • getFloorLevel

      public int getFloorLevel()
      Specified by:
      getFloorLevel in interface CoordShape
    • getPolygonView

      public CoordPolygonView getPolygonView()