Class LineKit

java.lang.Object
squidpony.squidgrid.mapping.LineKit

public class LineKit
extends Object
Tools for constructing patterns using box-drawing characters.
Created by Tommy Ettinger on 1/6/2018.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static long exteriorCircleLarge
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long exteriorDiamondLarge
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long exteriorPlus
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long exteriorPlusLarge
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long exteriorSquare
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long exteriorSquareLarge
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static char[] heavy  
    static char[] heavyAlt  
    static long interiorCircleLarge
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long interiorDiamondLarge
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long interiorPlus
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long interiorPlusLarge
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long interiorSquare
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long interiorSquareLarge
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static char[] light  
    static char[] lightAlt  
    static long shallowerExteriorSquareLarge
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long shallowerInteriorSquareLarge
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long shallowExteriorSquareLarge
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
    static long shallowInteriorSquareLarge
    A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area.
  • Constructor Summary

    Constructors 
    Constructor Description
    LineKit()  
  • Method Summary

    Modifier and Type Method Description
    static char[][] decode4x4​(long encoded)
    Produces a 4x4 2D char array by interpreting the bits of the given long as line information.
    static char[][] decode4x4​(long encoded, char[] symbols)
    Produces a 4x4 2D char array by interpreting the bits of the given long as line information.
    static char[][] decodeInto4x4​(long encoded, char[] symbols, char[][] into, int startX, int startY)
    Fills a 4x4 area of the given 2D char array into by interpreting the bits of the given long as line information.
    static long encode4x4​(char[][] decoded)
    Reads a 2D char array decoded, which must be at least 4x4 in size, and returns a long that encodes the cells from 0,0 to 3,3 in a way that this class can interpret and manipulate.
    static long flipHorizontal4x4​(long encoded)
    Makes a variant on the given encoded 4x4 pattern so the left side is flipped to the right side and vice versa.
    static long flipVertical4x4​(long encoded)
    Makes a variant on the given encoded 4x4 pattern so the top side is flipped to the bottom side and vice versa.
    static char[][] pruneLines​(char[][] map, GreasedRegion seen, char[][] writeInto)
    Adjusts an existing map that uses box-drawing characters so non-visible line segments aren't rendered.
    static char[][] pruneLines​(char[][] map, GreasedRegion seen, char[] symbols, char[][] writeInto)
    Adjusts an existing map that uses box-drawing characters so non-visible line segments aren't rendered.
    static long rotateClockwise​(long encoded)
    Makes a variant on the given encoded 4x4 pattern so the lines are rotated 90 degrees clockwise, changing their positions as well as what chars they will decode to.
    static long rotateCounterclockwise​(long encoded)
    Makes a variant on the given encoded 4x4 pattern so the lines are rotated 90 degrees counterclockwise, changing their positions as well as what chars they will decode to.
    static long transpose4x4​(long encoded)
    Makes a variant on the given encoded 4x4 pattern so the x and y axes are interchanged, making the top side become the left side and vice versa, while the bottom side becomes the right side and vice versa.

    Methods inherited from class java.lang.Object

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

    • lightAlt

      public static final char[] lightAlt
    • heavyAlt

      public static final char[] heavyAlt
    • light

      public static final char[] light
    • heavy

      public static final char[] heavy
    • interiorSquare

      public static final long interiorSquare
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • exteriorSquare

      public static final long exteriorSquare
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • interiorPlus

      public static final long interiorPlus
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • exteriorPlus

      public static final long exteriorPlus
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • interiorSquareLarge

      public static final long interiorSquareLarge
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • exteriorSquareLarge

      public static final long exteriorSquareLarge
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • shallowInteriorSquareLarge

      public static final long shallowInteriorSquareLarge
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • shallowExteriorSquareLarge

      public static final long shallowExteriorSquareLarge
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • shallowerInteriorSquareLarge

      public static final long shallowerInteriorSquareLarge
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • shallowerExteriorSquareLarge

      public static final long shallowerExteriorSquareLarge
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • interiorPlusLarge

      public static final long interiorPlusLarge
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • exteriorPlusLarge

      public static final long exteriorPlusLarge
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • interiorCircleLarge

      public static final long interiorCircleLarge
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • exteriorCircleLarge

      public static final long exteriorCircleLarge
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • interiorDiamondLarge

      public static final long interiorDiamondLarge
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
    • exteriorDiamondLarge

      public static final long exteriorDiamondLarge
      A constant that represents the encoded pattern for a 4x4 square with all lines possible except those that would extend to touch cells adjacent to the 4x4 area. Meant to restrict cells within the square area by using bitwise AND with an existing encoded pattern as another long, as with LineKit.interiorSquare & encoded. If you limit the area to the square with this, you may sometimes want to add a border, and for that you can use exteriorSquare and bitwise OR that with the restricted area.
      This looks like:
       "┌┬┬┐"
       "├┼┼┤"
       "├┼┼┤"
       "└┴┴┘"
       
      See Also:
      Constant Field Values
  • Constructor Details

  • Method Details

    • decode4x4

      public static char[][] decode4x4​(long encoded)
      Produces a 4x4 2D char array by interpreting the bits of the given long as line information. Uses the box drawing chars from light, which are compatible with most fonts.
      Parameters:
      encoded - a long, which can be random, that encodes some pattern of (typically box drawing) characters
      Returns:
      a 4x4 2D char array containing elements from symbols assigned based on encoded
    • decode4x4

      public static char[][] decode4x4​(long encoded, char[] symbols)
      Produces a 4x4 2D char array by interpreting the bits of the given long as line information. Uses the given char array, which must have at least 16 elements and is usually one of light, heavy, lightAlt, or heavyAlt, with the last two usable only if using a font that supports the chars ╴╵╶╷ (this is true for Iosevka and Source Code Pro, for instance, but not Inconsolata or GoMono).
      Parameters:
      encoded - a long, which can be random, that encodes some pattern of (typically box drawing) characters
      symbols - a 16-element-or-larger char array; usually a constant in this class like light
      Returns:
      a 4x4 2D char array containing elements from symbols assigned based on encoded
    • decodeInto4x4

      public static char[][] decodeInto4x4​(long encoded, char[] symbols, char[][] into, int startX, int startY)
      Fills a 4x4 area of the given 2D char array into by interpreting the bits of the given long as line information. Uses the given char array symbols, which must have at least 16 elements and is usually one of light, heavy, lightAlt, or heavyAlt, with the last two usable only if using a font that supports the chars ╴╵╶╷ (this is true for Iosevka and Source Code Pro, for instance, but not Inconsolata or GoMono).
      Parameters:
      encoded - a long, which can be random, that encodes some pattern of (typically box drawing) characters
      symbols - a 16-element-or-larger char array; usually a constant in this class like light
      into - a 2D char array that will be modified in a 4x4 area
      startX - the first x position to modify in into
      startY - the first y position to modify in into
      Returns:
      into, after modification
    • encode4x4

      public static long encode4x4​(char[][] decoded)
      Reads a 2D char array decoded, which must be at least 4x4 in size, and returns a long that encodes the cells from 0,0 to 3,3 in a way that this class can interpret and manipulate. The 2D array decoded must contain box drawing symbols, which can be any of those from light, heavy, lightAlt, or heavyAlt. Valid chars are ╴╵┘╶─└┴╷┐│┤┌┬├┼╸╹┛╺━┗┻╻┓┃┫┏┳┣╋; any other chars will be treated as empty space.
      Parameters:
      decoded - a 2D char array that must be at least 4x4 and should usually contain box drawing characters
      Returns:
      a long that encodes the box drawing information in decoded so this class can manipulate it
    • flipHorizontal4x4

      public static long flipHorizontal4x4​(long encoded)
      Makes a variant on the given encoded 4x4 pattern so the left side is flipped to the right side and vice versa.
      Parameters:
      encoded - an encoded pattern long that represents a 4x4 area
      Returns:
      a different encoded pattern long that represents the argument flipped left-to-right
    • flipVertical4x4

      public static long flipVertical4x4​(long encoded)
      Makes a variant on the given encoded 4x4 pattern so the top side is flipped to the bottom side and vice versa.
      Parameters:
      encoded - an encoded pattern long that represents a 4x4 area
      Returns:
      a different encoded pattern long that represents the argument flipped top-to-bottom
    • transpose4x4

      public static long transpose4x4​(long encoded)
      Makes a variant on the given encoded 4x4 pattern so the x and y axes are interchanged, making the top side become the left side and vice versa, while the bottom side becomes the right side and vice versa.
      Parameters:
      encoded - an encoded pattern long that represents a 4x4 area
      Returns:
      a different encoded pattern long that represents the argument transposed top-to-left and bottom-to-right
    • rotateClockwise

      public static long rotateClockwise​(long encoded)
      Makes a variant on the given encoded 4x4 pattern so the lines are rotated 90 degrees clockwise, changing their positions as well as what chars they will decode to. This can be called twice to get a 180 degree rotation, but rotateCounterclockwise(long) should be used for a 270 degree rotation.
      Parameters:
      encoded - an encoded pattern long that represents a 4x4 area
      Returns:
      a different encoded pattern long that represents the argument rotated 90 degrees clockwise
    • rotateCounterclockwise

      public static long rotateCounterclockwise​(long encoded)
      Makes a variant on the given encoded 4x4 pattern so the lines are rotated 90 degrees counterclockwise, changing their positions as well as what chars they will decode to. This can be called twice to get a 180 degree rotation, but rotateClockwise(long) should be used for a 270 degree rotation.
      Parameters:
      encoded - an encoded pattern long that represents a 4x4 area
      Returns:
      a different encoded pattern long that represents the argument rotated 90 degrees counterclockwise
    • pruneLines

      public static char[][] pruneLines​(char[][] map, GreasedRegion seen, char[][] writeInto)
      Adjusts an existing map that uses box-drawing characters so non-visible line segments aren't rendered. Takes a map that was produced using DungeonUtility.hashesToLines(char[][]) and a GreasedRegion that stores already-seen cells, and writes an altered version of the 2D char array map to writeInto, leaving non-box-drawing chars unchanged. This method modifies writeInto in-place, and also returns it after those changesare made. The way this works is explained well with an example: if the player is north of a T-junction wall, '┬', then unless he has already explored the area south of his position, the bottom segment of the wall isn't visible to him, and so '─' should be rendered instead of '┬'. If a cell has already been seen, it is considered still visible for the purpose of calculating shown segments (it won't change once you leave an area).
      Parameters:
      map - a 2D char array that should have been produced by DungeonUtility.hashesToLines(char[][])
      seen - a GreasedRegion where "on" cells are visible now or were visible in the past
      writeInto - a 2D char array that must have at least the dimensions of map; will be modified
      Returns:
      writeInto, after modifications
    • pruneLines

      public static char[][] pruneLines​(char[][] map, GreasedRegion seen, char[] symbols, char[][] writeInto)
      Adjusts an existing map that uses box-drawing characters so non-visible line segments aren't rendered. Takes a map that was produced using DungeonUtility.hashesToLines(char[][]) a GreasedRegion that stores already-seen cells, an optional char array that refers to a line drawing style constant in this class (defaults to light, and writes an altered version of the 2D char array map to writeInto, leaving non-box-drawing chars unchanged. This method modifies writeInto in-place, and also returns it after those changes are made. The way this works is explained well with an example: if the player is north of a T-junction wall, '┬', then unless he has already explored the area south of his position, the bottom segment of the wall isn't visible to him, and so '─' should be rendered instead of '┬'. If a cell has already been seen, it is considered still visible for the purpose of calculating shown segments (it won't change once you leave an area).
      Parameters:
      map - a 2D char array that should have been produced by DungeonUtility.hashesToLines(char[][])
      seen - a GreasedRegion where "on" cells are visible now or were visible in the past
      symbols - a char array that should be light or heavy unless you know your font supports the chars "╴╵╶╷", in which case you can use lightAlt, or the heavy-weight versions of those chars, in which case you can use heavyAlt
      writeInto - a 2D char array that must have at least the dimensions of map; will be modified
      Returns:
      writeInto, after modifications