|
stc
|
#include <cmath>#include <concepts>#include <stdexcept>Go to the source code of this file.
Namespaces | |
| namespace | stc |
| namespace | stc::math |
| namespace | stc::math::g2d |
Concepts | |
| concept | stc::math::VectorType2D |
| concept | stc::math::VectorType3D |
| concept | stc::math::SignedNumber |
Functions | |
| template<typename T > | |
| T | stc::math::square (const T &val) |
| template<typename IT , VectorType2D< IT > VT> | |
| bool | stc::math::g2d::isCounterClockwise (const VT &a, const VT &b, const VT &c) |
| template<SignedNumber IT, VectorType2D< IT > VT> | |
| IT | stc::math::g2d::isPointOnLeftOfEdge (const VT &point, const VT &lineStart, const VT &lineEnd) |
| template<typename IT , VectorType2D< IT > VT> requires std::equality_comparable_with<VT, VT> | |
| bool | stc::math::g2d::lineIntersectsLineInclusive (const VT &l1Start, const VT &l1End, const VT &l2Start, const VT &l2End) |
| template<typename IT , VectorType2D< IT > VT> | |
| bool | stc::math::g2d::lineIntersectsRectangleInclusive (const VT &lineStart, const VT &lineEnd, const VT &rectCornerA, const VT &rectCornerB, const VT &rectCornerC, const VT &rectCornerD) |
| template<SignedNumber IT, VectorType2D< IT > VT> | |
| bool | stc::math::g2d::rectangleContainsPointExclusive (const VT &point, const VT &rectCornerA, const VT &rectCornerB, const VT &rectCornerC, const VT &rectCornerD) |
| template<SignedNumber IT, VectorType2D< IT > VT> | |
| bool | stc::math::g2d::rectangleContainsPointInclusive (const VT &point, const VT &rectCornerA, const VT &rectCornerB, const VT &rectCornerC, const VT &rectCornerD) |
| template<typename IT , VectorType2D< IT > VT> | |
| bool | stc::math::g2d::rectangleContainsPointInclusive (const VT &point, const VT &startPosition, const VT &endPosition) |
| template<SignedNumber IT, VectorType2D< IT > VT> | |
| bool | stc::math::g2d::lineIntersectsRectangleInclusive (const VT &lineStart, const VT &lineEnd, const VT &rectStart, const VT &rectEnd) |
| template<SignedNumber IT, VectorType2D< IT > VT> | |
| bool | stc::math::g2d::lineIntersectsRectangleExclusive (const VT &lineStart, const VT &lineEnd, const VT &rectStart, const VT &rectEnd) |
This file contains mathematical extension functions. It relies on many built-in math functions; with the exception of a few functions explicitly designed to be fast or deal with type floatiness in built-in functions, these are extensions and not replacements.
Many functions in this library reference an arbitrary vector type (VectorType2D, VectorType3D, ...). This library does not provide a vector implementation; it's assumed you bring your own. Non-vector variants may be added in the future if there's interest in them, but as my use primarily covers use-cases where a vector is involved, I don't plan to implement it in the foreseeable future.
If you don't have one, and don't feel like doing it, I can strongly recommend glm: https://github.com/g-truc/glm However, the requirements for the vectors are minimised. The main requirement is that you have an x/y/z property (depending on the dimensionality), and offer an operator==. This is a bare minimum 2D vector that passes these requirements:
Vectors can be of any numeric type, both integers and floats. If you use a float, the usual floating point math caveats apply. Behaviour is often undefined for unsigned vectors; though they're technically legal, subtraction is performed that may be unsafe with certain combinations of unsigned vectors. It's strongly recommended you use a signed type.