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 generic 2D vector.
T xT 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.T[] items() @trustedbool isZero()bool isOne()T chop()GVec2!T opBinaryRight(IStr op)(T lhs)void opOpAssign(IStr op)(GVec2!T rhs)void opOpAssign(IStr op)(T rhs)T min()T max()A generic 3D vector.
T xT yT 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.T[] items() @trustedbool isZero()bool isOne()GVec3!T opBinaryRight(IStr op)(T lhs)void opOpAssign(IStr op)(GVec3!T rhs)void opOpAssign(IStr op)(T rhs)T min()T max()A generic 4D vector.
T xT yT zT 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.T[] items() @trustedbool isZero()bool isOne()GVec4!T opBinaryRight(IStr op)(T lhs)void opOpAssign(IStr op)(GVec4!T rhs)void opOpAssign(IStr op)(T rhs)T min()T max()A generic 2D rectangle.
bool hasSize()Self abs()GVec2!P topLeftPoint()GVec2!P topRightPoint()GVec2!P centerPoint()GVec2!P rightPoint()GVec2!P bottomLeftPoint()GVec2!P bottomPoint()Self centerArea()void fix()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)Handles the transition between two values over a specified duration.
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.Handles the transition between two boolean states.
float progressbool statebool 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.this(bool state)Creates a new toggle.Functions 141
T wrap(T)(T x, T a, T b)Returns `x` wrapped to the range [`a`, `b`], wrapping around when out of bounds.float fmod(float x, float y)double fmod64(double x, double y)float remainder(float x, float y)double remainder64(double x, double y)float exp(float x)double exp64(double x)float exp2(float x)double exp264(double x)float log(float x)double log64(double x)float log10(float x)double log1064(double x)float log2(float x)double log264(double x)float pow(float base, float exponent)double pow64(double base, double exponent)float atan2(float y, float x)double atan264(double y, double x)float roundNothing(float x)double roundNothing64(double x)float floorX(float x)double floorX64(double x)float floor(float x)double floor64(double x)float roundX(float x)double roundX64(double x)float round(float x)double round64(double x)float ceilX(float x)double ceilX64(double x)float ceil(float x)double ceil64(double x)float applyRounding(float x, Rounding type)double applyRounding64(double x, Rounding type)float sqrt(float x)double sqrt64(double x)float sin(float x)double sin64(double x)float cos(float x)double cos64(double x)float tan(float x)double tan64(double x)float asin(float x)double asin64(double x)float acos(float x)double acos64(double x)float atan(float x)double atan64(double x)float 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`.double 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`.float 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.double 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.float 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.double 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.float easeInOutCubic(float x)Easing function that accelerates then decelerates using a cubic curve.float easeOutQuint(float x)Easing function that starts fast and decelerates using a quintic curve.float easeInOutQuint(float x)Easing function that accelerates then decelerates using a quintic curve.float easeInOutCirc(float x)Easing function that accelerates then decelerates along a circular arc.float easeInElastic(float x)Easing function that overshoots the start with an elastic spring effect.float easeOutElastic(float x)Easing function that overshoots the end with an elastic spring effect.float easeInOutElastic(float x)Easing function that overshoots both ends with an elastic spring effect.float easeInQuad(float x)Easing function that starts slow and accelerates using a quadratic curve.float easeOutQuad(float x)Easing function that starts fast and decelerates using a quadratic curve.float easeInOutQuad(float x)Easing function that accelerates then decelerates using a quadratic curve.float easeOutQuart(float x)Easing function that starts fast and decelerates using a quartic curve.float easeInOutQuart(float x)Easing function that accelerates then decelerates using a quartic curve.float easeInOutBack(float x)Easing function that pulls back at the start and overshoots at the end.float easeInBounce(float x)Easing function that starts with a bouncing effect before reaching the target.float easeOutBounce(float x)Easing function that ends with a bouncing effect after reaching the target.bool fequals(float a, float b, float localEpsilon = epsilon)Returns true if `a` and `b` are within `localEpsilon` of each other.bool fequals64(double a, double b, double localEpsilon = epsilon)Returns true if `a` and `b` are within `localEpsilon` of each other.bool fequals(Vec2 a, Vec2 b, float localEpsilon = epsilon)Returns true if all components of `a` and `b` are within `localEpsilon` of each other.bool fequals(Vec3 a, Vec3 b, float localEpsilon = epsilon)Returns true if all components of `a` and `b` are within `localEpsilon` of each other.bool fequals(Vec4 a, Vec4 b, float localEpsilon = epsilon)Returns true if all components of `a` and `b` are within `localEpsilon` of each other.Vec4 toVec(Rgba color)Converts an `Rgba` color to a `Vec4` with components in the order `(r, g, b, a)`.IRect toIRect(Rect rect)Converts a `Rect` to an `IRect` by truncating position and size components to integers.Rgba toRgba(Vec3 vec)Converts a `Vec3` to an `Rgba` color, clamping each component to the range [0, 255] with full opacity.Rgba toRgba(Vec4 vec)Converts a `Vec4` to an `Rgba` color, clamping each component to the range [0, 255].Rgba toRgba(IStr str)Converts 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)Returns the linear interpolation between `from` and `to` by `weight`, applied per component.Vec3 lerp(Vec3 from, Vec3 to, float weight)Returns the linear interpolation between `from` and `to` by `weight`, applied per component.Vec4 lerp(Vec4 from, Vec4 to, float weight)Returns the linear interpolation between `from` and `to` by `weight`, applied per component.RoundingFunc rounding(Rounding type)Returns the rounding function corresponding to the given `Rounding` type.Rounding64Func rounding64(Rounding type)Returns the 64-bit rounding function corresponding to the given `Rounding` type.EasingFunc easing(Easing type)Returns the easing function corresponding to the given `Easing` type.float 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].float 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].float followState(ref float weight, bool target, float speed)Moves `weight` by ref toward the `target` state by `speed` and returns the updated value.double followState64(ref double weight, bool target, double speed)Moves `weight` by ref toward the `target` state by `speed` and returns the updated value.float moveTo(float from, float to, float delta)Moves `from` toward `to` by at most `delta`, stopping exactly at `to`.float moveTo64(double from, double to, double delta)Moves `from` toward `to` by at most `delta`, stopping exactly at `to`.Vec2 moveTo(Vec2 from, Vec2 to, Vec2 delta)Moves `from` toward `to` per component by at most `delta`, stopping exactly at `to`.Vec3 moveTo(Vec3 from, Vec3 to, Vec3 delta)Moves `from` toward `to` per component by at most `delta`, stopping exactly at `to`.Vec4 moveTo(Vec4 from, Vec4 to, Vec4 delta)Moves `from` toward `to` per component by at most `delta`, stopping exactly at `to`.float 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.float 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.Vec2 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.Vec3 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.Vec4 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
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()Not a color.
black = Rgba(0)Black black.
white = Rgba(255)White white.
red = Rgba(255, 0, 0)Red red.
green = Rgba(0, 255, 0)Green green.
blue = Rgba(0, 0, 255)Blue blue.
yellow = Rgba(255, 255, 0)Yellow yellow.
magenta = Rgba(255, 0, 255)Magenta magenta.
pink = Rgba(255, 192, 204)Pink pink.
cyan = Rgba(0, 255, 255)Cyan cyan.
orange = Rgba(255, 165, 0)Orange orange.
beige = Rgba(240, 235, 210)Beige beige.
brown = Rgba(165, 72, 42)Brown brown.
maroon = Rgba(128, 0, 0)Maroon maroon.
gray1 = Rgba(32, 32, 32)Gray 1.
gray2 = Rgba(96, 96, 96)Gray 22.
gray3 = Rgba(159, 159, 159)Gray 333.
gray4 = Rgba(223, 223, 223)Gray 4444.
gray = gray2Gray gray.