godot-math 0.0.3
Port of Godot vectors, matrices, quaternions, rectangles
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
godot-math
godot-math is a D port of Godot's linear algebra with unchanged semantics.
➡️ See Godot Math documentation
"dependencies":
{
"godot-math": "~>1.0"
}
dependency "godot-math" version="~>1.0"
Why?
Godot's math bring helpful semantics to small vectors and matrices.
A Transform2D/Transform3D is scaling + translation + rotation without shearing.
A Projection is a 4x4 matrix scaling with potentially perspective transform.
A Basis is a 3x3 matrix that only deals with base change / rotation.
Features
- one .d file
- Everything is fully
pure nothrow @nogc @safe. - LDC, GDC, DMD
| Type | Status | Description | Documentation |
|---|---|---|---|
| Vector2 | ✅ | 2D float vector, or size, or point | Vector2 |
| Vector3 | ✅ | 3D float vector, or size, or point | Vector3 |
| Vector4 | ✅ | 4D float vector or point | Vector4 |
| Vector2i | ✅ | 2D int vector, or size, or point | Vector2i |
| Vector3i | ✅ | 3D int vector, or size, or point | Vector3i |
| Vector4i | ✅ | 4D int vector or point | Vector4i |
| Rect2 | ✅ | 2D float rectangle | Rect2 |
| Rect2i | ✅ | 2D int rectangle | Rect2i |
| Transform2D | ✅ | 2x3 matrix | Transform2D |
| Basis | ✅ | 3x3 matrix | Basis |
| Transform3D | ✅ | 3x4 matrix | Transform3D |
| Projection | ✅ | 4x4 matrix | Projection |
| Plane | ❌ | 3D Plane matrix | Plane |
| AABB | ❌ | 3D bounding box | AABB |
Math functions
Note: When a float function exist, a double overload also exist with identical name.
float gm_abs(float x);
int gm_abs(int x);
float gm_acos(float x);
float gm_acosh(float x);
float gm_angle_difference(float from, float to);
float gm_asin(float x);
float gm_asinh(float x);
float gm_atan(float x);
float gm_atan2(float y, float x);
float gm_bezier_derivative(float start, float control_1, float control_2, float end, float t);
float gm_bezier_interpolate(float start, float control_1, float control_2, float end, float t);
float gm_ceil(float x);
float gm_clamp(float value, float min, float max);
int gm_clamp(int value, int min, int max);
float gm_cos(float x);
float gm_cubic_interpolate(float from, float to, float pre, float post, float weight);
float gm_cubic_interpolate_in_time(float from, float to, float pre, float post, float weight, float to_t, float pre_t, float post_t);
float gm_deg_to_rad(float y);
float gm_floor(float x);
float gm_fmod(float x, float y);
float gm_fposmod(float x, float y);
bool gm_is_equal_approx(float left, float right);
bool gm_is_equal_approx(float left, float right, float tolerance);
bool gm_is_finite(float x);
bool gm_is_zero_approx(float value);
float gm_lerp(float from, float to, float weight);
float gm_lerp_angle(float from, float to, float weight);
bool gm_likely(bool b);
bool gm_unlikely(bool b);
float gm_rad_to_deg(float y);
float gm_round(float x);
int gm_sign(int v);
float gm_sign(float v);
bool gm_signbit(float num);
bool gm_signbit(double num);
float gm_sin(float x);
float gm_snapped(float value, float step);
int gm_snapped(int value, int step);
float gm_sqrt(float x);
void gm_swap(T)(ref T a, ref T b);
float gm_tan(float x);
Differing names
- Both
floatanddoubleversions exist at once, with a***dsuffix (eg:Projectiond,Vector2d,Rect2d). - In global scope, function symbols get a
gm_prefix. - For vectors:
.clampf/.clampireplaced by overloaded.clamp.snappedf/.snappedireplaced by overloaded.snapped..minf/.minireplaced by overloaded.min.maxf/.maxireplaced by overloaded.max
Small semantic differences
Rect2/Rect2i/Rect2dhave a.merge_non_emptymethod that, in case of a union with an empty rectangle, return the other rectangle.- Bonus methods for rectangles, such has
.left,.top,.right,.bottom,.scale. Projectioninverse is less precise than in original Godot. You can always go double to get more precise.inverse()
- 0.0.3 released 17 days ago
- AuburnSounds/godot-math
- MIT
- Copyright 2025, Guillaume Piolat
- Authors:
- Dependencies:
- numem
- Versions:
-
Show all 6 versions0.0.5 2026-Jan-06 0.0.4 2026-Jan-04 0.0.3 2026-Jan-03 0.0.2 2026-Jan-03 0.0.1 2026-Jan-02 - Download Stats:
-
-
6 downloads today
-
54 downloads this week
-
191 downloads this month
-
191 downloads total
-
- Score:
- 1.8
- Short URL:
- godot-math.dub.pm