Package squidpony.squidgrid.mapping
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.
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 arrayinto
by interpreting the bits of the given long as line information.static long
encode4x4(char[][] decoded)
Reads a 2D char arraydecoded
, 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.
-
Field Details
-
lightAlt
-
heavyAlt
-
light
-
heavy
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
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 withLineKit.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 useexteriorSquare
and bitwise OR that with the restricted area.
This looks like:"┌┬┬┐" "├┼┼┤" "├┼┼┤" "└┴┴┘"
- See Also:
- Constant Field Values
-
-
Constructor Details
-
Method Details
-
decode4x4
Produces a 4x4 2D char array by interpreting the bits of the given long as line information. Uses the box drawing chars fromlight
, 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
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 oflight
,heavy
,lightAlt
, orheavyAlt
, 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) characterssymbols
- a 16-element-or-larger char array; usually a constant in this class likelight
- 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 arrayinto
by interpreting the bits of the given long as line information. Uses the given char arraysymbols
, which must have at least 16 elements and is usually one oflight
,heavy
,lightAlt
, orheavyAlt
, 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) characterssymbols
- a 16-element-or-larger char array; usually a constant in this class likelight
into
- a 2D char array that will be modified in a 4x4 areastartX
- the first x position to modify in intostartY
- the first y position to modify in into- Returns:
- into, after modification
-
encode4x4
Reads a 2D char arraydecoded
, 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 arraydecoded
must contain box drawing symbols, which can be any of those fromlight
,heavy
,lightAlt
, orheavyAlt
. 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
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
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
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
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, butrotateCounterclockwise(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
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, butrotateClockwise(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
Adjusts an existing map that uses box-drawing characters so non-visible line segments aren't rendered. Takes a map that was produced usingDungeonUtility.hashesToLines(char[][])
and a GreasedRegion that stores already-seen cells, and writes an altered version of the 2D char arraymap
towriteInto
, 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 byDungeonUtility.hashesToLines(char[][])
seen
- a GreasedRegion where "on" cells are visible now or were visible in the pastwriteInto
- 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 usingDungeonUtility.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 tolight
, and writes an altered version of the 2D char arraymap
towriteInto
, 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 byDungeonUtility.hashesToLines(char[][])
seen
- a GreasedRegion where "on" cells are visible now or were visible in the pastsymbols
- a char array that should belight
orheavy
unless you know your font supports the chars "╴╵╶╷", in which case you can uselightAlt
, or the heavy-weight versions of those chars, in which case you can useheavyAlt
writeInto
- a 2D char array that must have at least the dimensions of map; will be modified- Returns:
- writeInto, after modifications
-