Class Shape

java.lang.Object
com.takenoko.shape.Shape
Direct Known Subclasses:
Pattern

public class Shape extends Object
Class representing a Shape.
  • Field Details

  • Constructor Details

    • Shape

      public Shape(Map<PositionVector,Tile> shape, PositionVector defaultRotationOrigin)
      Constructor for the Shape class.
      Parameters:
      shape - the pattern of the shape
      defaultRotationOrigin - the default rotation origin of the shape
    • Shape

      public Shape(Map<PositionVector,Tile> shape)
      Constructor for the Shape class. The rotation origin is the element the closest to the origin of the coordinate system.
      Parameters:
      shape - the pattern of the shape
    • Shape

      public Shape(PositionVector... vectors)
      Constructor of the Shape class. To facilitate the creation of the shape, the shape is defined by a list of vectors. The rotation origin is the element the closest to the origin of the coordinate
      Parameters:
      vectors - the vectors of the shape
    • Shape

      public Shape(Shape shape)
    • Shape

      @SafeVarargs public Shape(org.apache.commons.lang3.tuple.Pair<PositionVector,Tile>... vectors)
      Constructor of the Shape class. To facilitate the creation of the shape, the shape is defined by a list of Pair of vectors and tiles. The rotation origin is the element the closest to the origin of the coordinate system.
  • Method Details

    • findOrigin

      private static PositionVector findOrigin(Map<PositionVector,Tile> shape)
      Find the rotation origin of the shape.
      Parameters:
      shape - the pattern of the shape
      Returns:
      the rotation origin of the shape
    • getElements

      public Map<PositionVector,Tile> getElements()
    • rotate60

      public Shape rotate60(PositionVector rotationOrigin)
      Returns a new shape with the same pattern but rotated 60 degrees around the given rotation rotationOrigin. see https://www.redblobgames.com/grids/hexagons/#rotation
      Parameters:
      rotationOrigin - pivot point of the rotation
      Returns:
      the rotated shape
    • rotate60

      public Shape rotate60()
      Returns a new shape with the same pattern but rotated 60 degrees around the rotation origin of the shape.
      Returns:
      the shape rotated 60 degrees around the first element of the pattern
    • getRotatedShapes

      public Set<Shape> getRotatedShapes()
    • getRotatedShape

      public Shape getRotatedShape(int i)
    • translate

      public Shape translate(PositionVector vector)
      Returns a new shape with the same pattern but translated by the given vector.
      Parameters:
      vector - the vector to translate the shape by
      Returns:
      a new shape with the same pattern but translated by the given vector
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • copy

      public Shape copy()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getMissingShape

      public Shape getMissingShape(Shape other)