Class Math
- Namespace
- Flexalon
- Assembly
- Flexalon.dll
Common math help functions.
public static class Math
- Inheritance
-
objectMath
Fields
MaxValue
public static readonly float MaxValue
Field Value
- float
MaxVector
public static readonly Vector3 MaxVector
Field Value
- Vector3
Methods
Abs(Vector3)
Applies absolute value of to each vector component.
public static Vector3 Abs(Vector3 v)
Parameters
vVector3The vector to apply absolute value to.
Returns
- Vector3
The vector with absolute value applied.
Align(float, Align)
Determines the aligned position in a size.
public static float Align(float size, Align align)
Parameters
sizefloatThe size to align to.
alignAlignThe alignment.
Returns
- float
The aligned position.
Align(float, float, Align, Align)
Aligns a child size to a parent size.
public static float Align(float childSize, float parentSize, Align parentAlign, Align childAlign)
Parameters
childSizefloatThe size of the child.
parentSizefloatThe size of the parent.
parentAlignAlignThe alignment of the parent.
childAlignAlignThe pivot of the child.
Returns
- float
The aligned position of the child.
Align(float, float, Align)
Aligns a child size to a parent size.
public static float Align(float childSize, float parentSize, Align align)
Parameters
childSizefloatThe size of the child.
parentSizefloatThe size of the parent.
alignAlignThe alignment of the parent and child.
Returns
- float
The aligned position of the child.
Align(Vector3, Align, Align, Align)
Determines the aligned position in a size.
public static Vector3 Align(Vector3 size, Align horizontal, Align vertical, Align depth)
Parameters
sizeVector3The size to align to.
horizontalAlignThe horizontal alignment.
verticalAlignThe vertical alignment.
depthAlignThe depth alignment.
Returns
- Vector3
The aligned position.
Align(Vector3, int, Align)
Determines the aligned position in a size for an axis.
public static float Align(Vector3 size, int axis, Align align)
Parameters
sizeVector3The size to align to.
axisintThe axis to align to.
alignAlignThe alignment.
Returns
- float
The aligned position.
Align(Vector3, Vector3, Align, Align, Align, Align, Align, Align)
Aligns a child size to a parent size on all axes.
public static Vector3 Align(Vector3 childSize, Vector3 parentSize, Align parentHorizontal, Align parentVertical, Align parentDepth, Align childHorizontal, Align childVertical, Align childDepth)
Parameters
childSizeVector3The size of the child.
parentSizeVector3The size of the parent.
parentHorizontalAlignThe horizontal alignment of the parent.
parentVerticalAlignThe vertical alignment of the parent.
parentDepthAlignThe depth alignment of the parent.
childHorizontalAlignThe horizontal pivot of the child.
childVerticalAlignThe vertical pivot of the child.
childDepthAlignThe depth pivot of the child.
Returns
- Vector3
The aligned position of the child.
Align(Vector3, Vector3, Align, Align, Align)
Aligns a child size to a parent size on all axes.
public static Vector3 Align(Vector3 childSize, Vector3 parentSize, Align horizontal, Align vertical, Align depth)
Parameters
childSizeVector3The size of the child.
parentSizeVector3The size of the parent.
horizontalAlignThe horizontal alignment of the parent and child.
verticalAlignThe vertical alignment of the parent and child.
depthAlignThe depth alignment of the parent and child.
Returns
- Vector3
The aligned position of the child.
Align(Vector3, Vector3, Axis, Align, Align)
Aligns a child size to a parent size on an axis.
public static float Align(Vector3 childSize, Vector3 parentSize, Axis axis, Align parentAlign, Align childAlign)
Parameters
childSizeVector3The size of the child.
parentSizeVector3The size of the parent.
axisAxisThe axis to align on.
parentAlignAlignThe alignment of the parent.
childAlignAlignThe pivot of the child.
Returns
- float
The aligned position of the child.
Align(Vector3, Vector3, Axis, Align)
Aligns a child size to a parent size on an axis.
public static float Align(Vector3 childSize, Vector3 parentSize, Axis axis, Align align)
Parameters
childSizeVector3The size of the child.
parentSizeVector3The size of the parent.
axisAxisThe axis to align on.
alignAlignThe alignment of the parent and child.
Returns
- float
The aligned position of the child.
Align(Vector3, Vector3, int, Align, Align)
Aligns a child size to a parent size on an axis.
public static float Align(Vector3 childSize, Vector3 parentSize, int axis, Align parentAlign, Align childAlign)
Parameters
childSizeVector3The size of the child.
parentSizeVector3The size of the parent.
axisintThe axis to align on.
parentAlignAlignThe alignment of the parent.
childAlignAlignThe pivot of the child.
Returns
- float
The aligned position of the child.
Align(Vector3, Vector3, int, Align)
Aligns a child size to a parent size on an axis.
public static float Align(Vector3 childSize, Vector3 parentSize, int axis, Align align)
Parameters
childSizeVector3The size of the child.
parentSizeVector3The size of the parent.
axisintThe axis to align on.
alignAlignThe alignment of the parent and child.
Returns
- float
The aligned position of the child.
Clamp(Vector3, Vector3, Vector3)
Clamps value of to each vector component between min and max.
public static Vector3 Clamp(Vector3 v, Vector3 min, Vector3 max)
Parameters
vVector3The vector to clamp.
minVector3The minimum value.
maxVector3The maximum value.
Returns
- Vector3
The clamped vector.
CreateRotatedBounds(Vector3, Vector3, Quaternion)
Creates rotated and scaled bounds at center.
public static Bounds CreateRotatedBounds(Vector3 center, Vector3 size, Quaternion rotation)
Parameters
centerVector3The center of the bounds.
sizeVector3The size of the bound before rotation.
rotationQuaternionThe rotation to apply to the size.
Returns
- Bounds
Div(Vector3, Vector3)
Divides each component of two vectors.
public static Vector3 Div(Vector3 a, Vector3 b)
Parameters
aVector3The divided vector.
bVector3The divisor vector.
Returns
- Vector3
The divided vector.
GetAxisFromDirection(Direction)
Returns the axis of a direction.
public static Axis GetAxisFromDirection(Direction direction)
Parameters
directionDirectionThe direction to get the axis of.
Returns
- Axis
The axis of the direction.
GetAxisFromDirection(int)
Returns the axis of a direction.
public static Axis GetAxisFromDirection(int direction)
Parameters
directionintThe direction to get the axis of.
Returns
- Axis
The axis of the direction.
GetDirectionsFromAxis(Axis)
Returns the positive and negative directions of an axis.
public static (Direction, Direction) GetDirectionsFromAxis(Axis axis)
Parameters
axisAxisThe axis to get the directions of.
Returns
GetDirectionsFromAxis(int)
Returns the positive and negative directions of an axis.
public static (Direction, Direction) GetDirectionsFromAxis(int axis)
Parameters
axisintThe axis to get the directions of.
Returns
GetOppositeDirection(Direction)
Returns the opposite direction.
public static Direction GetOppositeDirection(Direction direction)
Parameters
directionDirectionThe direction to get the opposite of.
Returns
- Direction
The opposite direction.
GetOppositeDirection(int)
Returns the opposite direction.
public static Direction GetOppositeDirection(int direction)
Parameters
directionintThe direction to get the opposite of.
Returns
- Direction
The opposite direction.
GetOtherAxes(Axis)
Returns the other two axes.
public static (Axis, Axis) GetOtherAxes(Axis axis)
Parameters
axisAxisThe axis to get the other two axes of.
Returns
GetOtherAxes(int)
Returns the other two axes.
public static (int, int) GetOtherAxes(int axis)
Parameters
axisintThe axis to get the other two axes of.
Returns
- (int, int)
The other two axes.
GetPlaneAxes(Plane)
Returns the axes of a plane.
public static (Axis, Axis) GetPlaneAxes(Plane plane)
Parameters
planePlaneThe plane to get the axes of.
Returns
GetPlaneAxesInt(Plane)
Returns the axes of a plane.
public static (int, int) GetPlaneAxesInt(Plane plane)
Parameters
planePlaneThe plane to get the axes of.
Returns
- (int, int)
The axes of the plane.
GetPositiveFromDirection(Direction)
Returns the positive direction of an axis.
public static float GetPositiveFromDirection(Direction direction)
Parameters
directionDirection
Returns
- float
The positive direction of the axis.
GetPositiveFromDirection(int)
Returns the positive direction of an axis.
public static float GetPositiveFromDirection(int direction)
Parameters
directionint
Returns
- float
The positive direction of the axis.
GetThirdAxis(Axis, Axis)
Given two axes, returns the third axis.
public static Axis GetThirdAxis(Axis axis1, Axis axis2)
Parameters
Returns
- Axis
The third axis.
GetThirdAxis(int, int)
Given two axes, returns the third axis.
public static int GetThirdAxis(int axis1, int axis2)
Parameters
axis1intThe first axis.
axis2intThe second axis.
Returns
- int
The third axis.
GetVectorFromAxis(Axis)
Returns a unit vector in the positive direction of axis.
public static Vector3 GetVectorFromAxis(Axis axis)
Parameters
axisAxisThe axis to get the vector of.
Returns
- Vector3
A unit vector in the axis.
GetVectorFromAxis(int)
Returns a unit vector in the positive direction of axis.
public static Vector3 GetVectorFromAxis(int axis)
Parameters
axisintThe axis to get the vector of.
Returns
- Vector3
A unit vector in the axis.
GetVectorFromDirection(Direction)
Returns a unit vector in the direction.
public static Vector3 GetVectorFromDirection(Direction direction)
Parameters
directionDirectionThe direction to get the vector of.
Returns
- Vector3
A unit vector in the direction.
GetVectorFromDirection(int)
Returns a unit vector in the direction.
public static Vector3 GetVectorFromDirection(int direction)
Parameters
directionintThe direction to get the vector of.
Returns
- Vector3
A unit vector in the direction.
MeasureComponentBounds(Bounds, FlexalonNode, Vector3, Vector3, Vector3)
Given the bounds of a component, creates a bounds for the node respecting the size types. Aspect ratio is preserved when possible.
public static Bounds MeasureComponentBounds(Bounds componentBounds, FlexalonNode node, Vector3 size, Vector3 min, Vector3 max)
Parameters
componentBoundsBoundsThe bounds of the component.
nodeFlexalonNodeThe node to measure the bounds for.
sizeVector3The size of the node.
minVector3The minimum size of the node.
maxVector3The maximum size of the node.
Returns
- Bounds
The bounds of the node.
MeasureComponentBounds2D(Bounds, FlexalonNode, Vector3, Vector3, Vector3)
Given the bounds of a component, creates a bounds for the node respecting the size types. Aspect ratio is preserved for X and Y when possible.
public static Bounds MeasureComponentBounds2D(Bounds componentBounds, FlexalonNode node, Vector3 size, Vector3 min, Vector3 max)
Parameters
componentBoundsBoundsThe bounds of the component.
nodeFlexalonNodeThe node to measure the bounds for.
sizeVector3The size of the node.
minVector3The minimum size of the node.
maxVector3The maximum size of the node.
Returns
- Bounds
The bounds of the node.
Mul(Vector3, Vector3)
Multiplies each component of two vectors.
public static Vector3 Mul(Vector3 a, Vector3 b)
Parameters
aVector3The first vector.
bVector3The second vector.
Returns
- Vector3
The multiplied vector.
RotateBounds(Bounds, Quaternion)
Rotates a bounds around the origin and returns a new bounds that encapsulates all of the rotated corners.
public static Bounds RotateBounds(Bounds bounds, Quaternion rotation)
Parameters
boundsBoundsThe bounds to rotate.
rotationQuaternionThe rotation to rotate the bounds by.
Returns
- Bounds
The new bounds.
SafeDivOne(Vector3, Vector3)
Divides each component of two vectors. If b is zero, returns 1.
public static Vector3 SafeDivOne(Vector3 a, Vector3 b)
Parameters
aVector3The divided vector.
bVector3The divisor vector.
Returns
- Vector3
The divided vector.
SafeDivZero(Vector3, Vector3)
Divides each component of two vectors. If b is zero, returns 1.
public static Vector3 SafeDivZero(Vector3 a, Vector3 b)
Parameters
aVector3The divided vector.
bVector3The divisor vector.
Returns
- Vector3
The divided vector.
ScaleBounds(Bounds, Vector3)
Scales a bounds by multiplying the center and size by 'scale'.
public static Bounds ScaleBounds(Bounds bounds, Vector3 scale)
Parameters
boundsBoundsThe bounds to scale.
scaleVector3The scale to scale the bounds by.
Returns
- Bounds
The scaled bounds.