Class CoordFine


  • public class CoordFine
    extends Object
    Represents a coordinate in fine space, where each world tile (Coord) is composed of 128 fine units. Fine space provides sub-tile precision used for movement, interpolation, animation, and rendering.

    A CoordFine stores:

    • matrixId – the ID of the RSWorldMatrix defining the local scene origin
    • x – fine-space X coordinate (matrix-relative)
    • y – fine-space Y coordinate (matrix-relative)
    • floorLevel – the plane (0–3)

    The coordinate is expressed in matrix-relative fine space. To convert a world Coord into fine units, the world matrix base coordinates are subtracted, then multiplied by 128, then sub-tile offsets are added.

    One full world tile equals 128 fine units.

    In the game engine, this is referred to as CoordFine

    • Method Detail

      • precision

        public static int precision​(int granularity)
        Computes the fine-unit step size for a given subdivision precision.

        For example:

         precision(1) = 128   // whole tile
         precision(2) = 64    // half-tile
         precision(4) = 32    // quarter-tile
         precision(8) = 16    // eighth-tile
         
        Parameters:
        granularity - number of subdivisions per tile (must divide 128)
        Returns:
        the fine-unit size of each subdivided segment
      • from

        public static CoordFine from​(int matrixId,
                                     int x,
                                     int y,
                                     int floorLevel)
        Constructs a new fine coordinate at the given matrix-relative fine X/Y values.

        The coordinate is associated with a specific world matrix identified by matrixId. The values x and y are interpreted directly in matrix-relative fine space (not world-absolute space).

        Parameters:
        matrixId - the ID of the world matrix defining the local scene origin
        x - fine-space X coordinate, relative to that matrix
        y - fine-space Y coordinate, relative to that matrix
        floorLevel - the floor/plane (0–3)
        Returns:
        a new CoordFine representing the given matrix-relative fine position
      • from

        public static CoordFine from​(int matrixId,
                                     int x,
                                     int y)
        Constructs a new fine coordinate on floor level 0, using the given matrix ID as the scene origin.
        Parameters:
        matrixId - the ID of the world matrix defining the local scene origin
        x - fine-space X coordinate, relative to that matrix
        y - fine-space Y coordinate, relative to that matrix
        Returns:
        a new CoordFine on floor level 0
      • fromCoord

        public static CoordFine fromCoord​(RSWorldMatrix matrix,
                                          Coord coord,
                                          int subX,
                                          int subY)
        Converts a world tile coordinate into a fine coordinate *relative to a specific RSWorldMatrix*, using the given sub-tile offsets.

        The world-space Coord is first transformed into scene-space by subtracting matrix.getBaseX() and matrix.getBaseY(). The resulting scene-space tile coordinates are then scaled into fine units (128 per tile), and finally subX and subY are added to position the coordinate within the tile.

        subX and subY must be in the range 0–127, representing the fine-unit offset inside a tile.

        Parameters:
        matrix - the world matrix providing the base/scene origin
        coord - the world-space tile coordinate to convert
        subX - fine X offset within the tile (0–127)
        subY - fine Y offset within the tile (0–127)
        Returns:
        a CoordFine representing the matrix-relative fine location
      • fromCoord

        public static CoordFine fromCoord​(Coord coord,
                                          int subX,
                                          int subY)
        Converts a world tile coordinate into a fine coordinate *relative to the matrix associated with the given Coord*, using the specified sub-tile offsets.

        This is a convenience overload that resolves the appropriate RSWorldMatrix by calling Game.getMatrixAt(coord), then delegates to fromCoord(RSWorldMatrix, Coord, int, int).

        Parameters:
        coord - the world-space tile coordinate
        subX - fine X offset within the tile (0–127)
        subY - fine Y offset within the tile (0–127)
        Returns:
        a CoordFine representing the matrix-relative fine location
      • fromCoordOrigin

        public static CoordFine fromCoordOrigin​(RSWorldMatrix matrix,
                                                Coord coord)
        Creates a fine coordinate at the exact origin (bottom-left corner) of a world tile, relative to the given RSWorldMatrix.

        The world-space Coord is first converted into scene-space using the provided matrix, then scaled into fine units (128 per tile). The resulting fine coordinate will be at sub-tile offsets (0, 0).

        Parameters:
        matrix - the world matrix providing the base/scene origin
        coord - the world-space tile coordinate
        Returns:
        a CoordFine located at the tile origin in matrix-relative fine space
      • fromCoordOrigin

        public static CoordFine fromCoordOrigin​(Coord coord)
        Creates a fine coordinate at the exact origin (bottom-left corner) of a world tile, relative to the matrix associated with the given coord.

        This is a convenience overload that resolves the appropriate RSWorldMatrix via Game.getMatrixAt(coord), then delegates to fromCoordOrigin(RSWorldMatrix, Coord).

        Parameters:
        coord - the world-space tile coordinate
        Returns:
        a CoordFine located at the tile origin in matrix-relative fine space
      • fromCoordCenter

        public static CoordFine fromCoordCenter​(RSWorldMatrix matrix,
                                                Coord coord)
        Creates a fine coordinate at the center of a world tile, relative to the given RSWorldMatrix.

        This uses precision(2) (which equals 64 fine units), placing the coordinate at the center of the tile at sub-tile offsets (64, 64).

        Parameters:
        matrix - the world matrix providing the base/scene origin
        coord - the world-space tile coordinate
        Returns:
        a CoordFine located at the tile center in matrix-relative fine space
      • fromCoordCenter

        public static CoordFine fromCoordCenter​(Coord coord)
        Creates a fine coordinate at the center of a world tile, relative to the matrix associated with the given coord.

        This is a convenience overload that resolves the appropriate RSWorldMatrix via Game.getMatrixAt(coord), then delegates to fromCoordCenter(RSWorldMatrix, Coord).

        Parameters:
        coord - the world-space tile coordinate
        Returns:
        a CoordFine located at the tile center in matrix-relative fine space
      • getCoordView

        public CoordView getCoordView()
      • getSceneContext

        public SceneContext getSceneContext​(int matrixId)
      • getMatrixId

        public int getMatrixId()
      • getX

        public int getX()
      • getY

        public int getY()
      • getFloorLevel

        public int getFloorLevel()
      • getSubX

        public int getSubX()
        Returns the fine X offset within the current tile.

        Equivalent to x % 128.

        Returns:
        sub-tile X offset in the range 0–127
      • getSubY

        public int getSubY()
        Returns the fine Y offset within the current tile.

        Equivalent to y % 128.

        Returns:
        sub-tile Y offset in the range 0–127
      • translate

        public CoordFine translate​(int x,
                                   int y,
                                   int granularity)
        Translates this fine coordinate by a movement expressed in tile units, scaled by a specified granularity.

        Granularity defines how many sbdivisions a tile is split into:

         granularity = 1  -> full tile movement      (128 fine units)
         granularity = 2  -> half-tile movement      ( 64 fine units)
         granularity = 4  -> quarter-tile movement   ( 32 fine units)
         granularity = 8  -> eighth-tile movement    ( 16 fine units)
         ...
         
        Parameters:
        x - the delta along the tile X axis (positive = east, negative = west)
        y - the delta along the tile Y axis (positive = north, negative = south)
        granularity - how many equal subdivisions of a tile to move per unit of x/y
        Returns:
        a new CoordFine offset by (x, y) at the given granularity
      • translate

        public CoordFine translate​(int x,
                                   int y)
        Parameters:
        x - The fine x units to translate
        y - The fine y units to translate
        Returns:
        a new CoordFine offset by (x, y)
      • translateHalfCoord

        public CoordFine translateHalfCoord()
      • translate

        public CoordFine translate​(Direction direction,
                                   int granularity)
        Translates this fine coordinate in the direction specified by Direction, scaled by the given granularity.

        This is equivalent to:

         translate(direction.getXOffset(), direction.getYOffset(), granularity)
         
        Parameters:
        direction - the movement direction (supports 4, 8, or 16 movement directions)
        granularity - how many subdivisions of a tile to move in the given direction
        Returns:
        a new CoordFine representing the translated position
      • dx

        public CoordFine dx​(int x,
                            int granularity)
        Translates this fine coordinate horizontally (along the X axis) by a fractional tile amount determined by the given granularity.

        Positive x moves east; negative moves west.

        Parameters:
        x - the tile-based horizontal delta
        granularity - how many subdivisions of a tile to move per unit of x
        Returns:
        a new CoordFine representing the translated position
      • dy

        public CoordFine dy​(int y,
                            int granularity)
        Translates this fine coordinate vertically (along the Y axis) by a fractional tile amount determined by the given granularity.

        Positive y moves north; negative moves south.

        Parameters:
        y - the tile-based vertical delta
        granularity - how many subdivisions of a tile to move per unit of y
        Returns:
        a new CoordFine representing the translated position
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object