Object
ChainCodesDirection

public class ChainCodesDirection extends Object
Maps directions to chain codes and vice versa.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The maximum value for a chain code, corresponding to code 0.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    chainCode(int x, int y, int z)
    Encodes a direction into a chain code.
    static Point3i
    decode(int chainCode)
    Decodes a chain-code into a point.
    static int
    xFromChainCode(int chainCode)
    Extracts the x-component from a chain code.
    static int
    yFromChainCode(int chainCode)
    Extracts the y-component from a chain code.
    static int
    zFromChainCode(int chainCode)
    Extracts the z-component from a chain code.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_VALUE

      public static final int MAX_VALUE
      The maximum value for a chain code, corresponding to code 0.
      See Also:
  • Method Details

    • decode

      public static Point3i decode(int chainCode)
      Decodes a chain-code into a point.

      TODO is it a good idea to cache the creation of chain codes, to avoid work on the heap? There is a finite number.

      Parameters:
      chainCode - the chain-code to decode
      Returns:
      a new Point3i (always newly created) for the given chain-code
    • chainCode

      public static int chainCode(int x, int y, int z)
      Encodes a direction into a chain code.
      Parameters:
      x - the x-component of the direction (-1, 0, or 1)
      y - the y-component of the direction (-1, 0, or 1)
      z - the z-component of the direction (-1, 0, or 1)
      Returns:
      the encoded chain code
    • xFromChainCode

      public static int xFromChainCode(int chainCode)
      Extracts the x-component from a chain code.
      Parameters:
      chainCode - the chain code to decode
      Returns:
      the x-component of the direction (-1, 0, or 1)
    • yFromChainCode

      public static int yFromChainCode(int chainCode)
      Extracts the y-component from a chain code.
      Parameters:
      chainCode - the chain code to decode
      Returns:
      the y-component of the direction (-1, 0, or 1)
    • zFromChainCode

      public static int zFromChainCode(int chainCode)
      Extracts the z-component from a chain code.
      Parameters:
      chainCode - the chain code to decode
      Returns:
      the z-component of the direction (-1, 0, or 1)