Class ShapeExtensions

java.lang.Object
com.technicjelle.BMUtils.ShapeExtensions

public class ShapeExtensions extends Object
Utility functions for Shapes
  • Method Summary

    Modifier and Type
    Method
    Description
    static Shape
    expandShapeAccurate(@NotNull Shape shape, double amount)
    Expands a Shape by a given amount, in all directions.
    More accurate for free-form shapes, like ellipses and circles, but less intuitive for rectangular shapes
    Use expandShapeRect(Shape, double) for more rectangular shapes.

    Example: expanding a square by 1 in each direction will only offset each edge by (√2)/2
    static Shape
    expandShapeRect(@NotNull Shape shape, double amount)
    Expands a Shape by a given amount, in all directions.
    This function is more intuitive for rectangular shapes, but technically not exactly mathematically accurate.
    Use expandShapeAccurate(Shape, double) for more free-form shapes, like ellipses and circles.

    Example: expanding a 16x16 square by 1 in each direction results in an 18x18 square
    static Shape
    scaleShapeAround(@NotNull Shape shape, double scale, Vector2d origin)
    Scales a shape by a given factor, around a given origin
    static @NotNull Shape
    scaleShapeMiddle(@NotNull Shape shape, double scale)
    Scales a shape by a given factor, around the middle of the shape
    static Shape
    scaleShapeOrigin(@NotNull Shape shape, double scale)
    Scales a shape by a given factor, around the origin (0, 0)
    static Shape
    shrinkShapeAccurate(@NotNull Shape shape, double amount)
    Shrinks a Shape by a given amount, in all directions.
    More accurate for free-form shapes, like ellipses and circles, but less intuitive for rectangular shapes
    Use shrinkShapeRect(Shape, double) for more rectangular shapes.

    Example: shrinking a square by 1 in each direction will only offset each edge by (√2)/2
    static Shape
    shrinkShapeRect(@NotNull Shape shape, double amount)
    Shrinks a Shape by a given amount, in all directions.
    This function is more intuitive for rectangular shapes, but technically not exactly mathematically accurate.
    Use shrinkShapeAccurate(Shape, double) for more free-form shapes, like ellipses and circles.

    Example: shrinking a 16x16 square by 1 in each direction results in a 14x14 square

    Methods inherited from class java.lang.Object

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

    • expandShapeRect

      public static Shape expandShapeRect(@NotNull @NotNull Shape shape, double amount)
      Expands a Shape by a given amount, in all directions.
      This function is more intuitive for rectangular shapes, but technically not exactly mathematically accurate.
      Use expandShapeAccurate(Shape, double) for more free-form shapes, like ellipses and circles.

      Example: expanding a 16x16 square by 1 in each direction results in an 18x18 square
      Parameters:
      shape - The shape to expand
      amount - The amount (in blocks) to expand the shape by. May be negative to shrink the shape.
      Returns:
      A new shape, expanded by the given amount
      See Also:
    • shrinkShapeRect

      public static Shape shrinkShapeRect(@NotNull @NotNull Shape shape, double amount)
      Shrinks a Shape by a given amount, in all directions.
      This function is more intuitive for rectangular shapes, but technically not exactly mathematically accurate.
      Use shrinkShapeAccurate(Shape, double) for more free-form shapes, like ellipses and circles.

      Example: shrinking a 16x16 square by 1 in each direction results in a 14x14 square
      Parameters:
      shape - The shape to shrink
      amount - The amount (in blocks) to expand the shape by. May be negative to expand the shape.
      Returns:
      A new shape, shrunk by the given amount
      See Also:
    • expandShapeAccurate

      public static Shape expandShapeAccurate(@NotNull @NotNull Shape shape, double amount)
      Expands a Shape by a given amount, in all directions.
      More accurate for free-form shapes, like ellipses and circles, but less intuitive for rectangular shapes
      Use expandShapeRect(Shape, double) for more rectangular shapes.

      Example: expanding a square by 1 in each direction will only offset each edge by (√2)/2
      Parameters:
      shape - The shape to expand
      amount - The amount to expand the shape by. May be negative to shrink the shape.
      Returns:
      A new shape, expanded by the given amount
      See Also:
    • shrinkShapeAccurate

      public static Shape shrinkShapeAccurate(@NotNull @NotNull Shape shape, double amount)
      Shrinks a Shape by a given amount, in all directions.
      More accurate for free-form shapes, like ellipses and circles, but less intuitive for rectangular shapes
      Use shrinkShapeRect(Shape, double) for more rectangular shapes.

      Example: shrinking a square by 1 in each direction will only offset each edge by (√2)/2
      Parameters:
      shape - The shape to shrink
      amount - The amount to expand the shape by. May be negative to shrink the shape.
      Returns:
      A new shape, shrunk by the given amount
      See Also:
    • scaleShapeOrigin

      public static Shape scaleShapeOrigin(@NotNull @NotNull Shape shape, double scale)
      Scales a shape by a given factor, around the origin (0, 0)
      Parameters:
      shape - The shape to scale
      scale - The factor to scale by
      Returns:
      A new scaled shape
    • scaleShapeMiddle

      @NotNull public static @NotNull Shape scaleShapeMiddle(@NotNull @NotNull Shape shape, double scale)
      Scales a shape by a given factor, around the middle of the shape
      Parameters:
      shape - The shape to scale
      scale - The factor to scale by
      Returns:
      A new scaled shape
    • scaleShapeAround

      public static Shape scaleShapeAround(@NotNull @NotNull Shape shape, double scale, Vector2d origin)
      Scales a shape by a given factor, around a given origin
      Parameters:
      shape - The shape to scale
      scale - The factor to scale by
      origin - The origin to scale around
      Returns:
      A new scaled shape