typed-geometry
Header-only strongly typed math library for graphics and geometry.
Usage / Example
Type definitions only, no functions:
#include <tg/typed-geometry.hh>
All functionality:
#include <tg/typed-geometry.hh>
tg::vec3 v;
tg::pos3 p;
// TODO
Most functionality is implemented as free functions, overloaded by type and with consistent vocabulary:
Vectors
Types vec3
, ivec4
, dvec2
, ...
-
normalize(a)
: returns normalized version ofa
-
dot(a, b)
: dot product -
cross(a, b)
: cross product - component-wise math functions:
sin
,cos
,abs
,sqrt
, ...
Transformations
- Matrix types
mat3
,imat3x4
, ... - Quaternion types
quat
,dquat
, ... - Transform types
transform3
,dtransform2
, ...
Objects
Types pos3
, iline2
, ray3
, dbox2
, ...
Represent individual points or sets of points.
-
contains(a, b)
: true iffa
containsb
(i.e. if each point inb
is also contained ina
) -
intersects(a, b)
: true iffa
andb
intersect (i.e. if at least one point is ina
and inb
) -
intersection(a, b)
: returns the appropriate object describing the intersection of two objects
Interpolation
-
mix(a, b, t)
: linearly interpolatesa
andb
with parametert
from 0..1. -
lerp(a, b, t)
: same asmix
-
slerp(a, b, t)
: same asmix
but with spherical interpolation (i.e. for quaternions) -
smoothstep(x0, x1, x)
: see GLSL smoothstep -
smootherstep(x0, x1, x)
: see GLSL smootherstep -
lmap(x, {x0_from, x1_from}, {x0_to, x1_to})
: linearly maps a value from one range to another
TODO: splines
Random
-
uniform(rng, a)
: uniformly samples a point from the objecta
-
uniform(rng, a, b)
: same asmix(a, b, uniform(t, 0.0f, 1.0f))
Naming Scheme
-
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)
)
Dependencies
None.
TODO
- Benchmark how compile times are affected by includes / templates
- Add tests that verify optimal assembly generated
- Fractional and bigint data types
- Deduction guides