Table of Contents

Class Math

Namespace
Flexalon
Assembly
Flexalon.dll

Common math help functions.

public static class Math
Inheritance
object
Math

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

v Vector3

The 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

size float

The size to align to.

align Align

The 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

childSize float

The size of the child.

parentSize float

The size of the parent.

parentAlign Align

The alignment of the parent.

childAlign Align

The 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

childSize float

The size of the child.

parentSize float

The size of the parent.

align Align

The 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

size Vector3

The size to align to.

horizontal Align

The horizontal alignment.

vertical Align

The vertical alignment.

depth Align

The 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

size Vector3

The size to align to.

axis int

The axis to align to.

align Align

The 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

childSize Vector3

The size of the child.

parentSize Vector3

The size of the parent.

parentHorizontal Align

The horizontal alignment of the parent.

parentVertical Align

The vertical alignment of the parent.

parentDepth Align

The depth alignment of the parent.

childHorizontal Align

The horizontal pivot of the child.

childVertical Align

The vertical pivot of the child.

childDepth Align

The 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

childSize Vector3

The size of the child.

parentSize Vector3

The size of the parent.

horizontal Align

The horizontal alignment of the parent and child.

vertical Align

The vertical alignment of the parent and child.

depth Align

The 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

childSize Vector3

The size of the child.

parentSize Vector3

The size of the parent.

axis Axis

The axis to align on.

parentAlign Align

The alignment of the parent.

childAlign Align

The 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

childSize Vector3

The size of the child.

parentSize Vector3

The size of the parent.

axis Axis

The axis to align on.

align Align

The 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

childSize Vector3

The size of the child.

parentSize Vector3

The size of the parent.

axis int

The axis to align on.

parentAlign Align

The alignment of the parent.

childAlign Align

The 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

childSize Vector3

The size of the child.

parentSize Vector3

The size of the parent.

axis int

The axis to align on.

align Align

The 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

v Vector3

The vector to clamp.

min Vector3

The minimum value.

max Vector3

The 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

center Vector3

The center of the bounds.

size Vector3

The size of the bound before rotation.

rotation Quaternion

The 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

a Vector3

The divided vector.

b Vector3

The divisor vector.

Returns

Vector3

The divided vector.

GetAxisFromDirection(Direction)

Returns the axis of a direction.

public static Axis GetAxisFromDirection(Direction direction)

Parameters

direction Direction

The 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

direction int

The 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

axis Axis

The axis to get the directions of.

Returns

(Direction, Direction)

The positive and negative directions of the axis.

GetDirectionsFromAxis(int)

Returns the positive and negative directions of an axis.

public static (Direction, Direction) GetDirectionsFromAxis(int axis)

Parameters

axis int

The axis to get the directions of.

Returns

(Direction, Direction)

The positive and negative directions of the axis.

GetOppositeDirection(Direction)

Returns the opposite direction.

public static Direction GetOppositeDirection(Direction direction)

Parameters

direction Direction

The direction to get the opposite of.

Returns

Direction

The opposite direction.

GetOppositeDirection(int)

Returns the opposite direction.

public static Direction GetOppositeDirection(int direction)

Parameters

direction int

The 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

axis Axis

The axis to get the other two axes of.

Returns

(Axis, Axis)

The other two axes.

GetOtherAxes(int)

Returns the other two axes.

public static (int, int) GetOtherAxes(int axis)

Parameters

axis int

The 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

plane Plane

The plane to get the axes of.

Returns

(Axis, Axis)

The axes of the plane.

GetPlaneAxesInt(Plane)

Returns the axes of a plane.

public static (int, int) GetPlaneAxesInt(Plane plane)

Parameters

plane Plane

The 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

direction Direction

Returns

float

The positive direction of the axis.

GetPositiveFromDirection(int)

Returns the positive direction of an axis.

public static float GetPositiveFromDirection(int direction)

Parameters

direction int

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

axis1 Axis

The first axis.

axis2 Axis

The second axis.

Returns

Axis

The third axis.

GetThirdAxis(int, int)

Given two axes, returns the third axis.

public static int GetThirdAxis(int axis1, int axis2)

Parameters

axis1 int

The first axis.

axis2 int

The 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

axis Axis

The 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

axis int

The 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

direction Direction

The 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

direction int

The 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

componentBounds Bounds

The bounds of the component.

node FlexalonNode

The node to measure the bounds for.

size Vector3

The size of the node.

min Vector3

The minimum size of the node.

max Vector3

The 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

componentBounds Bounds

The bounds of the component.

node FlexalonNode

The node to measure the bounds for.

size Vector3

The size of the node.

min Vector3

The minimum size of the node.

max Vector3

The 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

a Vector3

The first vector.

b Vector3

The 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

bounds Bounds

The bounds to rotate.

rotation Quaternion

The 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

a Vector3

The divided vector.

b Vector3

The 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

a Vector3

The divided vector.

b Vector3

The 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

bounds Bounds

The bounds to scale.

scale Vector3

The scale to scale the bounds by.

Returns

Bounds

The scaled bounds.