Skip to content

shBLOCK/spatium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 Cannot retrieve latest commit at this time.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GdMath: a lightning fast spatial math library for gamedev

Codegen Tests Release

Main features

  • Fast Pure Cython Implementation
    • ~20x speedup from pure python(3.12) impl on average
    • Based on custom code generation
  • Spatial Math
    • Vector
      • Operators +, -, *, /, @(dot), ^(cross), |(distance) ...
      • Fast (compile time) swizzling (e.g. Vec3(1, 2, 3).zxy)
      • Flexible constructor (e.g. Vec3(Vec2(1, 2), 3))
      • Iterating and unpacking (e.g. x, y, z = Vec3(1, 2, 3))
      • Works with other libraries (pygame, numpy, ...)
    • Transform
  • All floats are double-precision
  • Full pythonic interface & GLSL-like API
  • Stubs for better IDE support

Please refer to the wiki for more details

Benchmark

Benchmark Results

Implementation details

  • Codegen!
    Custom code generation is used throughout this library.
    Every swizzle pattern and constructor are implemented as individual methods and properties (For performance reasons).
    As a result, code generation is required so that I don't have to maintain 50,000+ lines of code by hand...
    Besides, it also handles vector classes of every dimension and type (e.g. Vec2 Vec3 Vec2i Vec3i) are generated from the same template, so a lot of repetitive code is avoided. There's also a stub generator.

Notes

  • This library was initially inspired by Godot's math library. Pun intended :)