Vixen
02b45cc4
csharp
public static class MathUtil

Scalar helpers the rest of the library and the engine share: the constants, the tolerance comparisons, and the interpolation and clamping that would otherwise be rewritten slightly differently in every subsystem.

No guide page documents this yet — the page shows what the code says about itself.

Fields and properties (6)

  • public const float Pi

    π.

  • public const float TwoPi

    2π — a full turn.

  • public const float PiOverTwo

    π/2 — a quarter turn.

  • public const float PiOverFour

    π/4 — an eighth of a turn.

  • public const float ZeroTolerance

    The default tolerance for "close enough": about 8 significant decimal digits of headroom below Single's ~7. Small enough that it does not hide a real error, large enough to absorb the rounding of a few chained operations.

  • public const float RoundingSlack

    The slack a predicate needs when it compares two quantities that were rounded independently: eight times Single's unit roundoff of 2⁻²⁴, which is about the loss of a chain of half a dozen operations with room to spare.

Methods (19)

  • public static float DegreesToRadians(float degrees)

    Converts degrees to radians.

  • public static float RadiansToDegrees(float radians)

    Converts radians to degrees.

  • public static bool IsZero(float value)

    Whether a value is within ZeroTolerance of zero.

  • public static bool IsOne(float value)

    Whether a value is within ZeroTolerance of one.

  • public static bool NearEqual(float left, float right, float tolerance = 1E-06)

    Whether two values are close enough to be treated as equal. The tolerance is scaled by the larger magnitude, so it behaves absolutely near zero and relatively out where Single steps in units of thousands — a fixed epsilon is wrong at one end or the other and there is no single value that is right at both.

  • public static float Clamp(float value, float min, float max)

    Constrains a value to an interval.

  • public static int Clamp(int value, int min, int max)
  • public static float Saturate(float value)

    Constrains a value to [0, 1].

  • public static float Lerp(float from, float to, float amount)

    Linearly interpolates between two values.

  • public static float InverseLerp(float from, float to, float value)

    Finds the interpolant that Lerp would need.

  • public static float SmoothStep(float amount)

    Interpolates with a curve that is flat at both ends (3t² − 2t³).

  • public static float SmootherStep(float amount)

    Interpolates with a curve whose first and second derivatives vanish at both ends (6t⁵ − 15t⁴ + 10t³). Worth the extra multiplies wherever the result drives acceleration, because SmoothStep has a visible jerk at its endpoints.

  • public static float WrapAngle(float radians)

    Wraps an angle into (−π, π].

  • public static float DeltaAngle(float from, float to)

    The shortest signed angle from one angle to another, in (−π, π]. Interpolating a heading without this goes the long way round whenever the pair straddles ±π.

  • public static bool IsPowerOfTwo(int value)

    Whether a value is a power of two. Zero is not.

  • public static int NextPowerOfTwo(int value)

    The smallest power of two that is at least .

  • public static int AlignUp(int value, int alignment)

    Rounds up to a multiple of .

  • public static float Repeat(float value, float length)

    Wraps a value into [0, length), unlike %, which reflects around zero for negative input and is almost never what a looping animation or a tiled coordinate wants.

  • public static float PingPong(float value, float length)

    Bounces a value back and forth within [0, length].

Used by (133, showing 40)

  • PlayerRigThirdPersonShooter
  • SamplingBenchmarksVixen.Benchmarks.Animation
  • AimGoalVixen.Animation
  • AlgebraicPropertyTestsVixen.Core.Mathematics.Tests
  • AnalyticVixen.Rendering.IrradianceFields.Tests
  • AnimationClipVixen.Animation
  • AnimationLayerVixen.Animation
  • AnimatorVixen.Animation
  • AttachmentSocketVixen.Animation
  • AudioFadeVixen.Audio
  • BlendedVixen.Rendering
  • BoneTransformVixen.Animation
  • BoneTransformTestsVixen.Animation.Tests
  • BoundingBoxVixen.Core.Mathematics
  • BoundingFrustumVixen.Core.Mathematics
  • BoundingSphereVixen.Core.Mathematics
  • BuilderVixen.Animation
  • CameraVixen.Engine
  • CameraBlendVixen.Engine
  • CameraConstraintsVixen.Animation
  • CameraDampingTestsVixen.Engine.Tests
  • CameraDirectorTestsVixen.Engine.Tests
  • CameraFramingVixen.Engine
  • CameraImpulsesVixen.Engine
  • CameraLensVixen.Engine
  • CameraNoiseVixen.Engine
  • CameraNoiseSignalVixen.Engine
  • CharacterControllerVixen.Physics
  • CharacterControllerSettingsVixen.Physics
  • CharacterMotionTestsVixen.Physics.Tests
  • Color3Vixen.Core.Mathematics
  • Color4Vixen.Core.Mathematics
  • ConstraintDescriptionVixen.Physics
  • ConstraintGizmoStyleVixen.Animation
  • ConstraintGizmosVixen.Animation
  • ConstraintProposalsVixen.Animation
  • ConstraintResidualVixen.Animation
  • ConstraintStackVixen.Animation
  • ConstraintTagVixen.Animation
  • ConstraintTemplateContentVixen.Animation