Class Mask

java.lang.Object
com.petrolpark.util.Mask
All Implemented Interfaces:
Cloneable

public class Mask extends Object implements Cloneable
A set of "enabled" pixels in a global 2D grid.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.Codec<Mask>
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    and(Mask mask)
    Intersect this Mask with the given Mask.
    void
    andNot(Mask mask)
    Subtract the given Mask from this one.
    void
    clear(int x, int y)
    Removes the given pixel from this Mask.
     
    void
    combine(Mask mask, Mask.Combination combination)
    Perform a binary operation on this Mask based on the contents of the given Mask.
    void
    cover(int minX, int minY, int maxX, int maxY)
    Does not change this Mask, but expands the BitSet internally to cover at least the given space.
    void
    cover(Mask other)
    Does not change this Mask, but expands the BitSet internally to cover the space occupied by the given Mask.
    downsample(int factor)
    Get a new Mask by splitting this Mask into factor by factor blocks and setting pixels in that Mask if any pixels in the corresponding block in this Mask are set.
    boolean
     
    static final com.mojang.serialization.Codec<Mask>
    friendlyCodecSized(int maxWidth, int maxHeight)
     
    static final Mask
    fromRowStrings(int xOffset, int yOffset, List<String> rowStrings)
    Deserialize a Mask.
    static final Mask
    fromTo(int fromX, int fromY, int toX, int toY)
    Construct a Mask with the given upper and lower corners.
    boolean
    get(int x, int y)
     
    boolean
    getRegion(int minX, int minY, int maxX, int maxY)
    true if any pixels are set in the given region
    int
    Get the internal x maximum of this Mask.
    int
    Get the internal y maximum of this Mask.
    int
    Get the internal x origin of this Mask.
    int
    Get the internal y origin of this Mask.
    void
    move(int dX, int dY)
    Moves every pixel in this Mask.
    void
    or(Mask mask)
    Effectively add the given Mask to this one.
    static final Mask
    rect(int x, int y, int width, int height)
    Construct a Mask at the given position of the given size.
    List<net.minecraft.client.renderer.Rect2i>
    Convert this Mask to a List of rectangles.
    Serialize this Mask.
    void
    set(int x, int y)
    Sets the given pixel in this Mask.

    Methods inherited from class java.lang.Object

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

    • FRIENDLY_CODEC

      public static final com.mojang.serialization.Codec<Mask> FRIENDLY_CODEC
  • Method Details

    • friendlyCodecSized

      public static final com.mojang.serialization.Codec<Mask> friendlyCodecSized(int maxWidth, int maxHeight)
    • cover

      public void cover(Mask other)
      Does not change this Mask, but expands the BitSet internally to cover the space occupied by the given Mask.
      See Also:
      • Inverse
    • cover

      public void cover(int minX, int minY, int maxX, int maxY)
      Does not change this Mask, but expands the BitSet internally to cover at least the given space.
      See Also:
      • trim()
    • minX

      public int minX()
      Get the internal x origin of this Mask. This is at most but not necessarily equal to the x coordinate of the leftmost set pixel. To ensure equality, call trim().
    • minY

      public int minY()
      Get the internal y origin of this Mask. This is at most but not necessarily equal to the y coordinate of the topmost set pixel. To ensure equality, call trim().
    • maxX

      public int maxX()
      Get the internal x maximum of this Mask. This is at most but not necessarily equal to the x coordinate of the rightmost set pixel. To ensure equality, call trim().
    • maxY

      public int maxY()
      Get the internal y maximum of this Mask. This is at most but not necessarily equal to the y coordinate of the bottommost set pixel. To ensure equality, call trim().
    • get

      public boolean get(int x, int y)
    • getRegion

      public boolean getRegion(int minX, int minY, int maxX, int maxY)
      true if any pixels are set in the given region
      Parameters:
      minX -
      minY -
      maxX -
      maxY -
    • set

      public void set(int x, int y)
      Sets the given pixel in this Mask.
      Parameters:
      x -
      y -
    • clear

      public void clear(int x, int y)
      Removes the given pixel from this Mask.
      Parameters:
      x -
      y -
      See Also:
      • Make the Mask internally as small as possible after doing this
    • move

      public void move(int dX, int dY)
      Moves every pixel in this Mask.
      Parameters:
      dX -
      dY -
    • combine

      public void combine(Mask mask, Mask.Combination combination)
      Perform a binary operation on this Mask based on the contents of the given Mask. This modifies this Mask, but not the given one.
      Parameters:
      mask -
      combination -
      See Also:
    • or

      public void or(Mask mask)
      Effectively add the given Mask to this one. This modifies this Mask, but not the given one.
      Parameters:
      mask -
      See Also:
    • and

      public void and(Mask mask)
      Intersect this Mask with the given Mask. This modifies this Mask, but not the given one.
      Parameters:
      mask -
      See Also:
    • andNot

      public void andNot(Mask mask)
      Subtract the given Mask from this one. This modifies this Mask, but not the given one.
      Parameters:
      mask -
      See Also:
    • equals

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

      public Mask clone()
      Overrides:
      clone in class Object
    • rowStrings

      public List<String> rowStrings()
      Serialize this Mask. Set pixels will be represented with a . and unset pixels with a space.
    • downsample

      public Mask downsample(int factor)
      Get a new Mask by splitting this Mask into factor by factor blocks and setting pixels in that Mask if any pixels in the corresponding block in this Mask are set.
      Parameters:
      factor -
    • fromRowStrings

      public static final Mask fromRowStrings(int xOffset, int yOffset, List<String> rowStrings)
      Deserialize a Mask. Spaces represent unset pixels and any other symbols represent set pixels.
      Parameters:
      xOffset - Horizontal offset to apply to the whole Mask. The same effect would be achieved by including xOffset spaces at the front of every line, but this field can also work for negative offsets.
      yOffset - Vertical offset to apply to the whole Mask. The same effect would be achieved by including yOffset empty lines at the start, but this field can also work for negative offsets.
      rowStrings - Must have all Strings the same length
    • rectangularize

      public List<net.minecraft.client.renderer.Rect2i> rectangularize()
      Convert this Mask to a List of rectangles. More horizontal rectangles are preferred.
      Returns:
      List of rectangles covering every pixel in this Mask exactly once.
    • rect

      public static final Mask rect(int x, int y, int width, int height)
      Construct a Mask at the given position of the given size.
      Parameters:
      x -
      y -
      width -
      height -
      See Also:
    • fromTo

      public static final Mask fromTo(int fromX, int fromY, int toX, int toY)
      Construct a Mask with the given upper and lower corners.
      Parameters:
      fromX -
      fromY -
      toX -
      toY -
      See Also: