Class CoordGrid

java.lang.Object
org.rspeer.game.coord.CoordGrid

public class CoordGrid extends Object
Represents a tile-aligned coordinate in a specific world matrix.

A CoordGrid corresponds to exact RuneScape tile coordinates (also called "scene coordinates" or "grid coordinates"), where each unit of x and y represents a full tile.

This is a lossy representation of CoordFine, which contains sub-tile precision. Converting from a fine coordinate to a grid coordinate will discard sub-tile offsets.

Why this type exists

CoordGrid is useful when:
  • tile-based collision checks are required
  • tile-based LOS (line of sight) traversal is used
  • indexing into arrays such as collisionMaps[floor][x][y]
  • using tile-level distance and region computations

The coordinate is immutable.

  • Method Details

    • from

      public static CoordGrid from(int matrixId, int x, int y, int floorLevel)
      Creates a new CoordGrid from raw tile coordinates.
      Parameters:
      matrixId - the matrix ID
      x - grid X (tile coordinate)
      y - grid Y (tile coordinate)
      floorLevel - floor level (0–3)
      Returns:
      a new CoordGrid
    • fromFine

      public static CoordGrid fromFine(CoordFine fine)
      Converts a CoordFine (sub-tile precision) into a tile-level CoordGrid, discarding sub-tile offset.

      Grid coordinates are computed as:

      gridX = fineX / CoordFine.UNITS_PER_SQUARE
      gridY = fineY / CoordFine.UNITS_PER_SQUARE
      
      Parameters:
      fine - the fine coordinate to convert
      Returns:
      a tile-level CoordGrid
    • fromCoord

      public static CoordGrid fromCoord(Coord coord)
      Converts a Coord (tile coordinate with sub tile fraction) into a CoordGrid. This performs a Coord.getCoordFine() and then reduces to tile units.
      Parameters:
      coord - the world coordinate
      Returns:
      a tile-level CoordGrid
    • getMatrixId

      public int getMatrixId()
    • getX

      public int getX()
    • getY

      public int getY()
    • getFloorLevel

      public int getFloorLevel()
    • getSceneContext

      public SceneContext getSceneContext()
    • equals

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

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

      public String toString()
      Overrides:
      toString in class Object