Record Class Coordinate

java.lang.Object
java.lang.Record
com.expedient.adventofcodejade.common.Coordinate
Record Components:
row -
col -

public record Coordinate(int row, int col) extends Record
Represents a row, col Coordinate on a 2D array
  • Constructor Details

    • Coordinate

      public Coordinate(int row, int col)
      Creates an instance of a Coordinate record class.
      Parameters:
      row - the value for the row record component
      col - the value for the col record component
  • Method Details

    • nextInDirection

      public Coordinate nextInDirection(Coordinate other)
      Provided a Coordinates, returns another Coordinate that's one additional step in the same direction from this one
      Parameters:
      other - Ending Coordinate
      Returns:
      Coordinate that continues in a line out from the second
    • inOppositeDirection

      public Coordinate inOppositeDirection(Coordinate other)
      Provided other Coordinate, returns another Coordinate that's on the opposite side of this one from the second
      Parameters:
      other - Ending Coordinate
      Returns:
      Coordinate one step from the first in the opposite direction
    • isOrthogonal

      public boolean isOrthogonal(Coordinate other)
      Determines whether this Coordinate is orthogonal to another
      Parameters:
      other - the other coordinate
      Returns:
      whether they're orthogonal
    • taxiCabDistance

      public int taxiCabDistance(Coordinate other)
      Finds the taxicab distance between this coordinate and another
      Parameters:
      other - the other coordinate
      Returns:
      the taxicab distance between the two
    • directionToCoordinate

      public Direction directionToCoordinate(Coordinate c2)
    • distance

      public double distance(Coordinate other)
      Finds the Euclidean distance between this coordinate and another
      Parameters:
      other - the other coordinate
      Returns:
      the Euclidean distance between the two coordinates
    • topLeft

      public Coordinate topLeft()
    • topCenter

      public Coordinate topCenter()
    • topRight

      public Coordinate topRight()
    • centerRight

      public Coordinate centerRight()
    • bottomRight

      public Coordinate bottomRight()
    • bottomCenter

      public Coordinate bottomCenter()
    • bottomLeft

      public Coordinate bottomLeft()
    • centerLeft

      public Coordinate centerLeft()
    • 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 the compare method from their corresponding wrapper classes.
      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.
    • row

      public int row()
      Returns the value of the row record component.
      Returns:
      the value of the row record component
    • col

      public int col()
      Returns the value of the col record component.
      Returns:
      the value of the col record component