How ericlengyel/terathon-math-library works
1. This repository is a C++ numerical/geometry library, not an application. Its architecture is centered on reusable value types for linear algebra and projective geometric algebra, exposed primarily through headers and supported by a small set of .cpp translation units.
2. The lowest layer is the platform and SIMD foundation: TSPlatform.h and TSSimd.h likely encapsulate compiler/OS/CPU feature differences and vectorized math support. TSMath.h/.cpp sits above that as the common scalar math utility layer used by all higher-level types.
3. The core linear algebra subsystem consists of vectors and matrices: TSVector2D/3D/4D, TSMatrix2D/3D/4D, and TSQuaternion. These are the basic data carriers and are the substrate for almost every other type in the library.
4. There is a separate scalar extension type, TSDualNum.h, which supports dual-number arithmetic. It is part of the math foundation and likely feeds specialized geometric or derivative-style computations.
5. The TSBivector3D type provides a bridge between conventional vector math and geometric algebra. It sits close to the algebraic layer rather than the pure matrix/vector layer.
6. The library is organized into several geometric-algebra domains:
- rigid 2D: TSRigid2D, TSMotor2D, TSFlector2D
- rigid 3D: TSRigid3D, TSMotor3D, TSFlector3D
- conformal 2D: TSConformal2D
- conformal 3D: TSConformal3D
These types represent specialized multivectors and transformations for motion, reflection, and conformal primitives.
7. The README describes the main data flow: primitives such as points, lines, planes, circles, spheres, motors, and flectors are manipulated algebraically and transformed through dedicated Transform() functions rather than through generic geometric-product operators. That suggests the API favors efficient, type-specific operations over constructing intermediate multivectors.
8. The matrix/vector types also expose “swizzling” and subobject extraction as expression-level views. This is an architectural boundary worth drawing: component access, row/column access, transpose, and submatrix selection are intended to be free or near-free operations when used in expressions.
9. The codebase is split into headers and implementation files in a way that suggests most functionality is inline/template-friendly, with .cpp files used for out-of-line definitions, shared routines, or to reduce compile cost for larger operator sets.
10. There are two distinct geometry families in the public API:
- conventional Euclidean math: vectors, matrices, quaternions
- projective/conformal geometric algebra: motors, flectors, flat points, lines, planes, circles, spheres
This is the most important conceptual boundary for an architecture diagram.
11. The library appears self-contained: there are no application entry points, services, storage systems, or external runtime dependencies. The only notable build-time variability called out in the README is the TERATHON_SWIZZLE_REPEAT define, which affects compile-time surface area and API behavior.
12. For diagramming, the best high-level structure is: platform/SIMD and math utilities at the base; linear algebra primitives in the middle; then rigid and conformal geometric-algebra modules layered on top, all sharing the same underlying vector/matrix/scalar infrastructure.
Main entry points: TSMath.h Math · TSAlgebra.h Algebra · TSConformal2D.h Conformal 2D · TSConformal3D.h Conformal 3D
Components 21
Foundation
Platform, SIMD, and scalar math support.
- Platform · Compiler and CPU portability layer.
TSPlatform.h - SIMD · SIMD abstraction and vectorized math support.
TSSimd.h - Math · Common scalar math utilities shared by the library.
TSMath.h - Dual Num · Dual-number arithmetic extension for specialized computations.
TSDualNum.h - Algebra · Umbrella algebra layer that ties the library together.
TSAlgebra.h
Euclidean
Core vector, matrix, and quaternion primitives.
- Vector2D · 2D vector value type and operations.
TSVector2D.h - Vector3D · 3D vector value type and operations.
TSVector3D.h - Vector4D · 4D vector value type and operations.
TSVector4D.h - Matrix2D · 2D matrix type with row, column, and subobject views.
TSMatrix2D.h - Matrix3D · 3D matrix type with row, column, and subobject views.
TSMatrix3D.h - Matrix4D · 4D matrix type with row, column, and subobject views.
TSMatrix4D.h - Quaternion · Quaternion rotation and orientation type.
TSQuaternion.h - Bivector3D · Bridge between vector math and geometric algebra.
TSBivector3D.h
Rigid 2D
2D rigid-motion geometric algebra.
Rigid 3D
3D rigid-motion geometric algebra.
Conformal
2D and 3D conformal geometric algebra.
- Conformal 2D · 2D conformal geometric algebra and primitives.
TSConformal2D.h - Conformal 3D · 3D conformal geometric algebra and primitives.
TSConformal3D.h
Connections 29
- Platform → SIMD: basis · SIMD builds on platform-specific feature handling.
- SIMD → Math: accelerates · Vectorized support underpins common math routines.
- Math → Dual Num: extends · Dual numbers reuse the scalar math foundation.
- Math → Vector2D: supports · Scalar utilities feed vector arithmetic.
- Math → Vector3D: supports · Scalar utilities feed vector arithmetic.
- Math → Vector4D: supports · Scalar utilities feed vector arithmetic.
- Math → Matrix2D: supports · Scalar utilities feed matrix arithmetic.
- Math → Matrix3D: supports · Scalar utilities feed matrix arithmetic.
- Math → Matrix4D: supports · Scalar utilities feed matrix arithmetic.
- Vector2D → Matrix2D: feeds · 2D vectors and 2x2 matrices form the base Euclidean layer.
- Vector3D → Matrix3D: feeds · 3D vectors and 3x3 matrices form the base Euclidean layer.
- Vector4D → Matrix4D: feeds · 4D vectors and 4x4 matrices form the base Euclidean layer.
- Matrix3D → Quaternion: supports · Matrix and quaternion rotation types are closely related.
- Vector3D → Bivector3D: bridges · Bivector3D connects conventional vector math to GA.
- Algebra → Bivector3D: includes · The algebra layer exposes the bivector bridge.
- Algebra → Rigid 2D: includes · Core algebra namespace exposes the 2D rigid domain.
- Algebra → Rigid 3D: includes · Core algebra namespace exposes the 3D rigid domain.
- Algebra → Conformal 2D: includes · Core algebra namespace exposes the 2D conformal domain.
- Algebra → Conformal 3D: includes · Core algebra namespace exposes the 3D conformal domain.
- Rigid 2D → Motor2D: specializes · 2D motors implement rigid motion.
- Rigid 2D → Flector2D: specializes · 2D flectors implement reflection-based transforms.
- Rigid 3D → Motor3D: specializes · 3D motors implement rigid motion.
- Rigid 3D → Flector3D: specializes · 3D flectors implement reflection-based transforms.
- Conformal 2D → Motor2D: reuses · Conformal 2D builds on the rigid-motion primitives.
- Conformal 3D → Motor3D: reuses · Conformal 3D builds on the rigid-motion primitives.
- Conformal 2D → Dual Num: leverages · Conformal computations can use dual-number support.
- Conformal 3D → Dual Num: leverages · Conformal computations can use dual-number support.
- Conformal 2D → Vector2D: represents · 2D conformal primitives rest on Euclidean vector types.
- Conformal 3D → Vector3D: represents · 3D conformal primitives rest on Euclidean vector types.