Header-only strongly typed math library for graphics and geometry.
Type definitions only, no functions:
#include <typed-geometry/tg-lean.hh>
All functionality:
#include <typed-geometry/tg.hh>
tg::vec3 v;
tg::pos3 p;
// TODO
Helpers for interacting with the standard library:
#include <typed-geometry/tg-std.hh>
tg::pos3 p;
std::cout << p; // std::operator<<(std::ostream&, ...)
std::map<p, int> v_cnts; // std::less
std::unordered_map<p, int> v_cnts; // std::hash
Most functionality is implemented as free functions, overloaded by type and with consistent vocabulary.
Basically all tg provided types are regular, i.e. have value semantics like int or vector.
The following categories exist:
- POD types like
vecand most fixed-size objects - dynamically sized non-POD values like
polygon(similar tovector) - transparent types like
vecwhere.xis part of the interface - opaque types like
angleandquadricwhere the representation is implementation detail
Types vec3, ivec4, dvec2, ...
normalize(a): returns normalized version ofadot(a, b): dot productcross(a, b): cross product- component-wise math functions:
sin,cos,abs,sqrt, ...
- Matrix types
mat3,imat3x4, ... - Quaternion types
quat,dquat, ... - Transform types
transform3,dtransform2, ...
Types pos3, iline2, ray3, dbox2, ...
Represent individual points or sets of points.
contains(a, b): true iffacontainsb(i.e. if each point inbis also contained ina)intersects(a, b): true iffaandbintersect (i.e. if at least one point is inaand inb)intersection(a, b): returns the appropriate object describing the intersection of two objects
See docs/Objects.md for more information.
mix(a, b, t): linearly interpolatesaandbwith parametertfrom 0..1.lerp(a, b, t): same asmixslerp(a, b, t): same asmixbut with spherical interpolation (i.e. for quaternions)smoothstep(x0, x1, x): see GLSL smoothstepsmootherstep(x0, x1, x): see GLSL smoothersteplmap(x, {x0_from, x1_from}, {x0_to, x1_to}): linearly maps a value from one range to another
TODO: splines
tg::rng rng;
auto v = uniform(rng, -1.0f, 1.0f);
auto p = uniform(rng, obj);
uniform(rng, a): uniformly samples a point from the objectauniform(rng, a, b): same asmix(a, b, uniform(t, 0.0f, 1.0f))
foo(a, b)should read in the same order as english- if not possible,
a.foo(b)should make sense (e.g.contains(a, b)is interpreted asa.contains(b)) - if still ambiguous: faster changing parameters go last (e.g.
coordinates(tri, point)ormix(a, b, t))
- deduction guides:
auto v = tg::vec(1, 2.5f, 3),auto p = tg::pos(v); - structured binding:
auto [x, y, z] = tg::vec3(...)
clean-core.
- Benchmark how compile times are affected by includes / templates
- Add tests that verify optimal assembly generated
- Fractional and bigint data types