joka.math

The math module provides mathematical data structures and functions.

Types 30

aliasColor = Rgba

The common color type.

aliasIVec2 = GVec2!int

A 2D vector using ints.

aliasVec2 = GVec2!float

A 2D vector using floats.

aliasIVec3 = GVec3!int

A 3D vector using ints.

aliasVec3 = GVec3!float

A 3D vector using floats.

aliasIVec4 = GVec4!int

A 4D vector using ints.

aliasVec4 = GVec4!float

A 4D vector using floats.

aliasIRect = GRect!int

A 2D rectangle using ints.

aliasRect = GRect!float

A 2D rectangle using floats.

aliasSRect = GRect!(int, short)

A 2D rectangle using ints for the position and shorts for the size.

aliasCirc = GCirc!float

A 2D circle using floats.

aliasLine = GLine!float

A 2D line using floats.

aliasTween = GTween!float

A tween using floats.

A tween using 2D vectors.

aliasRoundingFunc = float function(float x)

A function used for rounding.

aliasRounding64Func = double function(double x)

A function used for rounding.

aliasEasingFunc = float function(float x)

A function used for easing.

enumRounding : ubyte

A type representing rounding functions.

noneNo rounding.
floorRound down.
roundRound to nearest.
ceilRound up.
enumEasing : ubyte

A type representing easing functions.

linearConstant speed.
inSineSlow start.
outSineSlow end.
inOutSineSlow start and end.
inCubicCubic in.
outCubicCubic out.
inOutCubicCubic in-out.
inQuintQuintic in.
outQuintQuintic out.
inOutQuintQuintic in-out.
inCircCircular in.
outCircCircular out.
inOutCircCircular in-out.
inElasticElastic in.
outElasticElastic out.
inOutElasticElastic in-out.
inQuadQuadratic in.
outQuadQuadratic out.
inOutQuadQuadratic in-out.
inQuartQuartic in.
outQuartQuartic out.
inOutQuartQuartic in-out.
inExpoExponential in.
outExpoExponential out.
inOutExpoExponential in-out.
inBackBack in.
outBackBack out.
inOutBackBack in-out.
inBounceBounce in.
outBounceBounce out.
inOutBounceBounce in-out.
enumTweenMode : ubyte

A type that describes how a tween should update.

bombIt stops updating when it reaches the beginning or end of the animation.
loopIt returns to the beginning or end of the animation when it reaches the beginning or end of the animation.
yoyoIt reverses the given delta time when it reaches the beginning or end of the animation.
enumHook : ubyte

A type representing relative points.

topLeftThe top left point.
topThe top point.
topRightThe top right point.
leftThe left point.
centerThe center point.
rightThe right point.
bottomLeftThe bottom left point.
bottomThe bottom point.
bottomRightThe bottom right point.
structRgba

A RGBA color using ubytes.

Fields
ubyte r
ubyte g
ubyte b
ubyte a
"rgba" formThe form of the color.
Rgba(0, 0, 0, 0) zeroThe zero value of the color.
Rgba(1, 1, 1, 1) oneThe one value of the color.
4 lengthThe length of the color.
Methods
IStr toStr() @trusted
ubyte[] items() @trusted
bool isZero()
bool isOne()
Rgba alpha(ubyte value)Returns a color with just the alpha modified.
ubyte min()
ubyte max()
structGVec2(T)

A generic 2D vector.

Fields
T x
T y
"xy" formThe form of the vector.
GVec2!T(0) zeroThe zero value of the vector.
GVec2!T(1) oneThe one value of the vector.
2 lengthThe length of the vector.
Methods
IStr toStr() @trusted
T[] items() @trusted
bool isZero()
bool isOne()
T chop()
GVec2!T yx()
GVec2!T xx()
GVec2!T yy()
GVec2!T opBinary(IStr op)(GVec2!T rhs)
GVec2!T opBinary(IStr op)(T rhs)
GVec2!T opBinaryRight(IStr op)(T lhs)
void opOpAssign(IStr op)(GVec2!T rhs)
void opOpAssign(IStr op)(T rhs)
GVec2!T _swizzleN(G)(const(G)[] args...)
GVec2!T _swizzleC(IStr args...)
GVec2!T swizzle(G)(const(G)[] args...)
T min()
T max()
structGVec3(T)

A generic 3D vector.

Fields
T x
T y
T z
"xyz" formThe form of the vector.
GVec3!T(0) zeroThe zero value of the vector.
GVec3!T(1) oneThe one value of the vector.
3 lengthThe length of the vector.
Methods
IStr toStr() @trusted
T[] items() @trusted
bool isZero()
bool isOne()
GVec2!T yx()
GVec2!T xx()
GVec2!T yy()
GVec2!T xy()
GVec2!T yz()
GVec3!T opBinary(IStr op)(GVec3!T rhs)
GVec3!T opBinary(IStr op)(T rhs)
GVec3!T opBinaryRight(IStr op)(T lhs)
void opOpAssign(IStr op)(GVec3!T rhs)
void opOpAssign(IStr op)(T rhs)
GVec3!T _swizzleN(G)(const(G)[] args...)
GVec3!T _swizzleC(IStr args...)
GVec3!T swizzle(G)(const(G)[] args...)
T min()
T max()
structGVec4(T)

A generic 4D vector.

Fields
T x
T y
T z
T w
"xyzw" formThe form of the vector.
GVec4!T(0) zeroThe zero value of the vector.
GVec4!T(1) oneThe one value of the vector.
4 lengthThe length of the vector.
Methods
IStr toStr() @trusted
T[] items() @trusted
bool isZero()
bool isOne()
GVec2!T yx()
GVec2!T xx()
GVec2!T yy()
GVec2!T xy()
GVec2!T yz()
GVec4!T opBinary(IStr op)(GVec4!T rhs)
GVec4!T opBinary(IStr op)(T rhs)
GVec4!T opBinaryRight(IStr op)(T lhs)
void opOpAssign(IStr op)(GVec4!T rhs)
void opOpAssign(IStr op)(T rhs)
GVec4!T _swizzleN(G)(const(G)[] args...)
GVec4!T _swizzleC(IStr args...)
GVec4!T swizzle(G)(const(G)[] args...)
T min()
T max()
structGRect(P, S = P) if (P.sizeof >= S.sizeof)

A generic 2D rectangle.

Fields
GVec2!P position
GVec2!S size
Methods
IStr toStr() @trusted
P x() @trusted refThe X position of the rectangle.
P y() @trusted refThe Y position of the rectangle.
S w() @trusted refThe width of the rectangle.
S h() @trusted refThe height of the rectangle.
bool hasSize()
Self abs()
GVec2!P origin(Hook hook)
GVec2!P point(Hook hook)
Self area(Hook hook)
Self centerArea()
void fix()
bool hasPoint(GVec2!P point)
bool hasIntersection(Self area)
Self intersection(Self area)
Self merger(Self area)
P sliceX(P areaCount, P spacing = 0)
P sliceY(P areaCount, P spacing = 0)
Self addLeft(P amount)
Self addRight(P amount)
Self addTop(P amount)
Self addBottom(P amount)
Self subLeft(P amount, P spacing = 0)
Self subRight(P amount, P spacing = 0)
Self subTop(P amount, P spacing = 0)
Self subBottom(P amount, P spacing = 0)
Self addLeftRight(P amount)
Self addTopBottom(P amount)
Self addAll(P amount)
Self subLeftRight(P amount)
Self subTopBottom(P amount)
Self subAll(P amount)
structGCirc(T)

A generic 2D Circle.

Fields
GVec2!T position
T radius
Methods
IStr toStr() @trusted
T x() @trusted refThe X position of the circle.
T y() @trusted refThe Y position of the circle.
T r() @trusted refThe radius of the circle.
bool hasSize()
structGLine(T)

A generic 2D Line.

Fields
GVec2!T a
GVec2!T b
Methods
IStr toStr() @trusted
T x1() @trusted ref
T y1() @trusted ref
T x2() @trusted ref
T y2() @trusted ref
structGTween(T)

Handles the transition between two values over a specified duration.

Fields
T a
T b
float time
float duration
Easing type
bool isYoyoing
Methods
bool isAtStart()Returns true if time is at the start (0.0). Useful when using `TweenMode.bomb`.
bool isAtEnd()Returns true if time is at the end (duration). Useful when using `TweenMode.bomb`.
T now()Returns the current interpolated value between `a` and `b`.
T update(float delta)Advances the tween by the given delta time and returns the current value.
T reset()Resets the tween to the start and returns the current value.
float progress()Returns the current progress (between 0.0 to 1.0).
void setProgress(float value)Sets the progress to a specific value (between 0.0 to 1.0).
void setTime(float value)Sets the current time and applies the tween mode rules.
Constructors
this(T a, T b, float duration, TweenMode mode = TweenMode.bomb, Easing type = Easing.linear)Creates a new tween.

Handles the transition between two boolean states.

Fields
float progress
bool state
Methods
bool isAtStart()Returns true if progress is at the start (0.0).
bool isAtEnd()Returns true if progress is at the end (1.0).
bool isActive()Returns true if progress is not at the start (0.0) or the end (1.0).
float now()Returns the current progress (between 0.0 and 1.0).
float update(float delta)Advances the progress toward the current state. Returns the updated progress.
float reset()Resets the progress to 0.0. Returns the updated progress.
void setProgress(float value)Sets the progress to the given value (clamped).
bool toggle()Toggles the target state. Returns the new state.
bool toggleSnap()Toggles the state and instantly sets progress to match. Returns the new state.
Constructors
this(bool state)Creates a new toggle.

Functions 141

fnT abs(T)(T x)Returns the absolute value of `x`.
fnT min(T)(T a, T b)Returns the smaller of `a` and `b`.
fnT min3(T)(T a, T b, T c)Returns the smallest of `a`, `b`, and `c`.
fnT min4(T)(T a, T b, T c, T d)Returns the smallest of `a`, `b`, `c`, and `d`.
fnT max(T)(T a, T b)Returns the larger of `a` and `b`.
fnT max3(T)(T a, T b, T c)Returns the largest of `a`, `b`, and `c`.
fnT max4(T)(T a, T b, T c, T d)Returns the largest of `a`, `b`, `c`, and `d`.
fnT sign(T)(T x)Returns -1 if `x` is negative, 1 if positive, or 0 if zero.
fnT clamp(T)(T x, T a, T b)Returns `x` clamped to the range [`a`, `b`].
fnT wrap(T)(T x, T a, T b)Returns `x` wrapped to the range [`a`, `b`], wrapping around when out of bounds.
fnT snap(T)(T x, T step)Returns `x` rounded to the nearest multiple of `step`.
fnfloat fmod(float x, float y)
fndouble fmod64(double x, double y)
fnfloat remainder(float x, float y)
fndouble remainder64(double x, double y)
fnfloat exp(float x)
fndouble exp64(double x)
fnfloat exp2(float x)
fndouble exp264(double x)
fnfloat log(float x)
fndouble log64(double x)
fnfloat log10(float x)
fndouble log1064(double x)
fnfloat log2(float x)
fndouble log264(double x)
fnfloat pow(float base, float exponent)
fndouble pow64(double base, double exponent)
fnfloat atan2(float y, float x)
fndouble atan264(double y, double x)
fnfloat roundNothing(float x)
fndouble roundNothing64(double x)
fnfloat floorX(float x)
fndouble floorX64(double x)
fnfloat floor(float x)
fndouble floor64(double x)
fnfloat roundX(float x)
fndouble roundX64(double x)
fnfloat round(float x)
fndouble round64(double x)
fnfloat ceilX(float x)
fndouble ceilX64(double x)
fnfloat ceil(float x)
fndouble ceil64(double x)
fnfloat applyRounding(float x, Rounding type)
fndouble applyRounding64(double x, Rounding type)
fnfloat sqrt(float x)
fndouble sqrt64(double x)
fnfloat sin(float x)
fndouble sin64(double x)
fnfloat cos(float x)
fndouble cos64(double x)
fnfloat tan(float x)
fndouble tan64(double x)
fnfloat asin(float x)
fndouble asin64(double x)
fnfloat acos(float x)
fndouble acos64(double x)
fnfloat atan(float x)
fndouble atan64(double x)
fnfloat lerp(float from, float to, float weight)Returns the linear interpolation between `from` and `to` by `weight`. A weight of 0 returns `from`, a weight of 1 returns `to`.
fndouble lerp64(double from, double to, double weight)Returns the linear interpolation between `from` and `to` by `weight`. A weight of 0 returns `from`, a weight of 1 returns `to`.
fnfloat smoothstep(float from, float to, float weight)Returns 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.
fndouble smoothstep64(double from, double to, double weight)Returns 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.
fnfloat smootherstep(float from, float to, float weight)Returns 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.
fndouble smootherstep64(double from, double to, double weight)Returns 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.
fnfloat easeLinear(float x)Easing function with no acceleration. Returns `x` unchanged.
fnfloat easeInSine(float x)Easing function that starts slow and accelerates using a sine curve.
fnfloat easeOutSine(float x)Easing function that starts fast and decelerates using a sine curve.
fnfloat easeInOutSine(float x)Easing function that accelerates then decelerates using a sine curve.
fnfloat easeInCubic(float x)Easing function that starts slow and accelerates using a cubic curve.
fnfloat easeOutCubic(float x)Easing function that starts fast and decelerates using a cubic curve.
fnfloat easeInOutCubic(float x)Easing function that accelerates then decelerates using a cubic curve.
fnfloat easeInQuint(float x)Easing function that starts slow and accelerates using a quintic curve.
fnfloat easeOutQuint(float x)Easing function that starts fast and decelerates using a quintic curve.
fnfloat easeInOutQuint(float x)Easing function that accelerates then decelerates using a quintic curve.
fnfloat easeInCirc(float x)Easing function that starts slow and accelerates along a circular arc.
fnfloat easeOutCirc(float x)Easing function that starts fast and decelerates along a circular arc.
fnfloat easeInOutCirc(float x)Easing function that accelerates then decelerates along a circular arc.
fnfloat easeInElastic(float x)Easing function that overshoots the start with an elastic spring effect.
fnfloat easeOutElastic(float x)Easing function that overshoots the end with an elastic spring effect.
fnfloat easeInOutElastic(float x)Easing function that overshoots both ends with an elastic spring effect.
fnfloat easeInQuad(float x)Easing function that starts slow and accelerates using a quadratic curve.
fnfloat easeOutQuad(float x)Easing function that starts fast and decelerates using a quadratic curve.
fnfloat easeInOutQuad(float x)Easing function that accelerates then decelerates using a quadratic curve.
fnfloat easeInQuart(float x)Easing function that starts slow and accelerates using a quartic curve.
fnfloat easeOutQuart(float x)Easing function that starts fast and decelerates using a quartic curve.
fnfloat easeInOutQuart(float x)Easing function that accelerates then decelerates using a quartic curve.
fnfloat easeInExpo(float x)Easing function that starts slow and accelerates exponentially.
fnfloat easeOutExpo(float x)Easing function that starts fast and decelerates exponentially.
fnfloat easeInOutExpo(float x)Easing function that accelerates then decelerates exponentially.
fnfloat easeInBack(float x)Easing function that pulls back slightly before accelerating forward.
fnfloat easeOutBack(float x)Easing function that overshoots the target before settling.
fnfloat easeInOutBack(float x)Easing function that pulls back at the start and overshoots at the end.
fnfloat easeInBounce(float x)Easing function that starts with a bouncing effect before reaching the target.
fnfloat easeOutBounce(float x)Easing function that ends with a bouncing effect after reaching the target.
fnfloat easeInOutBounce(float x)Easing function that bounces at both the start and end.
fnbool fequals(float a, float b, float localEpsilon = epsilon)Returns true if `a` and `b` are within `localEpsilon` of each other.
fnbool fequals64(double a, double b, double localEpsilon = epsilon)Returns true if `a` and `b` are within `localEpsilon` of each other.
fnbool fequals(Vec2 a, Vec2 b, float localEpsilon = epsilon)Returns true if all components of `a` and `b` are within `localEpsilon` of each other.
fnbool fequals(Vec3 a, Vec3 b, float localEpsilon = epsilon)Returns true if all components of `a` and `b` are within `localEpsilon` of each other.
fnbool fequals(Vec4 a, Vec4 b, float localEpsilon = epsilon)Returns true if all components of `a` and `b` are within `localEpsilon` of each other.
fnfloat toRadians(float degrees)Converts degrees to radians.
fndouble toRadians64(double degrees)Converts degrees to radians.
fnfloat toDegrees(float radians)Converts radians to degrees.
fndouble toDegrees64(double radians)Converts radians to degrees.
fnIVec2 toIVec(Vec2 vec)Converts a `Vec2` to an `IVec2` by truncating each component to an integer.
fnIVec3 toIVec(Vec3 vec)Converts a `Vec3` to an `IVec3` by truncating each component to an integer.
fnIVec4 toIVec(Vec4 vec)Converts a `Vec4` to an `IVec4` by truncating each component to an integer.
fnVec2 toVec(IVec2 vec)Converts an `IVec2` to a `Vec2`.
fnVec2 toVec(GVec2!short vec)Converts a `GVec2!short` to a `Vec2`.
fnVec3 toVec(IVec3 vec)Converts an `IVec3` to a `Vec3`.
fnVec4 toVec(IVec4 vec)Converts an `IVec4` to a `Vec4`.
fnVec4 toVec(Rgba color)Converts an `Rgba` color to a `Vec4` with components in the order `(r, g, b, a)`.
fnIRect toIRect(Rect rect)Converts a `Rect` to an `IRect` by truncating position and size components to integers.
fnRect toRect(IRect rect)Converts an `IRect` to a `Rect`.
fnRect toRect(SRect rect)Converts an `SRect` to a `Rect`.
fnRgba toRgb(uint rgb)Converts a packed 24-bit RGB integer to an `Rgba` color with full opacity.
fnRgba toRgba(uint rgba)Converts a packed 32-bit RGBA integer to an `Rgba` color.
fnRgba toRgba(Vec3 vec)Converts a `Vec3` to an `Rgba` color, clamping each component to the range [0, 255] with full opacity.
fnRgba toRgba(Vec4 vec)Converts a `Vec4` to an `Rgba` color, clamping each component to the range [0, 255].
fnRgba toRgba(IStr str)Converts a hex color string (e.g. `"#RGB"`, `"RRGGBB"`, `"RRGGBBAA"`) to an `Rgba` color. Returns `blank` if the string is invalid.
fnVec2 lerp(Vec2 from, Vec2 to, float weight)Returns the linear interpolation between `from` and `to` by `weight`, applied per component.
fnVec3 lerp(Vec3 from, Vec3 to, float weight)Returns the linear interpolation between `from` and `to` by `weight`, applied per component.
fnVec4 lerp(Vec4 from, Vec4 to, float weight)Returns the linear interpolation between `from` and `to` by `weight`, applied per component.
fnRoundingFunc rounding(Rounding type)Returns the rounding function corresponding to the given `Rounding` type.
fnRounding64Func rounding64(Rounding type)Returns the 64-bit rounding function corresponding to the given `Rounding` type.
fnEasingFunc easing(Easing type)Returns the easing function corresponding to the given `Easing` type.
fnfloat moveToState(float from, bool to, float delta)Moves `from` toward 1 by `delta` if `to` is true, or toward 0 if false. Result is clamped to [0, 1].
fnfloat moveToState64(double from, bool to, double delta)Moves `from` toward 1 by `delta` if `to` is true, or toward 0 if false. Result is clamped to [0, 1].
fnfloat followState(ref float weight, bool target, float speed)Moves `weight` by ref toward the `target` state by `speed` and returns the updated value.
fndouble followState64(ref double weight, bool target, double speed)Moves `weight` by ref toward the `target` state by `speed` and returns the updated value.
fnfloat moveTo(float from, float to, float delta)Moves `from` toward `to` by at most `delta`, stopping exactly at `to`.
fnfloat moveTo64(double from, double to, double delta)Moves `from` toward `to` by at most `delta`, stopping exactly at `to`.
fnVec2 moveTo(Vec2 from, Vec2 to, Vec2 delta)Moves `from` toward `to` per component by at most `delta`, stopping exactly at `to`.
fnVec3 moveTo(Vec3 from, Vec3 to, Vec3 delta)Moves `from` toward `to` per component by at most `delta`, stopping exactly at `to`.
fnVec4 moveTo(Vec4 from, Vec4 to, Vec4 delta)Moves `from` toward `to` per component by at most `delta`, stopping exactly at `to`.
fnfloat moveToWithSlowdown(float from, float to, float delta, float slowdown)Moves `from` toward `to` by `delta` each step, decelerating as it approaches using `slowdown`. A `slowdown` value around 0.1 gives a natural deceleration feel.
fnfloat moveToWithSlowdown64(double from, double to, double delta, double slowdown)Moves `from` toward `to` by `delta` each step, decelerating as it approaches using `slowdown`. A `slowdown` value around 0.1 gives a natural deceleration feel.
fnVec2 moveToWithSlowdown(Vec2 from, Vec2 to, Vec2 delta, float slowdown)Moves `from` toward `to` per component by `delta`, decelerating as it approaches using `slowdown`. A `slowdown` value around 0.1 gives a natural deceleration feel.
fnVec3 moveToWithSlowdown(Vec3 from, Vec3 to, Vec3 delta, float slowdown)Moves `from` toward `to` per component by `delta`, decelerating as it approaches using `slowdown`. A `slowdown` value around 0.1 gives a natural deceleration feel.
fnVec4 moveToWithSlowdown(Vec4 from, Vec4 to, Vec4 delta, float slowdown)Moves `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

enumvarepsilon = 0.0001

The value of epsilon.

enumvareuler = 2.71828182845904523536028747135266249

The value of Euler's number.

enumvarlog2e = 1.44269504088896340735992468100189214

The value of log2(e).

enumvarlog10e = 0.43429448190325182765112891891660508

The value of log10(e).

enumvarln2 = 0.69314718055994530941723212145817656

The value of ln(2).

enumvarln10 = 2.30258509299404568401799145468436421

The value of ln(10).

enumvarpi = 3.14159265358979323846264338327950288

The value of PI.

enumvarpi2 = pi / 2.0

The value of PI / 2.

enumvarpi4 = pi / 4.0

The value of PI / 4.

enumvarpi180 = pi / 180.0

The value of PI / 180.

enumvardpi = 1.0 / pi

The value of 1 / PI.

enumvardpi2 = 2.0 / pi

The value of 2 / PI.

enumvardpi180 = 180.0 / pi

The value of 180 / PI.

enumvarsqrt2 = 1.41421356237309504880168872420969808

The value of sqrt(2).

enumvardsqrt2 = 0.70710678118654752440084436210484903

The value of 1 / sqrt(2).

enumvarblank = Rgba()

Not a color.

enumvarblack = Rgba(0)

Black black.

enumvarwhite = Rgba(255)

White white.

enumvarred = Rgba(255, 0, 0)

Red red.

enumvargreen = Rgba(0, 255, 0)

Green green.

enumvarblue = Rgba(0, 0, 255)

Blue blue.

enumvaryellow = Rgba(255, 255, 0)

Yellow yellow.

enumvarmagenta = Rgba(255, 0, 255)

Magenta magenta.

enumvarpink = Rgba(255, 192, 204)

Pink pink.

enumvarcyan = Rgba(0, 255, 255)

Cyan cyan.

enumvarorange = Rgba(255, 165, 0)

Orange orange.

enumvarbeige = Rgba(240, 235, 210)

Beige beige.

enumvarbrown = Rgba(165, 72, 42)

Brown brown.

enumvarmaroon = Rgba(128, 0, 0)

Maroon maroon.

enumvargray1 = Rgba(32, 32, 32)

Gray 1.

enumvargray2 = Rgba(96, 96, 96)

Gray 22.

enumvargray3 = Rgba(159, 159, 159)

Gray 333.

enumvargray4 = Rgba(223, 223, 223)

Gray 4444.

enumvargray = gray2

Gray gray.