A* Pathfinding Project  4.1.12
The A* Pathfinding Project for Unity 3D
AstarMath Class Reference

Utility functions for working with numbers and strings. More...

Detailed Description

Utility functions for working with numbers and strings.

See also
Polygon
VectorMath

Static Public Member Functions

static float Abs (float a)
 
static int Abs (int a)
 
static float Clamp (float a, float b, float c)
 
static int Clamp (int a, int b, int c)
 
static float Clamp01 (float a)
 
static int Clamp01 (int a)
 
static int ComputeVertexHash (int x, int y, int z)
 
static Vector3 CubicBezier (Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
 Returns a point on a cubic bezier curve. More...
 
static float DistancePointSegment (int x, int z, int px, int pz, int qx, int qz)
 Returns the approximate shortest squared distance between x,z and the line p-q. More...
 
static float DistancePointSegment (Int3 a, Int3 b, Int3 p)
 Returns the approximate shortest squared distance between x,z and the line p-q. More...
 
static float DistancePointSegment2 (int x, int z, int px, int pz, int qx, int qz)
 
static float DistancePointSegment2 (Vector3 a, Vector3 b, Vector3 p)
 
static float DistancePointSegmentStrict (Vector3 a, Vector3 b, Vector3 p)
 Returns the squared distance between c and the line a-b. More...
 
static string FormatBytes (int bytes)
 
static string FormatBytesBinary (int bytes)
 Returns a nicely formatted string for the number of bytes (KiB, MiB, GiB etc). More...
 
static float Hermite (float start, float end, float value)
 
static Color HSVToRGB (float h, float s, float v)
 Converts an HSV color to an RGB color. More...
 
static Color IntToColor (int i, float a)
 Returns a nice color from int i with alpha a. More...
 
static float Lerp (float a, float b, float t)
 
static float MagnitudeXZ (Vector3 a, Vector3 b)
 
static float MapTo (float startMin, float startMax, float value)
 Maps a value between startMin and startMax to be between 0 and 1. More...
 
static float MapTo (float startMin, float startMax, float targetMin, float targetMax, float value)
 Maps a value between startMin and startMax to be between targetMin and targetMax. More...
 
static float MapToRange (float targetMin, float targetMax, float value)
 
static float Max (float a, float b)
 
static int Max (int a, int b)
 
static uint Max (uint a, uint b)
 
static ushort Max (ushort a, ushort b)
 
static float Min (float a, float b)
 
static int Min (int a, int b)
 
static uint Min (uint a, uint b)
 
static Vector3 NearestPoint (Vector3 lineStart, Vector3 lineEnd, Vector3 point)
 Returns the closest point on the line. More...
 
static float NearestPointFactor (Vector3 lineStart, Vector3 lineEnd, Vector3 point)
 
static float NearestPointFactor (Int3 lineStart, Int3 lineEnd, Int3 point)
 Factor of the nearest point on the segment. More...
 
static float NearestPointFactor (Int2 lineStart, Int2 lineEnd, Int2 point)
 Factor of the nearest point on the segment. More...
 
static Vector3 NearestPointStrict (Vector3 lineStart, Vector3 lineEnd, Vector3 point)
 Returns the closest point on the line segment. More...
 
static Vector3 NearestPointStrictXZ (Vector3 lineStart, Vector3 lineEnd, Vector3 point)
 Returns the closest point on the line segment on the XZ plane. More...
 
static int Repeat (int i, int n)
 
static int RoundToInt (float v)
 
static int RoundToInt (double v)
 
static float Sign (float a)
 
static int Sign (int a)
 
static float SqrMagnitudeXZ (Vector3 a, Vector3 b)
 Squared distance between two points on the XZ plane. More...
 

Static Private Member Functions

static int Bit (int a, int b)
 Returns bit number b from int a. More...
 

Member Function Documentation

◆ Abs() [1/2]

static float Abs ( float  a)
static
Deprecated:
Use Mathf.Abs instead

◆ Abs() [2/2]

static int Abs ( int  a)
static
Deprecated:
Use Mathf.Abs instead

◆ Bit()

static int Bit ( int  a,
int  b 
)
staticprivate

Returns bit number b from int a.

The bit number is zero based. Relevant b values are from 0 to 31. Equals to (a >> b) & 1

◆ Clamp() [1/2]

static float Clamp ( float  a,
float  b,
float  c 
)
static
Deprecated:
Use Mathf.Clamp instead

◆ Clamp() [2/2]

static int Clamp ( int  a,
int  b,
int  c 
)
static
Deprecated:
Use Mathf.Clamp instead

◆ Clamp01() [1/2]

static float Clamp01 ( float  a)
static
Deprecated:
Use Mathf.Clamp01 instead

◆ Clamp01() [2/2]

static int Clamp01 ( int  a)
static
Deprecated:
Use Mathf.Clamp01 instead

◆ ComputeVertexHash()

static int ComputeVertexHash ( int  x,
int  y,
int  z 
)
static

◆ CubicBezier()

static Vector3 CubicBezier ( Vector3  p0,
Vector3  p1,
Vector3  p2,
Vector3  p3,
float  t 
)
static

Returns a point on a cubic bezier curve.

t is clamped between 0 and 1

◆ DistancePointSegment() [1/2]

static float DistancePointSegment ( int  x,
int  z,
int  px,
int  pz,
int  qx,
int  qz 
)
static

Returns the approximate shortest squared distance between x,z and the line p-q.

The line is considered infinite. This function is not entirely exact, but it is about twice as fast as DistancePointSegment2.

◆ DistancePointSegment() [2/2]

static float DistancePointSegment ( Int3  a,
Int3  b,
Int3  p 
)
static

Returns the approximate shortest squared distance between x,z and the line p-q.

The line is considered infinite. This function is not entirely exact, but it is about twice as fast as DistancePointSegment2.

◆ DistancePointSegment2() [1/2]

static float DistancePointSegment2 ( int  x,
int  z,
int  px,
int  pz,
int  qx,
int  qz 
)
static
Deprecated:
Obsolete

◆ DistancePointSegment2() [2/2]

static float DistancePointSegment2 ( Vector3  a,
Vector3  b,
Vector3  p 
)
static
Deprecated:
Obsolete

◆ DistancePointSegmentStrict()

static float DistancePointSegmentStrict ( Vector3  a,
Vector3  b,
Vector3  p 
)
static

Returns the squared distance between c and the line a-b.

The line is not considered infinite.

◆ FormatBytes()

static string FormatBytes ( int  bytes)
static
Deprecated:
Obsolete

◆ FormatBytesBinary()

static string FormatBytesBinary ( int  bytes)
static

Returns a nicely formatted string for the number of bytes (KiB, MiB, GiB etc).

Uses decimal names (KB, Mb - 1000) but calculates using binary values (KiB, MiB - 1024)

◆ Hermite()

static float Hermite ( float  start,
float  end,
float  value 
)
static
Deprecated:
Obsolete

◆ HSVToRGB()

static Color HSVToRGB ( float  h,
float  s,
float  v 
)
static

Converts an HSV color to an RGB color.

According to the algorithm described at http://en.wikipedia.org/wiki/HSL_and_HSV

Author
Wikipedia
Returns
the RGB representation of the color.

◆ IntToColor()

static Color IntToColor ( int  i,
float  a 
)
static

Returns a nice color from int i with alpha a.

Got code from the open-source Recast project, works really well. Seems like there are only 64 possible colors from studying the code

◆ Lerp()

static float Lerp ( float  a,
float  b,
float  t 
)
static
Deprecated:
Use Mathf.Lerp instead

◆ MagnitudeXZ()

static float MagnitudeXZ ( Vector3  a,
Vector3  b 
)
static
Deprecated:
Obsolete

◆ MapTo() [1/2]

static float MapTo ( float  startMin,
float  startMax,
float  value 
)
static

Maps a value between startMin and startMax to be between 0 and 1.

◆ MapTo() [2/2]

static float MapTo ( float  startMin,
float  startMax,
float  targetMin,
float  targetMax,
float  value 
)
static

Maps a value between startMin and startMax to be between targetMin and targetMax.

◆ MapToRange()

static float MapToRange ( float  targetMin,
float  targetMax,
float  value 
)
static
Deprecated:
Obsolete

◆ Max() [1/4]

static float Max ( float  a,
float  b 
)
static
Deprecated:
Use Mathf.Max instead

◆ Max() [2/4]

static int Max ( int  a,
int  b 
)
static
Deprecated:
Use Mathf.Max instead

◆ Max() [3/4]

static uint Max ( uint  a,
uint  b 
)
static
Deprecated:
Use Mathf.Max instead

◆ Max() [4/4]

static ushort Max ( ushort  a,
ushort  b 
)
static
Deprecated:
Use Mathf.Max instead

◆ Min() [1/3]

static float Min ( float  a,
float  b 
)
static
Deprecated:
Use Mathf.Min instead

◆ Min() [2/3]

static int Min ( int  a,
int  b 
)
static
Deprecated:
Use Mathf.Min instead

◆ Min() [3/3]

static uint Min ( uint  a,
uint  b 
)
static
Deprecated:
Use Mathf.Min instead

◆ NearestPoint()

static Vector3 NearestPoint ( Vector3  lineStart,
Vector3  lineEnd,
Vector3  point 
)
static

Returns the closest point on the line.

The line is treated as infinite.

See also
NearestPointStrict

◆ NearestPointFactor() [1/3]

static float NearestPointFactor ( Vector3  lineStart,
Vector3  lineEnd,
Vector3  point 
)
static

◆ NearestPointFactor() [2/3]

static float NearestPointFactor ( Int3  lineStart,
Int3  lineEnd,
Int3  point 
)
static

Factor of the nearest point on the segment.

Returned value is in the range [0,1] if the point lies on the segment otherwise it just lies on the line. The closest point can be got by (end-start)*factor + start;

◆ NearestPointFactor() [3/3]

static float NearestPointFactor ( Int2  lineStart,
Int2  lineEnd,
Int2  point 
)
static

Factor of the nearest point on the segment.

Returned value is in the range [0,1] if the point lies on the segment otherwise it just lies on the line. The closest point can be got by (end-start)*factor + start;

◆ NearestPointStrict()

static Vector3 NearestPointStrict ( Vector3  lineStart,
Vector3  lineEnd,
Vector3  point 
)
static

Returns the closest point on the line segment.

The line is NOT treated as infinite.

See also
NearestPoint

◆ NearestPointStrictXZ()

static Vector3 NearestPointStrictXZ ( Vector3  lineStart,
Vector3  lineEnd,
Vector3  point 
)
static

Returns the closest point on the line segment on the XZ plane.

The line is NOT treated as infinite.

See also
NearestPoint

◆ Repeat()

static int Repeat ( int  i,
int  n 
)
static
Deprecated:
Obsolete

◆ RoundToInt() [1/2]

static int RoundToInt ( float  v)
static
Deprecated:
Use Mathf.RoundToInt instead

◆ RoundToInt() [2/2]

static int RoundToInt ( double  v)
static
Deprecated:
Use Mathf.RoundToInt instead

◆ Sign() [1/2]

static float Sign ( float  a)
static
Deprecated:
Use Mathf.Sign instead

◆ Sign() [2/2]

static int Sign ( int  a)
static
Deprecated:
Use Mathf.Sign instead

◆ SqrMagnitudeXZ()

static float SqrMagnitudeXZ ( Vector3  a,
Vector3  b 
)
static

Squared distance between two points on the XZ plane.


The documentation for this class was generated from the following file: