MathUtils

MathUtils

Pure C# math utilities to replace Godot’s Mathf class. Provides AOT-compatible math operations for iOS/Android. Shared-safe: stateless and thread-safe; safe to reuse across user scopes.

Project: GridPlacement v6.0
Layer: Core
Source: Core/Math/MathUtils.cs
Namespace: GridBuilding.Core.Math
Kind: class

Parsing Method: AST-based (Roslyn) - NOT regex

⚠️ IMPORTANT: This documentation was generated using AST parsing, not regex.

Methods

Clamp

Clamps a value between min and max (inclusive).

Returns: int

Parameters:

  • int value
  • int min
  • int max

Clamp

Clamps a float value between min and max (inclusive).

Returns: float

Parameters:

  • float value
  • float min
  • float max

Clamp

Clamps a double value between min and max (inclusive).

Returns: double

Parameters:

  • double value
  • double min
  • double max

Max

Returns the larger of two integers.

Returns: int

Parameters:

  • int a
  • int b

Max

Returns the larger of two floats.

Returns: float

Parameters:

  • float a
  • float b

Max

Returns the larger of two doubles.

Returns: double

Parameters:

  • double a
  • double b

Min

Returns the smaller of two integers.

Returns: int

Parameters:

  • int a
  • int b

Min

Returns the smaller of two floats.

Returns: float

Parameters:

  • float a
  • float b

Min

Returns the smaller of two doubles.

Returns: double

Parameters:

  • double a
  • double b

Lerp

Linear interpolation between two values.

Returns: float

Parameters:

  • float from
  • float to
  • float weight

Lerp

Linear interpolation between two double values.

Returns: double

Parameters:

  • double from
  • double to
  • double weight

InverseLerp

Inverse linear interpolation - returns where a value falls between two points.

Returns: float

Parameters:

  • float from
  • float to
  • float value

Abs

Returns the absolute value of an integer.

Returns: int

Parameters:

  • int value

Abs

Returns the absolute value of a float.

Returns: float

Parameters:

  • float value

Sign

Returns the sign of a number (-1, 0, or 1).

Returns: int

Parameters:

  • int value

Sign

Returns the sign of a float (-1, 0, or 1).

Returns: float

Parameters:

  • float value

RoundToInt

Rounds a float to the nearest integer.

Returns: int

Parameters:

  • float value

FloorToInt

Floors a float to the nearest integer.

Returns: int

Parameters:

  • float value

CeilToInt

Ceils a float to the nearest integer.

Returns: int

Parameters:

  • float value

Approximately

Checks if two floats are approximately equal within epsilon.

Returns: bool

Parameters:

  • float a
  • float b
  • float epsilon

Wrap

Wraps a value to stay within a range [0, length).

Returns: int

Parameters:

  • int value
  • int length

Wrap

Wraps a float value to stay within a range [0, length).

Returns: float

Parameters:

  • float value
  • float length

Distance

Calculates the distance between two points.

Returns: float

Parameters:

  • float x1
  • float y1
  • float x2
  • float y2

DistanceSquared

Calculates the squared distance between two points (faster than Distance).

Returns: float

Parameters:

  • float x1
  • float y1
  • float x2
  • float y2

DegToRad

Converts degrees to radians.

Returns: float

Parameters:

  • float degrees

RadToDeg

Converts radians to degrees.

Returns: float

Parameters:

  • float radians

SmoothStep

Smoothly interpolates between two values using cubic Hermite interpolation.

Returns: float

Parameters:

  • float from
  • float to
  • float weight

MoveToward

Moves a value toward a target by a maximum delta.

Returns: float

Parameters:

  • float from
  • float to
  • float delta