joka.math
The math module provides mathematical data structures and functions.
Types 30
A function used for rounding.
A function used for rounding.
A function used for easing.
A type representing rounding functions.
A type representing easing functions.
A type that describes how a tween should update.
A type representing relative points.
A RGBA color using ubytes.
ubyte rubyte gubyte bubyte a formThe form of the color. zeroThe zero value of the color. oneThe one value of the color. lengthThe length of the color.A generic 2D vector.
T xT y formThe form of the vector. zeroThe zero value of the vector. oneThe one value of the vector. lengthThe length of the vector.A generic 3D vector.
T xT yT z formThe form of the vector. zeroThe zero value of the vector. oneThe one value of the vector. lengthThe length of the vector.A generic 4D vector.
T xT yT zT w formThe form of the vector. zeroThe zero value of the vector. oneThe one value of the vector. lengthThe length of the vector.A generic 2D rectangle.
A generic 2D Circle.
A generic 2D Line.
Handles the transition between two values over a specified duration.
bool isAtStart() @safe nothrow @nogcReturns true if time is at the start (0.0). Useful when using `TweenMode.bomb`.bool isAtEnd() @safe nothrow @nogcReturns true if time is at the end (duration). Useful when using `TweenMode.bomb`.T update(float delta) @safe nothrow @nogcAdvances the tween by the given delta time and returns the current value.void setProgress(float value) @safe nothrow @nogcSets the progress to a specific value (between 0.0 to 1.0).void setTime(float value) @safe nothrow @nogcSets the current time and applies the tween mode rules.Handles the transition between two boolean states.
float progressbool statebool isActive() @safe nothrow @nogcReturns true if progress is not at the start (0.0) or the end (1.0).float update(float delta) @safe nothrow @nogcAdvances the progress toward the current state. Returns the updated progress.bool toggleSnap() @safe nothrow @nogcToggles the state and instantly sets progress to match. Returns the new state.this(bool state)Creates a new toggle.Functions 126
T wrap(T)(T x, T a, T b) @trusted @safe nothrow @nogcReturns `x` wrapped to the range [`a`, `b`], wrapping around when out of bounds.T snap(T)(T x, T step) @trusted @safe nothrow @nogcReturns `x` rounded to the nearest multiple of `step`.float fmod(float x, float y) @trusted @safe nothrow @nogcReturns the floating-point remainder of `x / y`.double fmod64(double x, double y) @trusted @safe nothrow @nogcReturns the floating-point remainder of `x / y`.float remainder(float x, float y) @trusted @safe nothrow @nogcReturns the IEEE 754 floating-point remainder of `x / y`.double remainder64(double x, double y) @trusted @safe nothrow @nogcReturns the IEEE 754 floating-point remainder of `x / y`.float exp(float x) @trusted @safe nothrow @nogcReturns Euler's number `e` raised to the power of `x`.double exp64(double x) @trusted @safe nothrow @nogcReturns Euler's number `e` raised to the power of `x`.float pow(float base, float exponent) @trusted @safe nothrow @nogcReturns `base` raised to the power of `exponent`.double pow64(double base, double exponent) @trusted @safe nothrow @nogcReturns `base` raised to the power of `exponent`.float atan2(float y, float x) @trusted @safe nothrow @nogcReturns the angle between the positive x-axis and the point (`x`, `y`).double atan264(double y, double x) @trusted @safe nothrow @nogcReturns the angle between the positive x-axis and the point (`x`, `y`).float applyRounding(float x, Rounding type) @trusted @safe nothrow @nogcApplies the specified `type` of rounding to `x`.double applyRounding64(double x, Rounding type) @trusted @safe nothrow @nogcApplies the specified `type` of rounding to `x`.float lerp(float from, float to, float weight) @trusted @safe nothrow @nogcReturns the linear interpolation between `from` and `to` by `weight`. A weight of 0 returns `from`, a weight of 1 returns `to`.double lerp64(double from, double to, double weight) @trusted @safe nothrow @nogcReturns the linear interpolation between `from` and `to` by `weight`. A weight of 0 returns `from`, a weight of 1 returns `to`.float smoothstep(float from, float to, float weight) @trusted @safe nothrow @nogcReturns the smooth interpolation between `from` and `to` by `weight` using a cubic curve. Eases in and out, with zero first-order derivatives at both endpoints.double smoothstep64(double from, double to, double weight) @trusted @safe nothrow @nogcReturns the smooth interpolation between `from` and `to` by `weight` using a cubic curve. Eases in and out, with zero first-order derivatives at both endpoints.float smootherstep(float from, float to, float weight) @trusted @safe nothrow @nogcReturns the smoother interpolation between `from` and `to` by `weight` using a quintic curve. Eases in and out, with zero first and second-order derivatives at both endpoints.double smootherstep64(double from, double to, double weight) @trusted @safe nothrow @nogcReturns the smoother interpolation between `from` and `to` by `weight` using a quintic curve. Eases in and out, with zero first and second-order derivatives at both endpoints.float easeLinear(float x) @trusted @safe nothrow @nogcEasing function with no acceleration. Returns `x` unchanged.float easeInSine(float x) @trusted @safe nothrow @nogcEasing function that starts slow and accelerates using a sine curve.float easeOutSine(float x) @trusted @safe nothrow @nogcEasing function that starts fast and decelerates using a sine curve.float easeInOutSine(float x) @trusted @safe nothrow @nogcEasing function that accelerates then decelerates using a sine curve.float easeInCubic(float x) @trusted @safe nothrow @nogcEasing function that starts slow and accelerates using a cubic curve.float easeOutCubic(float x) @trusted @safe nothrow @nogcEasing function that starts fast and decelerates using a cubic curve.float easeInOutCubic(float x) @trusted @safe nothrow @nogcEasing function that accelerates then decelerates using a cubic curve.float easeInQuint(float x) @trusted @safe nothrow @nogcEasing function that starts slow and accelerates using a quintic curve.float easeOutQuint(float x) @trusted @safe nothrow @nogcEasing function that starts fast and decelerates using a quintic curve.float easeInOutQuint(float x) @trusted @safe nothrow @nogcEasing function that accelerates then decelerates using a quintic curve.float easeInCirc(float x) @trusted @safe nothrow @nogcEasing function that starts slow and accelerates along a circular arc.float easeOutCirc(float x) @trusted @safe nothrow @nogcEasing function that starts fast and decelerates along a circular arc.float easeInOutCirc(float x) @trusted @safe nothrow @nogcEasing function that accelerates then decelerates along a circular arc.float easeInElastic(float x) @trusted @safe nothrow @nogcEasing function that overshoots the start with an elastic spring effect.float easeOutElastic(float x) @trusted @safe nothrow @nogcEasing function that overshoots the end with an elastic spring effect.float easeInOutElastic(float x) @trusted @safe nothrow @nogcEasing function that overshoots both ends with an elastic spring effect.float easeInQuad(float x) @trusted @safe nothrow @nogcEasing function that starts slow and accelerates using a quadratic curve.float easeOutQuad(float x) @trusted @safe nothrow @nogcEasing function that starts fast and decelerates using a quadratic curve.float easeInOutQuad(float x) @trusted @safe nothrow @nogcEasing function that accelerates then decelerates using a quadratic curve.float easeInQuart(float x) @trusted @safe nothrow @nogcEasing function that starts slow and accelerates using a quartic curve.float easeOutQuart(float x) @trusted @safe nothrow @nogcEasing function that starts fast and decelerates using a quartic curve.float easeInOutQuart(float x) @trusted @safe nothrow @nogcEasing function that accelerates then decelerates using a quartic curve.float easeInExpo(float x) @trusted @safe nothrow @nogcEasing function that starts slow and accelerates exponentially.float easeOutExpo(float x) @trusted @safe nothrow @nogcEasing function that starts fast and decelerates exponentially.float easeInOutExpo(float x) @trusted @safe nothrow @nogcEasing function that accelerates then decelerates exponentially.float easeInBack(float x) @trusted @safe nothrow @nogcEasing function that pulls back slightly before accelerating forward.float easeOutBack(float x) @trusted @safe nothrow @nogcEasing function that overshoots the target before settling.float easeInOutBack(float x) @trusted @safe nothrow @nogcEasing function that pulls back at the start and overshoots at the end.float easeInBounce(float x) @trusted @safe nothrow @nogcEasing function that starts with a bouncing effect before reaching the target.float easeOutBounce(float x) @trusted @safe nothrow @nogcEasing function that ends with a bouncing effect after reaching the target.float easeInOutBounce(float x) @trusted @safe nothrow @nogcEasing function that bounces at both the start and end.bool fequals(float a, float b, float localEpsilon = epsilon) @trusted @safe nothrow @nogcReturns true if `a` and `b` are within `localEpsilon` of each other.bool fequals64(double a, double b, double localEpsilon = epsilon) @trusted @safe nothrow @nogcReturns true if `a` and `b` are within `localEpsilon` of each other.bool fequals(Vec2 a, Vec2 b, float localEpsilon = epsilon) @trusted @safe nothrow @nogcReturns true if all components of `a` and `b` are within `localEpsilon` of each other.bool fequals(Vec3 a, Vec3 b, float localEpsilon = epsilon) @trusted @safe nothrow @nogcReturns true if all components of `a` and `b` are within `localEpsilon` of each other.bool fequals(Vec4 a, Vec4 b, float localEpsilon = epsilon) @trusted @safe nothrow @nogcReturns true if all components of `a` and `b` are within `localEpsilon` of each other.IVec2 toIVec(Vec2 vec) @trusted @safe nothrow @nogcConverts a `Vec2` to an `IVec2` by truncating each component to an integer.IVec3 toIVec(Vec3 vec) @trusted @safe nothrow @nogcConverts a `Vec3` to an `IVec3` by truncating each component to an integer.IVec4 toIVec(Vec4 vec) @trusted @safe nothrow @nogcConverts a `Vec4` to an `IVec4` by truncating each component to an integer.Vec4 toVec(Rgba color) @trusted @safe nothrow @nogcConverts an `Rgba` color to a `Vec4` with components in the order `(r, g, b, a)`.IRect toIRect(Rect rect) @trusted @safe nothrow @nogcConverts a `Rect` to an `IRect` by truncating position and size components to integers.Rgba toRgb(uint rgb) @trusted @safe nothrow @nogcConverts a packed 24-bit RGB integer to an `Rgba` color with full opacity.Rgba toRgba(uint rgba) @trusted @safe nothrow @nogcConverts a packed 32-bit RGBA integer to an `Rgba` color.Rgba toRgba(Vec3 vec) @trusted @safe nothrow @nogcConverts a `Vec3` to an `Rgba` color, clamping each component to the range [0, 255] with full opacity.Rgba toRgba(Vec4 vec) @trusted @safe nothrow @nogcConverts a `Vec4` to an `Rgba` color, clamping each component to the range [0, 255].Rgba toRgba(IStr str) @trusted @safe nothrow @nogcConverts a hex color string (e.g. `"#RGB"`, `"RRGGBB"`, `"RRGGBBAA"`) to an `Rgba` color. Returns `blank` if the string is invalid.Vec2 lerp(Vec2 from, Vec2 to, float weight) @trusted @safe nothrow @nogcReturns the linear interpolation between `from` and `to` by `weight`, applied per component.Vec3 lerp(Vec3 from, Vec3 to, float weight) @trusted @safe nothrow @nogcReturns the linear interpolation between `from` and `to` by `weight`, applied per component.Vec4 lerp(Vec4 from, Vec4 to, float weight) @trusted @safe nothrow @nogcReturns the linear interpolation between `from` and `to` by `weight`, applied per component.RoundingFunc rounding(Rounding type) @trusted @safe nothrow @nogcReturns the rounding function corresponding to the given `Rounding` type.Rounding64Func rounding64(Rounding type) @trusted @safe nothrow @nogcReturns the 64-bit rounding function corresponding to the given `Rounding` type.EasingFunc easing(Easing type) @trusted @safe nothrow @nogcReturns the easing function corresponding to the given `Easing` type.float moveToState(float from, bool to, float delta) @trusted @safe nothrow @nogcMoves `from` toward 1 by `delta` if `to` is true, or toward 0 if false. Result is clamped to [0, 1].float moveToState64(double from, bool to, double delta) @trusted @safe nothrow @nogcMoves `from` toward 1 by `delta` if `to` is true, or toward 0 if false. Result is clamped to [0, 1].float followState(ref float weight, bool target, float speed) @trusted @safe nothrow @nogcMoves `weight` by ref toward the `target` state by `speed` and returns the updated value.double followState64(ref double weight, bool target, double speed) @trusted @safe nothrow @nogcMoves `weight` by ref toward the `target` state by `speed` and returns the updated value.float moveTo(float from, float to, float delta) @trusted @safe nothrow @nogcMoves `from` toward `to` by at most `delta`, stopping exactly at `to`.float moveTo64(double from, double to, double delta) @trusted @safe nothrow @nogcMoves `from` toward `to` by at most `delta`, stopping exactly at `to`.Vec2 moveTo(Vec2 from, Vec2 to, Vec2 delta) @trusted @safe nothrow @nogcMoves `from` toward `to` per component by at most `delta`, stopping exactly at `to`.Vec3 moveTo(Vec3 from, Vec3 to, Vec3 delta) @trusted @safe nothrow @nogcMoves `from` toward `to` per component by at most `delta`, stopping exactly at `to`.Vec4 moveTo(Vec4 from, Vec4 to, Vec4 delta) @trusted @safe nothrow @nogcMoves `from` toward `to` per component by at most `delta`, stopping exactly at `to`.float moveToWithSlowdown(float from, float to, float delta, float slowdown) @trusted @safe nothrow @nogcMoves `from` toward `to` by `delta` each step, decelerating as it approaches using `slowdown`. A `slowdown` value around 0.1 gives a natural deceleration feel.float moveToWithSlowdown64(double from, double to, double delta, double slowdown) @trusted @safe nothrow @nogcMoves `from` toward `to` by `delta` each step, decelerating as it approaches using `slowdown`. A `slowdown` value around 0.1 gives a natural deceleration feel.Vec2 moveToWithSlowdown(Vec2 from, Vec2 to, Vec2 delta, float slowdown) @trusted @safe nothrow @nogcMoves `from` toward `to` per component by `delta`, decelerating as it approaches using `slowdown`. A `slowdown` value around 0.1 gives a natural deceleration feel.Vec3 moveToWithSlowdown(Vec3 from, Vec3 to, Vec3 delta, float slowdown) @trusted @safe nothrow @nogcMoves `from` toward `to` per component by `delta`, decelerating as it approaches using `slowdown`. A `slowdown` value around 0.1 gives a natural deceleration feel.Vec4 moveToWithSlowdown(Vec4 from, Vec4 to, Vec4 delta, float slowdown) @trusted @safe nothrow @nogcMoves `from` toward `to` per component by `delta`, decelerating as it approaches using `slowdown`. A `slowdown` value around 0.1 gives a natural deceleration feel.Variables 34
epsilon = 0.0001The value of epsilon.
euler = 2.71828182845904523536028747135266249The value of Euler's number.
log2e = 1.44269504088896340735992468100189214The value of log2(e).
log10e = 0.43429448190325182765112891891660508The value of log10(e).
ln2 = 0.69314718055994530941723212145817656The value of ln(2).
ln10 = 2.30258509299404568401799145468436421The value of ln(10).
pi = 3.14159265358979323846264338327950288The value of PI.
pi2 = pi / 2.0The value of PI / 2.
pi4 = pi / 4.0The value of PI / 4.
pi180 = pi / 180.0The value of PI / 180.
dpi = 1.0 / piThe value of 1 / PI.
dpi2 = 2.0 / piThe value of 2 / PI.
dpi180 = 180.0 / piThe value of 180 / PI.
sqrt2 = 1.41421356237309504880168872420969808The value of sqrt(2).
dsqrt2 = 0.70710678118654752440084436210484903The value of 1 / sqrt(2).
blank = Rgba()#00000000
black = Rgba(0)#000000FF
white = Rgba(255)#FFFFFFFF
red = Rgba(255, 0, 0)#FF0000FF
green = Rgba(0, 255, 0)#00FF00FF
blue = Rgba(0, 0, 255)#0000FFFF
yellow = Rgba(255, 255, 0)#FFFF00FF
magenta = Rgba(255, 0, 255)#FF00FFFF
cyan = Rgba(0, 255, 255)#00FFFFFF
pink = Rgba(255, 192, 204)#FFC0CCFF
orange = Rgba(255, 165, 0)#FFA500FF
beige = Rgba(240, 235, 210)#F0EBD2FF
brown = Rgba(165, 72, 42)#A5482AFF
maroon = Rgba(128, 0, 0)#800000FF
gray1 = Rgba(32, 32, 32)#202020FF
gray2 = Rgba(96, 96, 96)#606060FF
gray3 = Rgba(159, 159, 159)#9F9F9FFF
gray4 = Rgba(223, 223, 223)#DFDFDFFF
gray = gray2#606060FF