Package net.dermetfan.utils.math
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 SummaryConstructors Constructor Description GeometryUtils()
- 
Method SummaryModifier 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 booleanareVerticesClockwise(float[] vertices)static booleanareVerticesClockwise(float[] vertices, int offset, int length)static voidarrangeConvexPolygon(float[] vertices, boolean clockwise)static voidarrangeConvexPolygon(float[] vertices, int offset, int length, boolean clockwise)static booleanbetween(float x, float y, float aX, float aY, float bX, float bY)static booleanbetween(float x, float y, float aX, float aY, float bX, float bY, boolean inclusive)static intclosePoints(float x, float y, float maxDistance2, float[] vertices, int offset, int length, float[] output, int outputOffset)static intclosePoints(float x, float y, float deltaX, float deltaY, float[] vertices, int offset, int length, float[] output, int outputOffset)static floatdepth(float[] vertices)static floatdepth(float[] vertices, int offset, int length)static floatdistance(float x1, float y1, float x2, float y2)static floatdistance2(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 floatheight(float[] vertices)static floatheight(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 floatinvertAxis(float coord, float axisSize)static booleanisConvex(float[] vertices)static booleanisConvex(float[] vertices, int offset, int length)static floatmaxX(float[] vertices)static floatmaxX(float[] vertices, int offset, int length)static floatmaxY(float[] vertices)static floatmaxY(float[] vertices, int offset, int length)static floatminX(float[] vertices)static floatminX(float[] vertices, int offset, int length)static floatminY(float[] vertices)static floatminY(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 floatpolygonArea(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 voidsetFloats(float[] floats)static voidsortPoints(float[] vertices, boolean byY)static voidsortPoints(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 theirheightstatic 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 theirheightstatic floatwidth(float[] vertices)static floatwidth(float[] vertices, int offset, int length)Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
- 
Constructor Details- 
GeometryUtilspublic GeometryUtils()
 
- 
- 
Method Details- 
setFloatspublic static void setFloats(float[] floats)- Parameters:
- floats- the- floatsto set
 
- 
getFloatspublic static float[] getFloats()- Returns:
- the floats
 
- 
betweenpublic 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
 
- 
betweenpublic 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)
 
- 
addpublic 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
 
- 
addpublic static float[] add(float[] vertices, float x, float y)- See Also:
- add(float[], int, int, float, float)
 
- 
subpublic static float[] sub(float[] items, int offset, int length, float x, float y)- See Also:
- add(float[], int, int, float, float)
 
- 
subpublic static float[] sub(float[] items, float x, float y)- See Also:
- sub(float[], int, int, float, float)
 
- 
addXpublic static float[] addX(float[] items, int offset, int length, float value)- See Also:
- add(float[], int, int, float, float)
 
- 
addXpublic static float[] addX(float[] items, float value)- See Also:
- addX(float[], int, int, float)
 
- 
addYpublic static float[] addY(float[] items, int offset, int length, float value)- See Also:
- add(float[], int, int, float, float)
 
- 
addYpublic static float[] addY(float[] items, float value)- See Also:
- addY(float[], int, int, float)
 
- 
subXpublic static float[] subX(float[] items, int offset, int length, float value)- See Also:
- sub(float[], int, int, float, float)
 
- 
subXpublic static float[] subX(float[] items, float value)- See Also:
- subX(float[], int, int, float)
 
- 
subYpublic static float[] subY(float[] items, int offset, int length, float value)- See Also:
- sub(float[], int, int, float, float)
 
- 
subYpublic static float[] subY(float[] items, float value)- See Also:
- subY(float[], int, int, float)
 
- 
mulpublic 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
 
- 
mulpublic static float[] mul(float[] items, float factorX, float factorY)- See Also:
- mul(float[], int, int, float, float)
 
- 
mulXpublic static float[] mulX(float[] items, int offset, int length, float factor)- See Also:
- mul(float[], int, int, float, float)
 
- 
mulXpublic static float[] mulX(float[] items, float factor)- See Also:
- mulX(float[], int, int, float)
 
- 
mulYpublic static float[] mulY(float[] items, int offset, int length, float factor)- See Also:
- mul(float[], int, int, float, float)
 
- 
mulYpublic static float[] mulY(float[] items, float factor)- See Also:
- mulY(float[], int, int, float)
 
- 
divpublic 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
 
- 
divpublic static float[] div(float[] items, float divisorX, float divisorY)- See Also:
- div(float[], int, int, float, float)
 
- 
divXpublic static float[] divX(float[] items, int offset, int length, float divisor)- See Also:
- div(float[], int, int, float, float)
 
- 
divXpublic static float[] divX(float[] items, float divisor)- See Also:
- divX(float[], int, int, float)
 
- 
divYpublic static float[] divY(float[] items, int offset, int length, float divisor)- See Also:
- div(float[], int, int, float, float)
 
- 
divYpublic static float[] divY(float[] items, float divisor)- See Also:
- divY(float[], int, int, float)
 
- 
widthpublic static float width(float[] vertices, int offset, int length)- Parameters:
- vertices- the vertices which width to get
- Returns:
- the width of the given vertices
 
- 
widthpublic static float width(float[] vertices)- See Also:
- width(float[], int, int)
 
- 
heightpublic static float height(float[] vertices, int offset, int length)- Parameters:
- vertices- the vertices which height to get
- Returns:
- the height of the given vertices
 
- 
heightpublic static float height(float[] vertices)- See Also:
- height(float[], int, int)
 
- 
depthpublic static float depth(float[] vertices, int offset, int length)- Parameters:
- vertices- the vertices which depth to get
- Returns:
- the depth of the given vertices
 
- 
depthpublic static float depth(float[] vertices)- See Also:
- depth(float[], int, int)
 
- 
filterXpublic 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
 
- 
filterXpublic static float[] filterX(float[] vertices, int offset, int length, float[] dest)- See Also:
- filterX(float[], int, int, float[], int)
 
- 
filterXpublic static float[] filterX(float[] vertices, float[] dest)- See Also:
- filterX(float[], int, int, float[])
 
- 
filterXpublic static float[] filterX(float[] vertices, int offset, int length)- See Also:
- filterX(float[], int, int, float[])
 
- 
filterXpublic static float[] filterX(float[] vertices)- See Also:
- filterX(float[], float[])
 
- 
filterYpublic 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
 
- 
filterYpublic static float[] filterY(float[] vertices, int offset, int length, float[] dest)- See Also:
- filterY(float[], int, int, float[], int)
 
- 
filterYpublic static float[] filterY(float[] vertices, float[] dest)- See Also:
- filterY(float[], int, int, float[])
 
- 
filterYpublic static float[] filterY(float[] vertices, int offset, int length)- See Also:
- filterY(float[], int, int, float[])
 
- 
filterYpublic static float[] filterY(float[] vertices)- See Also:
- filterY(float[], float[])
 
- 
filterZpublic 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
 
- 
filterZpublic static float[] filterZ(float[] vertices, int offset, int length, float[] dest)- See Also:
- filterZ(float[], int, int, float[], int)
 
- 
filterZpublic static float[] filterZ(float[] vertices, float[] dest)- See Also:
- filterZ(float[], int, int, float[])
 
- 
filterZpublic static float[] filterZ(float[] vertices, int offset, int length)- See Also:
- filterZ(float[], int, int, float[])
 
- 
filterZpublic static float[] filterZ(float[] vertices)- See Also:
- filterZ(float[], float[])
 
- 
filterWpublic 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
 
- 
filterWpublic static float[] filterW(float[] vertices, int offset, int length, float[] dest)- See Also:
- filterW(float[], int, int, float[], int)
 
- 
filterWpublic static float[] filterW(float[] vertices, float[] dest)- See Also:
- filterW(float[], int, int, float[])
 
- 
filterWpublic static float[] filterW(float[] vertices, int offset, int length)- See Also:
- filterW(float[], int, int, float[])
 
- 
filterWpublic static float[] filterW(float[] vertices)- See Also:
- filterW(float[], float[])
 
- 
minXpublic static float minX(float[] vertices, int offset, int length)- Returns:
- the min x value in the given vertices
 
- 
minXpublic static float minX(float[] vertices)- See Also:
- minX(float[], int, int)
 
- 
minYpublic static float minY(float[] vertices, int offset, int length)- Returns:
- the min y value in the given vertices
 
- 
minYpublic static float minY(float[] vertices)- See Also:
- minY(float[], int, int)
 
- 
maxXpublic static float maxX(float[] vertices, int offset, int length)- Returns:
- the max x value in the given vertices
 
- 
maxXpublic static float maxX(float[] vertices)- See Also:
- maxX(float[], int, int)
 
- 
maxYpublic static float maxY(float[] vertices, int offset, int length)- Returns:
- the max y value in the given vertices
 
- 
maxYpublic static float maxY(float[] vertices)- See Also:
- maxY(float[], int, int)
 
- 
distancepublic static float distance(float x1, float y1, float x2, float y2)- Returns:
- the distance between the two given points
- Since:
- 0.11.0
 
- 
distance2public static float distance2(float x1, float y1, float x2, float y2)- Returns:
- the squared distance between the two given points
- Since:
- 0.11.0
 
- 
scalepublic 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
 
- 
scalepublic static float[] scale(float[] vertices, float minX, float minY, float maxX, float maxY)
- 
reversepublic static float[] reverse(float[] vertices, int offset, int length)- Parameters:
- vertices- the vertices to reverse
- Returns:
- the reversed given vertices for chaining
 
- 
reversepublic static float[] reverse(float[] vertices)- See Also:
- reverse(float[], int, int)
 
- 
reverse3Dpublic static float[] reverse3D(float[] vertices, int offset, int length)- Parameters:
- vertices- the 3D vertices to reverse
- Returns:
- the reversed given vertices for chaining
 
- 
reverse3Dpublic static float[] reverse3D(float[] vertices)- See Also:
- reverse3D(float[], int, int)
 
- 
closePointspublic 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
 
- 
closePointspublic 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
 
- 
sortPointspublic static void sortPoints(float[] vertices, boolean byY)- Since:
- 0.11.0
- See Also:
- sortPoints(float[], int, int, boolean)
 
- 
sortPointspublic 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
 
- 
arrangeConvexPolygonpublic static void arrangeConvexPolygon(float[] vertices, boolean clockwise)
- 
arrangeConvexPolygonpublic 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
 
- 
polygonAreapublic static float polygonArea(float[] vertices, int offset, int length)- Returns:
- the area contained by the given simple/non self intersecting polygon
 
- 
areVerticesClockwisepublic static boolean areVerticesClockwise(float[] vertices, int offset, int length)- Returns:
- whether the given vertices are in clockwise order
 
- 
areVerticesClockwisepublic static boolean areVerticesClockwise(float[] vertices)- See Also:
- areVerticesClockwise(float[], int, int)
 
- 
isConvexpublic static boolean isConvex(float[] vertices)- See Also:
- isConvex(float[], int, int)
 
- 
isConvexpublic static boolean isConvex(float[] vertices, int offset, int length)- Parameters:
- vertices- the polygon
- Returns:
- whether the given vertices form a convex polygon
 
- 
rotatepublic 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
 
- 
invertAxispublic 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
 
- 
invertAxespublic 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
 
- 
invertAxespublic static float[] invertAxes(float[] vertices, boolean x, boolean y)
- 
toYDownpublic 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 theirheight- See Also:
- invertAxes(float[], boolean, boolean)
 
- 
toYDownpublic static float[] toYDown(float[] vertices)- See Also:
- toYDown(float[], int, int)
 
- 
toYUppublic 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 theirheight- See Also:
- invertAxes(float[], boolean, boolean)
 
- 
toYUppublic static float[] toYUp(float[] vertices)- See Also:
- toYUp(float[], int, int)
 
 
-