Class GeometryUtils

java.lang.Object
net.dermetfan.utils.math.GeometryUtils
Direct Known Subclasses:
GeometryUtils

public class GeometryUtils
extends java.lang.Object
geometric calculation utility methods
Since:
0.5.0
  • Constructor Summary

    Constructors
    Constructor Description
    GeometryUtils()  
  • Method Summary

    Modifier and Type Method Description
    static float[] add​(float[] vertices, float x, float y)  
    static float[] add​(float[] items, int offset, int length, float x, float y)  
    static float[] addX​(float[] items, float value)  
    static float[] addX​(float[] items, int offset, int length, float value)  
    static float[] addY​(float[] items, float value)  
    static float[] addY​(float[] items, int offset, int length, float value)  
    static boolean areVerticesClockwise​(float[] vertices)  
    static boolean areVerticesClockwise​(float[] vertices, int offset, int length)  
    static void arrangeConvexPolygon​(float[] vertices, boolean clockwise)  
    static void arrangeConvexPolygon​(float[] vertices, int offset, int length, boolean clockwise)  
    static boolean between​(float x, float y, float aX, float aY, float bX, float bY)  
    static boolean between​(float x, float y, float aX, float aY, float bX, float bY, boolean inclusive)  
    static int closePoints​(float x, float y, float maxDistance2, float[] vertices, int offset, int length, float[] output, int outputOffset)  
    static int closePoints​(float x, float y, float deltaX, float deltaY, float[] vertices, int offset, int length, float[] output, int outputOffset)  
    static float depth​(float[] vertices)  
    static float depth​(float[] vertices, int offset, int length)  
    static float distance​(float x1, float y1, float x2, float y2)  
    static float distance2​(float x1, float y1, float x2, float y2)  
    static float[] div​(float[] items, float divisorX, float divisorY)  
    static float[] div​(float[] items, int offset, int length, float divisorX, float divisorY)  
    static float[] divX​(float[] items, float divisor)  
    static float[] divX​(float[] items, int offset, int length, float divisor)  
    static float[] divY​(float[] items, float divisor)  
    static float[] divY​(float[] items, int offset, int length, float divisor)  
    static float[] filterW​(float[] vertices)  
    static float[] filterW​(float[] vertices, float[] dest)  
    static float[] filterW​(float[] vertices, int offset, int length)  
    static float[] filterW​(float[] vertices, int offset, int length, float[] dest)  
    static float[] filterW​(float[] vertices, int offset, int length, float[] dest, int destOffset)  
    static float[] filterX​(float[] vertices)  
    static float[] filterX​(float[] vertices, float[] dest)  
    static float[] filterX​(float[] vertices, int offset, int length)  
    static float[] filterX​(float[] vertices, int offset, int length, float[] dest)  
    static float[] filterX​(float[] vertices, int offset, int length, float[] dest, int destOffset)  
    static float[] filterY​(float[] vertices)  
    static float[] filterY​(float[] vertices, float[] dest)  
    static float[] filterY​(float[] vertices, int offset, int length)  
    static float[] filterY​(float[] vertices, int offset, int length, float[] dest)  
    static float[] filterY​(float[] vertices, int offset, int length, float[] dest, int destOffset)  
    static float[] filterZ​(float[] vertices)  
    static float[] filterZ​(float[] vertices, float[] dest)  
    static float[] filterZ​(float[] vertices, int offset, int length)  
    static float[] filterZ​(float[] vertices, int offset, int length, float[] dest)  
    static float[] filterZ​(float[] vertices, int offset, int length, float[] dest, int destOffset)  
    static float[] getFloats()  
    static float height​(float[] vertices)  
    static float height​(float[] vertices, int offset, int length)  
    static float[] invertAxes​(float[] vertices, boolean x, boolean y)  
    static float[] invertAxes​(float[] vertices, int offset, int length, boolean x, boolean y)
    Converts the given vertices to their position on inverted axes.
    static float invertAxis​(float coord, float axisSize)  
    static boolean isConvex​(float[] vertices)  
    static boolean isConvex​(float[] vertices, int offset, int length)  
    static float maxX​(float[] vertices)  
    static float maxX​(float[] vertices, int offset, int length)  
    static float maxY​(float[] vertices)  
    static float maxY​(float[] vertices, int offset, int length)  
    static float minX​(float[] vertices)  
    static float minX​(float[] vertices, int offset, int length)  
    static float minY​(float[] vertices)  
    static float minY​(float[] vertices, int offset, int length)  
    static float[] mul​(float[] items, float factorX, float factorY)  
    static float[] mul​(float[] items, int offset, int length, float factorX, float factorY)  
    static float[] mulX​(float[] items, float factor)  
    static float[] mulX​(float[] items, int offset, int length, float factor)  
    static float[] mulY​(float[] items, float factor)  
    static float[] mulY​(float[] items, int offset, int length, float factor)  
    static float polygonArea​(float[] vertices, int offset, int length)  
    static float[] reverse​(float[] vertices)  
    static float[] reverse​(float[] vertices, int offset, int length)  
    static float[] reverse3D​(float[] vertices)  
    static float[] reverse3D​(float[] vertices, int offset, int length)  
    static float[] rotate​(float x, float y, float width, float height, float radians, float[] output, int offset)  
    static float[] scale​(float[] vertices, float minX, float minY, float maxX, float maxY)  
    static float[] scale​(float[] vertices, int offset, int length, float minX, float minY, float maxX, float maxY)  
    static void setFloats​(float[] floats)  
    static void sortPoints​(float[] vertices, boolean byY)  
    static void sortPoints​(float[] vertices, int offset, int length, boolean byY)
    Sorts the given points in ascending order by their x (or, if byY is true, y) coordinate.
    static float[] sub​(float[] items, float x, float y)  
    static float[] sub​(float[] items, int offset, int length, float x, float y)  
    static float[] subX​(float[] items, float value)  
    static float[] subX​(float[] items, int offset, int length, float value)  
    static float[] subY​(float[] items, float value)  
    static float[] subY​(float[] items, int offset, int length, float value)  
    static float[] toYDown​(float[] vertices)  
    static float[] toYDown​(float[] vertices, int offset, int length)
    inverts the given vertices to a y-down coordinate system and translates them according to their parent coordinate system by their height
    static float[] toYUp​(float[] vertices)  
    static float[] toYUp​(float[] vertices, int offset, int length)
    inverts the given vertices to a y-up coordinate system and translates them according to their parent coordinate system by their height
    static float width​(float[] vertices)  
    static float width​(float[] vertices, int offset, int length)  

    Methods inherited from class java.lang.Object

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

    • GeometryUtils

      public GeometryUtils()
  • Method Details

    • setFloats

      public static void setFloats​(float[] floats)
      Parameters:
      floats - the floats to set
    • getFloats

      public static float[] getFloats()
      Returns:
      the floats
    • between

      public static boolean between​(float x, float y, float aX, float aY, float bX, float bY, boolean inclusive)
      Parameters:
      x - the x of the point to test
      y - the y of the point to test
      aX - the x of the first point of the segment
      aY - the y of the first point of the segment
      bX - the x of the second point of the segment
      bY - the y of the second point of the segment
      inclusive - if the given point is allowed to be equal to min or maxs
      Returns:
      if the given point lies on a line with and between the given points
    • between

      public static boolean between​(float x, float y, float aX, float aY, float bX, float bY)
      Returns:
      if the given point is between a and b (inclusive)
      See Also:
      between(float, float, float, float, float, float, boolean)
    • add

      public static float[] add​(float[] items, int offset, int length, float x, float y)
      Parameters:
      items - the items to add the given values to
      x - the x value to add
      y - the y value to add
      Returns:
      the given items for chaining
    • add

      public static float[] add​(float[] vertices, float x, float y)
      See Also:
      add(float[], int, int, float, float)
    • sub

      public static float[] sub​(float[] items, int offset, int length, float x, float y)
      See Also:
      add(float[], int, int, float, float)
    • sub

      public static float[] sub​(float[] items, float x, float y)
      See Also:
      sub(float[], int, int, float, float)
    • addX

      public static float[] addX​(float[] items, int offset, int length, float value)
      See Also:
      add(float[], int, int, float, float)
    • addX

      public static float[] addX​(float[] items, float value)
      See Also:
      addX(float[], int, int, float)
    • addY

      public static float[] addY​(float[] items, int offset, int length, float value)
      See Also:
      add(float[], int, int, float, float)
    • addY

      public static float[] addY​(float[] items, float value)
      See Also:
      addY(float[], int, int, float)
    • subX

      public static float[] subX​(float[] items, int offset, int length, float value)
      See Also:
      sub(float[], int, int, float, float)
    • subX

      public static float[] subX​(float[] items, float value)
      See Also:
      subX(float[], int, int, float)
    • subY

      public static float[] subY​(float[] items, int offset, int length, float value)
      See Also:
      sub(float[], int, int, float, float)
    • subY

      public static float[] subY​(float[] items, float value)
      See Also:
      subY(float[], int, int, float)
    • mul

      public static float[] mul​(float[] items, int offset, int length, float factorX, float factorY)
      Parameters:
      items - the items to multiply
      factorX - the factor for x coordinates
      factorY - the factor for y coordinates
      Returns:
      the given items for chaining
    • mul

      public static float[] mul​(float[] items, float factorX, float factorY)
      See Also:
      mul(float[], int, int, float, float)
    • mulX

      public static float[] mulX​(float[] items, int offset, int length, float factor)
      See Also:
      mul(float[], int, int, float, float)
    • mulX

      public static float[] mulX​(float[] items, float factor)
      See Also:
      mulX(float[], int, int, float)
    • mulY

      public static float[] mulY​(float[] items, int offset, int length, float factor)
      See Also:
      mul(float[], int, int, float, float)
    • mulY

      public static float[] mulY​(float[] items, float factor)
      See Also:
      mulY(float[], int, int, float)
    • div

      public static float[] div​(float[] items, int offset, int length, float divisorX, float divisorY)
      Parameters:
      items - the items to divide
      divisorX - the divisor for x coordinates
      divisorY - the divisor for y coordinates
      Returns:
      the given items for chaining
    • div

      public static float[] div​(float[] items, float divisorX, float divisorY)
      See Also:
      div(float[], int, int, float, float)
    • divX

      public static float[] divX​(float[] items, int offset, int length, float divisor)
      See Also:
      div(float[], int, int, float, float)
    • divX

      public static float[] divX​(float[] items, float divisor)
      See Also:
      divX(float[], int, int, float)
    • divY

      public static float[] divY​(float[] items, int offset, int length, float divisor)
      See Also:
      div(float[], int, int, float, float)
    • divY

      public static float[] divY​(float[] items, float divisor)
      See Also:
      divY(float[], int, int, float)
    • width

      public static float width​(float[] vertices, int offset, int length)
      Parameters:
      vertices - the vertices which width to get
      Returns:
      the width of the given vertices
    • width

      public static float width​(float[] vertices)
      See Also:
      width(float[], int, int)
    • height

      public static float height​(float[] vertices, int offset, int length)
      Parameters:
      vertices - the vertices which height to get
      Returns:
      the height of the given vertices
    • height

      public static float height​(float[] vertices)
      See Also:
      height(float[], int, int)
    • depth

      public static float depth​(float[] vertices, int offset, int length)
      Parameters:
      vertices - the vertices which depth to get
      Returns:
      the depth of the given vertices
    • depth

      public static float depth​(float[] vertices)
      See Also:
      depth(float[], int, int)
    • filterX

      public static float[] filterX​(float[] vertices, int offset, int length, float[] dest, int destOffset)
      Parameters:
      vertices - the vertices
      dest - the array to fill
      Returns:
      the x values of the given vertices
    • filterX

      public static float[] filterX​(float[] vertices, int offset, int length, float[] dest)
      See Also:
      filterX(float[], int, int, float[], int)
    • filterX

      public static float[] filterX​(float[] vertices, float[] dest)
      See Also:
      filterX(float[], int, int, float[])
    • filterX

      public static float[] filterX​(float[] vertices, int offset, int length)
      See Also:
      filterX(float[], int, int, float[])
    • filterX

      public static float[] filterX​(float[] vertices)
      See Also:
      filterX(float[], float[])
    • filterY

      public static float[] filterY​(float[] vertices, int offset, int length, float[] dest, int destOffset)
      Parameters:
      vertices - the vertices
      dest - the array to fill
      Returns:
      the y values of the given vertices
    • filterY

      public static float[] filterY​(float[] vertices, int offset, int length, float[] dest)
      See Also:
      filterY(float[], int, int, float[], int)
    • filterY

      public static float[] filterY​(float[] vertices, float[] dest)
      See Also:
      filterY(float[], int, int, float[])
    • filterY

      public static float[] filterY​(float[] vertices, int offset, int length)
      See Also:
      filterY(float[], int, int, float[])
    • filterY

      public static float[] filterY​(float[] vertices)
      See Also:
      filterY(float[], float[])
    • filterZ

      public static float[] filterZ​(float[] vertices, int offset, int length, float[] dest, int destOffset)
      Parameters:
      vertices - the vertices
      dest - the array to fill
      Returns:
      the z values of the given vertices
    • filterZ

      public static float[] filterZ​(float[] vertices, int offset, int length, float[] dest)
      See Also:
      filterZ(float[], int, int, float[], int)
    • filterZ

      public static float[] filterZ​(float[] vertices, float[] dest)
      See Also:
      filterZ(float[], int, int, float[])
    • filterZ

      public static float[] filterZ​(float[] vertices, int offset, int length)
      See Also:
      filterZ(float[], int, int, float[])
    • filterZ

      public static float[] filterZ​(float[] vertices)
      See Also:
      filterZ(float[], float[])
    • filterW

      public static float[] filterW​(float[] vertices, int offset, int length, float[] dest, int destOffset)
      Parameters:
      vertices - the vertices
      dest - the array to fill
      Returns:
      the w values of the given vertices
    • filterW

      public static float[] filterW​(float[] vertices, int offset, int length, float[] dest)
      See Also:
      filterW(float[], int, int, float[], int)
    • filterW

      public static float[] filterW​(float[] vertices, float[] dest)
      See Also:
      filterW(float[], int, int, float[])
    • filterW

      public static float[] filterW​(float[] vertices, int offset, int length)
      See Also:
      filterW(float[], int, int, float[])
    • filterW

      public static float[] filterW​(float[] vertices)
      See Also:
      filterW(float[], float[])
    • minX

      public static float minX​(float[] vertices, int offset, int length)
      Returns:
      the min x value in the given vertices
    • minX

      public static float minX​(float[] vertices)
      See Also:
      minX(float[], int, int)
    • minY

      public static float minY​(float[] vertices, int offset, int length)
      Returns:
      the min y value in the given vertices
    • minY

      public static float minY​(float[] vertices)
      See Also:
      minY(float[], int, int)
    • maxX

      public static float maxX​(float[] vertices, int offset, int length)
      Returns:
      the max x value in the given vertices
    • maxX

      public static float maxX​(float[] vertices)
      See Also:
      maxX(float[], int, int)
    • maxY

      public static float maxY​(float[] vertices, int offset, int length)
      Returns:
      the max y value in the given vertices
    • maxY

      public static float maxY​(float[] vertices)
      See Also:
      maxY(float[], int, int)
    • distance

      public static float distance​(float x1, float y1, float x2, float y2)
      Returns:
      the distance between the two given points
      Since:
      0.11.0
    • distance2

      public static float distance2​(float x1, float y1, float x2, float y2)
      Returns:
      the squared distance between the two given points
      Since:
      0.11.0
    • scale

      public static float[] scale​(float[] vertices, int offset, int length, float minX, float minY, float maxX, float maxY)
      Parameters:
      vertices - the vertices to scale
      minX - the desired minimal x coordinate
      minY - the desired minimal y coordinate
      maxX - the desired maximal x coordinate
      maxY - the desired maximal y coordinate
      Returns:
      the given and scaled vertices for chaining
    • scale

      public static float[] scale​(float[] vertices, float minX, float minY, float maxX, float maxY)
      See Also:
      scale(float[], int, int, float, float, float, float)
    • reverse

      public static float[] reverse​(float[] vertices, int offset, int length)
      Parameters:
      vertices - the vertices to reverse
      Returns:
      the reversed given vertices for chaining
    • reverse

      public static float[] reverse​(float[] vertices)
      See Also:
      reverse(float[], int, int)
    • reverse3D

      public static float[] reverse3D​(float[] vertices, int offset, int length)
      Parameters:
      vertices - the 3D vertices to reverse
      Returns:
      the reversed given vertices for chaining
    • reverse3D

      public static float[] reverse3D​(float[] vertices)
      See Also:
      reverse3D(float[], int, int)
    • closePoints

      public static int closePoints​(float x, float y, float maxDistance2, float[] vertices, int offset, int length, float[] output, int outputOffset)
      Parameters:
      x - the x coordinate of the point
      y - the y coordinate of the point
      maxDistance2 - the max squared distance between the given point and a close point
      vertices - the vertices to search for close points
      Returns:
      the number of points close to the given point
      Since:
      0.11.0
    • closePoints

      public static int closePoints​(float x, float y, float deltaX, float deltaY, float[] vertices, int offset, int length, float[] output, int outputOffset)
      Parameters:
      x - the x coordinate of the point
      y - the y coordinate of the point
      deltaX - the max difference between the point's and a close point's x coordinate
      deltaY - the max difference between the point's and a close point's y coordinate
      vertices - the vertices to search for close points
      output - The array to store the close points in. May be null.
      Returns:
      the number of points close to the given point
      Since:
      0.11.0
    • sortPoints

      public static void sortPoints​(float[] vertices, boolean byY)
      Since:
      0.11.0
      See Also:
      sortPoints(float[], int, int, boolean)
    • sortPoints

      public static void sortPoints​(float[] vertices, int offset, int length, boolean byY)
      Sorts the given points in ascending order by their x (or, if byY is true, y) coordinate.
      Parameters:
      vertices - the points to sort
      byY - whether the points shall by sorted by their y rather than their x coordinate
      Since:
      0.11.0
    • arrangeConvexPolygon

      public static void arrangeConvexPolygon​(float[] vertices, boolean clockwise)
      See Also:
      arrangeConvexPolygon(float[], int, int, boolean)
    • arrangeConvexPolygon

      public static void arrangeConvexPolygon​(float[] vertices, int offset, int length, boolean clockwise)
      Parameters:
      vertices - the vertices of the convex polygon
      clockwise - if true, the vertices will be arranged in clockwise, otherwise counter-clockwise order
    • polygonArea

      public static float polygonArea​(float[] vertices, int offset, int length)
      Returns:
      the area contained by the given simple/non self intersecting polygon
    • areVerticesClockwise

      public static boolean areVerticesClockwise​(float[] vertices, int offset, int length)
      Returns:
      whether the given vertices are in clockwise order
    • areVerticesClockwise

      public static boolean areVerticesClockwise​(float[] vertices)
      See Also:
      areVerticesClockwise(float[], int, int)
    • isConvex

      public static boolean isConvex​(float[] vertices)
      See Also:
      isConvex(float[], int, int)
    • isConvex

      public static boolean isConvex​(float[] vertices, int offset, int length)
      Parameters:
      vertices - the polygon
      Returns:
      whether the given vertices form a convex polygon
    • rotate

      public static float[] rotate​(float x, float y, float width, float height, float radians, float[] output, int offset)
      Parameters:
      x - the x of the rectangle
      y - the y of the rectangle
      width - the width of the rectangle
      height - the height of the rectangle
      radians - the desired rotation of the rectangle (in radians)
      output - The array to store the results in. A new one will be created if it is null or its length is less than 8.
      Returns:
      the given output array with the rotated vertices as in [x1, y1, x2, y2, x3, y3, x4, y4] starting from the given offset
    • invertAxis

      public static float invertAxis​(float coord, float axisSize)
      Parameters:
      coord - the position of the object
      axisSize - the size of the axis
      Returns:
      the position of the object on the axis, inverted from going to positive to negative
    • invertAxes

      public static float[] invertAxes​(float[] vertices, int offset, int length, boolean x, boolean y)
      Converts the given vertices to their position on inverted axes.
      Parameters:
      vertices - the vertices to convert
      x - if the x-axis should be inverted
      y - if the y-axis should be inverted
      Returns:
      the given vertices converted to the inverted axis in their local coordinate system
    • invertAxes

      public static float[] invertAxes​(float[] vertices, boolean x, boolean y)
      See Also:
      invertAxes(float[], int, int, boolean, boolean)
    • toYDown

      public static float[] toYDown​(float[] vertices, int offset, int length)
      inverts the given vertices to a y-down coordinate system and translates them according to their parent coordinate system by their height
      See Also:
      invertAxes(float[], boolean, boolean)
    • toYDown

      public static float[] toYDown​(float[] vertices)
      See Also:
      toYDown(float[], int, int)
    • toYUp

      public static float[] toYUp​(float[] vertices, int offset, int length)
      inverts the given vertices to a y-up coordinate system and translates them according to their parent coordinate system by their height
      See Also:
      invertAxes(float[], boolean, boolean)
    • toYUp

      public static float[] toYUp​(float[] vertices)
      See Also:
      toYUp(float[], int, int)