java.lang.Object
com.io7m.jregions.core.unparameterized.areas.AreasI

public final class AreasI
extends java.lang.Object

Functions over areas.

These functions operate using the concepts of minimum-x, maximum-x, minimum-y, and maximum-y edges. It is up to individual applications to assign meaning to these edges such as "left" for minimum-x and "top" for minimum-y.

  • Method Details

    • create

      public static AreaI create​(int x, int y, int size_x, int size_y)
      Create an area of size size_x on the X axis and size size_y on the Y axis, placing the minimum corner at (x, y).
      Parameters:
      x - The X value of the minimum corner
      y - The Y value of the minimum corner
      size_x - The size of the area on the X axis
      size_y - The size of the area on the Y axis
      Returns:
      An area
    • contains

      public static boolean contains​(AreaI a, AreaI b)

      Determine whether or not one area contains another.

      Containing is reflexive: contains(a, a) == true.

      Containing is transitive: contains(a, b) → contains(b, c) → contains(a, c).

      Containing is not necessarily symmetric.

      Parameters:
      a - Area A
      b - Area B
      Returns:
      true iff a contains b
    • moveRelative

      public static AreaI moveRelative​(AreaI area, int x, int y)
      Move the given area by (x, y).
      Parameters:
      area - The area
      x - The amount to move on the X axis
      y - The amount to move on the Y axis
      Returns:
      A moved area
    • moveRelativeClampedX

      public static AreaI moveRelativeClampedX​(AreaI container, AreaI area, int x)
      Move the given area by x, without allowing area to leave container.
      Parameters:
      container - The container area
      area - The area
      x - The amount to move on the X axis
      Returns:
      A moved area
      Since:
      3.0.0
    • moveRelativeClampedY

      public static AreaI moveRelativeClampedY​(AreaI container, AreaI area, int y)
      Move the given area by y, without allowing area to leave container.
      Parameters:
      container - The container area
      area - The area
      y - The amount to move on the Y axis
      Returns:
      A moved area
      Since:
      3.0.0
    • moveRelativeClamped

      public static AreaI moveRelativeClamped​(AreaI container, AreaI area, int x, int y)
      Move the given area by (x, y), without allowing area to leave container.
      Parameters:
      container - The container area
      area - The area
      x - The amount to move on the X axis
      y - The amount to move on the Y axis
      Returns:
      A moved area
      Since:
      3.0.0
    • moveAbsolute

      public static AreaI moveAbsolute​(AreaI area, int x, int y)
      Move the given area to (x, y).
      Parameters:
      area - The area
      x - The position to which to move on the X axis
      y - The position to which to move on the Y axis
      Returns:
      A moved area
    • moveToOrigin

      public static AreaI moveToOrigin​(AreaI area)
      Move the given area to (0, 0).
      Parameters:
      area - The area
      Returns:
      A moved area
    • alignOnXCenter

      public static AreaI alignOnXCenter​(AreaI outer, AreaI inner)
      Align the area inner along the X axis in the center of outer.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
      Since:
      1.1.0
    • alignOnXMinX

      public static AreaI alignOnXMinX​(AreaI outer, AreaI inner)
      Equivalent to calling alignOnXMinXOffset(AreaI, AreaI, int) with a zero offset.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
      Since:
      1.1.0
    • alignOnXMinXOffset

      public static AreaI alignOnXMinXOffset​(AreaI outer, AreaI inner, int offset)
      Align the area inner along the X axis against the inside minimum-x edge of outer. The area will be at least offset units from the minimum-x edge.
      Parameters:
      outer - The outer area
      inner - The inner area
      offset - The offset from the edge
      Returns:
      An aligned area
      Since:
      1.1.0
    • alignOnXMaxX

      public static AreaI alignOnXMaxX​(AreaI outer, AreaI inner)
      Equivalent to calling alignOnXMaxXOffset(AreaI, AreaI, int) with a zero offset.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
      Since:
      1.1.0
    • alignOnXMaxXOffset

      public static AreaI alignOnXMaxXOffset​(AreaI outer, AreaI inner, int offset)
      Align the area inner along the X axis against the inside maximum-x edge of outer. The area will be at least offset units from the maximum-x edge.
      Parameters:
      outer - The outer area
      inner - The inner area
      offset - The offset from the edge
      Returns:
      An aligned area
      Since:
      1.1.0
    • alignOnYMinY

      public static AreaI alignOnYMinY​(AreaI outer, AreaI inner)
      Equivalent to calling alignOnYMinYOffset(AreaI, AreaI, int) with a zero offset.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
      Since:
      1.1.0
    • alignOnYMinYOffset

      public static AreaI alignOnYMinYOffset​(AreaI outer, AreaI inner, int offset)
      Align the area inner along the Y axis against the inside minimum-y edge of outer. The area will be at least offset units from the minimum-y edge.
      Parameters:
      outer - The outer area
      inner - The inner area
      offset - The offset from the edge
      Returns:
      An aligned area
      Since:
      1.1.0
    • alignOnYMaxY

      public static AreaI alignOnYMaxY​(AreaI outer, AreaI inner)
      Equivalent to calling alignOnYMaxYOffset(AreaI, AreaI, int) with a zero offset.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
      Since:
      1.1.0
    • alignOnYMaxYOffset

      public static AreaI alignOnYMaxYOffset​(AreaI outer, AreaI inner, int offset)
      Align the area inner along the Y axis against the inside maximum-y edge of outer. The area will be at least offset units from the maximum-y edge.
      Parameters:
      outer - The outer area
      inner - The inner area
      offset - The offset from the edge
      Returns:
      An aligned area
      Since:
      1.1.0
    • alignOnYCenter

      public static AreaI alignOnYCenter​(AreaI outer, AreaI inner)
      Align the area inner along the Y axis in the center of outer.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
      Since:
      1.1.0
    • alignHorizontallyCenter

      @Deprecated public static AreaI alignHorizontallyCenter​(AreaI outer, AreaI inner)
      Align the area inner horizontally in the center of outer.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
    • alignHorizontallyMinX

      @Deprecated public static AreaI alignHorizontallyMinX​(AreaI outer, AreaI inner)
      Equivalent to calling alignHorizontallyMinXOffset(AreaI, AreaI, int) with a zero offset.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
    • alignHorizontallyMinXOffset

      @Deprecated public static AreaI alignHorizontallyMinXOffset​(AreaI outer, AreaI inner, int offset)
      Align the area inner horizontally against the inside minimum-x edge of outer. The area will be at least offset units from the minimum-x edge.
      Parameters:
      outer - The outer area
      inner - The inner area
      offset - The offset from the edge
      Returns:
      An aligned area
    • alignHorizontallyMaxX

      @Deprecated public static AreaI alignHorizontallyMaxX​(AreaI outer, AreaI inner)
      Equivalent to calling alignHorizontallyMaxXOffset(AreaI, AreaI, int) with a zero offset.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
    • alignHorizontallyMaxXOffset

      @Deprecated public static AreaI alignHorizontallyMaxXOffset​(AreaI outer, AreaI inner, int offset)
      Align the area inner horizontally against the inside maximum-x edge of outer. The area will be at least offset units from the maximum-x edge.
      Parameters:
      outer - The outer area
      inner - The inner area
      offset - The offset from the edge
      Returns:
      An aligned area
    • alignVerticallyMinY

      @Deprecated public static AreaI alignVerticallyMinY​(AreaI outer, AreaI inner)
      Equivalent to calling alignVerticallyMinYOffset(AreaI, AreaI, int) with a zero offset.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
    • alignVerticallyMinYOffset

      @Deprecated public static AreaI alignVerticallyMinYOffset​(AreaI outer, AreaI inner, int offset)
      Align the area inner vertically against the inside minimum-y edge of outer. The area will be at least offset units from the minimum-y edge.
      Parameters:
      outer - The outer area
      inner - The inner area
      offset - The offset from the edge
      Returns:
      An aligned area
    • alignVerticallyMaxY

      @Deprecated public static AreaI alignVerticallyMaxY​(AreaI outer, AreaI inner)
      Equivalent to calling alignVerticallyMaxYOffset(AreaI, AreaI, int) with a zero offset.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
    • alignVerticallyMaxYOffset

      @Deprecated public static AreaI alignVerticallyMaxYOffset​(AreaI outer, AreaI inner, int offset)
      Align the area inner vertically against the inside maximum-y edge of outer. The area will be at least offset units from the maximum-y edge.
      Parameters:
      outer - The outer area
      inner - The inner area
      offset - The offset from the edge
      Returns:
      An aligned area
    • alignVerticallyCenter

      @Deprecated public static AreaI alignVerticallyCenter​(AreaI outer, AreaI inner)
      Align the area inner vertically in the center of outer.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
    • alignMinYMinX

      public static AreaI alignMinYMinX​(AreaI outer, AreaI inner)
      Equivalent to calling alignMinYMinXOffset(AreaI, AreaI, int, int) with zero offsets.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
    • alignMinYMinXOffset

      public static AreaI alignMinYMinXOffset​(AreaI outer, AreaI inner, int offset_x, int offset_y)
      Align the area inner such that the minimum-y edge is at least offset_y from the inside minimum-y edge of outer and the minimum-x edge is at least offset_x from the inside minimum-x edge of outer.
      Parameters:
      outer - The outer area
      inner - The inner area
      offset_x - The offset from the minimum-x edge
      offset_y - The offset from the minimum-y edge
      Returns:
      An aligned area
    • alignMinYMaxX

      public static AreaI alignMinYMaxX​(AreaI outer, AreaI inner)
      Equivalent to calling alignMinYMaxXOffset(AreaI, AreaI, int, int) with zero offsets.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
    • alignMinYMaxXOffset

      public static AreaI alignMinYMaxXOffset​(AreaI outer, AreaI inner, int offset_x, int offset_y)
      Align the area inner such that the minimum-y edge is at least offset_y from the inside minimum-y edge of outer and the maximum-x edge is at least offset_x from the inside maximum-x edge of outer.
      Parameters:
      outer - The outer area
      inner - The inner area
      offset_x - The offset from the maximum-x edge
      offset_y - The offset from the minimum-y edge
      Returns:
      An aligned area
    • alignMaxYMinX

      public static AreaI alignMaxYMinX​(AreaI outer, AreaI inner)
      Equivalent to calling alignMaxYMinXOffset(AreaI, AreaI, int, int) with zero offsets.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
    • alignMaxYMinXOffset

      public static AreaI alignMaxYMinXOffset​(AreaI outer, AreaI inner, int offset_x, int offset_y)
      Align the area inner such that the maximum-y edge is at least offset_y from the inside maximum-y edge of outer and the minimum-x edge is at least offset_x from the inside minimum-x edge of outer.
      Parameters:
      outer - The outer area
      inner - The inner area
      offset_x - The offset from the minimum-x edge
      offset_y - The offset from the maximum-y edge
      Returns:
      An aligned area
    • alignMaxYMaxX

      public static AreaI alignMaxYMaxX​(AreaI outer, AreaI inner)
      Equivalent to calling alignMaxYMaxXOffset(AreaI, AreaI, int, int) with zero offsets.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
    • alignMaxYMaxXOffset

      public static AreaI alignMaxYMaxXOffset​(AreaI outer, AreaI inner, int offset_x, int offset_y)
      Align the area inner such that the maximum-y edge is at least offset_y from the inside maximum-y edge of outer and the maximum-x edge is at least offset_x from the inside maximum-x edge of outer.
      Parameters:
      outer - The outer area
      inner - The inner area
      offset_x - The offset from the maximum-x edge
      offset_y - The offset from the maximum-y edge
      Returns:
      An aligned area
    • alignCenter

      public static AreaI alignCenter​(AreaI outer, AreaI inner)
      Align the area inner such that the center of the area is equal to the center of outer.
      Parameters:
      outer - The outer area
      inner - The inner area
      Returns:
      An aligned area
    • hollowOut

      public static AreaI hollowOut​(AreaI outer, int min_x_offset, int max_x_offset, int min_y_offset, int max_y_offset)
      Construct a new area that fits inside outer based on the given offsets from each edge.
      Parameters:
      outer - The containing area
      min_x_offset - The offset from the minimum-x edge (must be non-negative)
      max_x_offset - The offset from the maximum-x edge (must be non-negative)
      min_y_offset - The offset from the minimum-y edge (must be non-negative)
      max_y_offset - The offset from the maximum-y edge (must be non-negative)
      Returns:
      A new area
    • hollowOutEvenly

      public static AreaI hollowOutEvenly​(AreaI outer, int offset)
      Equivalent to calling hollowOut(AreaI, int, int, int, int) with offset for all offset parameters.
      Parameters:
      outer - The containing area
      offset - The offset from each edge (must be non-negative)
      Returns:
      A new area
    • setSizeFromCenter

      public static AreaI setSizeFromCenter​(AreaI area, int sizeX, int sizeY)

      Set the sizeX and sizeY of area to sizeX and sizeY, respectively.

      The area is resized from its own center.

      Parameters:
      area - The area
      sizeX - The new sizeX (must be non-negative)
      sizeY - The new sizeY (must be non-negative)
      Returns:
      A resized area
    • setSizeFromMinYMinX

      public static AreaI setSizeFromMinYMinX​(AreaI area, int sizeX, int sizeY)

      Set the sizeX and sizeY of area to sizeX and sizeY, respectively.

      The area is resized by moving its minimum-y-minimum-x corner.

      Parameters:
      area - The area
      sizeX - The new sizeX (must be non-negative)
      sizeY - The new sizeY (must be non-negative)
      Returns:
      A resized area
    • setSizeFromMinYMaxX

      public static AreaI setSizeFromMinYMaxX​(AreaI area, int sizeX, int sizeY)

      Set the sizeX and sizeY of area to sizeX and sizeY, respectively.

      The area is resized by moving its minimum-y-maximum-x corner.

      Parameters:
      area - The area
      sizeX - The new sizeX (must be non-negative)
      sizeY - The new sizeY (must be non-negative)
      Returns:
      A resized area
    • setSizeFromMaxYMaxX

      public static AreaI setSizeFromMaxYMaxX​(AreaI area, int sizeX, int sizeY)

      Set the sizeX and sizeY of area to sizeX and sizeY, respectively.

      The area is resized by moving its maximum-y-maximum-x corner.

      Parameters:
      area - The area
      sizeX - The new sizeX (must be non-negative)
      sizeY - The new sizeY (must be non-negative)
      Returns:
      A resized area
    • setSizeFromMaxYMinX

      public static AreaI setSizeFromMaxYMinX​(AreaI area, int sizeX, int sizeY)

      Set the sizeX and sizeY of area to sizeX and sizeY, respectively.

      The area is resized by moving its maximum-y-minimum-x corner.

      Parameters:
      area - The area
      sizeX - The new sizeX (must be non-negative)
      sizeY - The new sizeY (must be non-negative)
      Returns:
      A resized area
    • scaleFromMinYMinX

      public static AreaI scaleFromMinYMinX​(AreaI area, int x_diff, int y_diff)

      Scale area by adding x_diff to the sizeX, and y_diff to the sizeY. The size of the resulting area is clamped so that its sizeX and sizeY are always non-negative.

      The area is resized by moving its minimum-y-minimum-x corner.

      Parameters:
      area - The area
      x_diff - The X difference
      y_diff - The Y difference
      Returns:
      A resized area
    • scaleFromMinYMaxX

      public static AreaI scaleFromMinYMaxX​(AreaI area, int x_diff, int y_diff)

      Scale area by adding x_diff to the sizeX, and y_diff to the sizeY. The size of the resulting area is clamped so that its sizeX and sizeY are always non-negative.

      The area is resized by moving its minimum-y-maximum-x corner.

      Parameters:
      area - The area
      x_diff - The X difference
      y_diff - The Y difference
      Returns:
      A resized area
    • scaleFromMaxYMinX

      public static AreaI scaleFromMaxYMinX​(AreaI area, int x_diff, int y_diff)

      Scale area by adding x_diff to the sizeX, and y_diff to the sizeY. The size of the resulting area is clamped so that its sizeX and sizeY are always non-negative.

      The area is resized by moving its maximum-y-minimum-x corner.

      Parameters:
      area - The area
      x_diff - The X difference
      y_diff - The Y difference
      Returns:
      A resized area
    • scaleFromMaxYMaxX

      public static AreaI scaleFromMaxYMaxX​(AreaI area, int x_diff, int y_diff)

      Scale area by adding x_diff to the sizeX, and y_diff to the sizeY. The size of the resulting area is clamped so that its sizeX and sizeY are always non-negative.

      The area is resized by moving its maximum-y-maximum-x corner.

      Parameters:
      area - The area
      x_diff - The X difference
      y_diff - The Y difference
      Returns:
      A resized area
    • scaleFromCenter

      public static AreaI scaleFromCenter​(AreaI area, int x_diff, int y_diff)

      Scale area by adding x_diff to the sizeX, and y_diff to the sizeY. The size of the resulting area is clamped so that its sizeX and sizeY are always non-negative.

      The area is resized from its own center.

      Parameters:
      area - The area
      x_diff - The X difference
      y_diff - The Y difference
      Returns:
      A resized area
    • overlaps

      public static boolean overlaps​(AreaI a, AreaI b)

      Determine whether or not two areas overlap.

      Overlapping is reflexive: overlaps(a, a) == true.

      Overlapping is symmetric: overlaps(a, b) == overlaps(b, a).

      Overlapping is not necessarily transitive.

      Parameters:
      a - An area
      b - An area
      Returns:
      true iff a overlaps b
    • couldFitInside

      public static boolean couldFitInside​(AreaI a, AreaI b)

      Determine whether or not one area could fit inside another.

      Fitting is reflexive: couldFitInside(a, a) == true.

      Fitting is transitive: couldFitInside(a, b) → couldFitInside(b, c) → couldFitInside(a, c).

      Fitting is not necessarily symmetric.

      Parameters:
      a - An area
      b - An area
      Returns:
      true iff a could fit inside b
    • containing

      public static AreaI containing​(AreaI a, AreaI b)
      Construct a area that will contain both a and b.
      Parameters:
      a - An area
      b - An area
      Returns:
      An area containing a and b
    • containsPoint

      public static boolean containsPoint​(AreaI a, int x, int y)

      Determine whether or not a area contains a given point.

      Parameters:
      a - An area
      x - The X coordinate of the point
      y - The Y coordinate of the point
      Returns:
      true iff a contains (x, y)
    • fitBetweenHorizontal

      @Deprecated public static AreaI fitBetweenHorizontal​(AreaI fit, AreaI a, AreaI b)
      Attempt to fit fit between a and b, horizontally.
      Parameters:
      fit - The area to be fitted
      a - An area
      b - An area
      Returns:
      A fitted area
    • fitBetweenVertical

      @Deprecated public static AreaI fitBetweenVertical​(AreaI fit, AreaI a, AreaI b)
      Attempt to fit fit between a and b, vertically.
      Parameters:
      fit - The area to be fitted
      a - An area
      b - An area
      Returns:
      A fitted area
    • fitBetweenOnX

      public static AreaI fitBetweenOnX​(AreaI fit, AreaI a, AreaI b)
      Attempt to fit fit between a and b, horizontally.
      Parameters:
      fit - The area to be fitted
      a - An area
      b - An area
      Returns:
      A fitted area
    • fitBetweenOnY

      public static AreaI fitBetweenOnY​(AreaI fit, AreaI a, AreaI b)
      Attempt to fit fit between a and b, vertically.
      Parameters:
      fit - The area to be fitted
      a - An area
      b - An area
      Returns:
      A fitted area
    • splitAlongParallelToX

      public static AreaXSplitI<AreaI> splitAlongParallelToX​(AreaI area, int y)
      Split area along a line parallel to the X axis placed at y units from its own minimum-y edge.
      Parameters:
      area - The area to be split
      y - The relative Y coordinate of the splitting edge
      Returns:
      A pair of areas
    • splitAlongParallelToY

      public static AreaYSplitI<AreaI> splitAlongParallelToY​(AreaI area, int x)
      Split area along a line parallel to the Y axis placed at x units from its own minimum-x edge.
      Parameters:
      area - The area to be split
      x - The relative X coordinate of the splitting edge
      Returns:
      A pair of areas
    • splitAlongXY

      public static AreaXYSplitI<AreaI> splitAlongXY​(AreaI area, int x, int y)
      Split area along a two axis-aligned perpendicular lines that intercept at (x, y).
      Parameters:
      area - The area to be split
      x - The relative X coordinate of the splitting edge
      y - The relative Y coordinate of the splitting edge
      Returns:
      The four resulting quadrants
      Since:
      1.1.0
    • show

      public static java.lang.String show​(AreaI area)
      Parameters:
      area - The area
      Returns:
      A terse string describing the position and size of the area
    • size

      public static AreaSizeI size​(AreaI area)
      Parameters:
      area - The area
      Returns:
      The size of the area
    • showToBuilder

      public static java.lang.String showToBuilder​(AreaI area, java.lang.StringBuilder sb)
      Parameters:
      area - The area
      sb - A string builder
      Returns:
      A terse string describing the position and size of the area