Jackalope / jmath (public) (License: GPLv3 or later) (since 2018-10-11) (hash sha1)
C++ conxstexpr template Math library with:
- multidimensional vectors and matrices
- geometry primitives with projection, distance and intersection functions
- coordinate systems conversions
- some routines

Depends on GCE-math C++ library as git submodule.

Used with clang (version 9 or 10) and gcc (version 9).
Written with C++17.
List of commits:
Subject Hash Author Date (UTC)
GCC compatibility. 1225bb2c0d6f2b44ae65e1ca54b87f036c75d919 Jackalope 2020-05-29 15:53:38
removed excess template e1d8066084bfcc83e9b9a06513324d50c1968dba Jackalope 2020-05-25 01:46:37
more typedefs for vector dd05bec6f1da79751e46ac95f8196f7fe11a1c7e Jackalope 2020-05-21 11:50:27
Changed cmake library interface, gcem included properly 7e660bcdd283cc7d9203b0e03a2a5c2d7ee44829 Jackalope 2020-05-12 06:59:38
refactoring with name change to jmath, jm namespace, added license dda67de093198e66c57cbb10857c968e4382ac30 Jackalope 2020-05-09 19:07:42
replaced std min and max with math functions 0cbb0dfdbb9c3364361d27e25f70450f802518f3 Jackalope 2020-02-11 13:48:59
function number is template to prevent warnings 761fea461d2b6178c35385d63c4005eb708b2c6c Jackalope 2020-02-05 15:53:17
removed excess includes 88bc9c2f36118412a784907c91997f992825cb0e Jackalope 2020-02-05 12:18:17
changed vector to plane argument in plane distance 498b8412af406915b03f7cfa36228ae946c15baa jp.larry 2020-01-14 17:12:59
new line definitions and correct circle polygon intersection ffdc291cc19b8edcea2a33f06306dcc628d3535c jp.larry 2020-01-14 16:08:58
vector length_p2 function 8e59b70fef912432e5b9ce2299274b3d953c3116 jp.larry 2020-01-14 16:08:07
vector_base refactoring and distance,intersection functions moved to geometry header d8473eef6419504fbcc130fb1ce1f59032503a42 jp.larry 2020-01-14 00:41:30
functions to check if line out of range f54afa1443012f918cdf16483e7fb36021d1d465 jp.larry 2020-01-11 20:39:29
clusters depth slices and depth convertions a0d15a75baa2bdeef9c033c19ded7424ab29da1a jp.larry 2020-01-10 12:06:17
plane struct inherited from vector of size 4 with normal and offset 74331763aa73548b17ff91aab0d6abaa6fa0e7d8 jp.larry 2020-01-10 10:29:04
changed identation c815eb8588c6229bbf56606446e76b0a75553eee jp.larry 2020-01-10 10:28:20
sqrt function 856c393e7ba60f99bd18e524ef408f427e04fa1c jp.larry 2020-01-10 10:27:55
removed unused matrix files 1bc1e845a6a391cce90be9023fae41937dbd100d jp.larry 2020-01-07 13:55:53
frustum data type 48480173a43561e7502458579378b78591716d1c jp.larry 2020-01-07 13:53:57
different projection matrix built functions for different fov specifications (horizontal, vertical, both) 0aa5dbb5e22c616a559bb6f6d75b0313db7b3e84 jp.larry 2020-01-07 13:53:30
Commit 1225bb2c0d6f2b44ae65e1ca54b87f036c75d919 - GCC compatibility.
Author: Jackalope
Author date (UTC): 2020-05-29 15:53
Committer name: Jackalope
Committer date (UTC): 2020-05-29 15:53
Parent(s): e1d8066084bfcc83e9b9a06513324d50c1968dba
Signing key:
Tree: a2a9d61bc1f490a7e51da33a8e39077ff4b5845b
File Lines added Lines deleted
include/jmath/constants.h 4 1
include/jmath/geometry.h 1 1
include/jmath/matrix/base.h 53 35
include/jmath/matrix/base.hpp 54 58
File include/jmath/constants.h changed (mode: 100644) (index bb4f0fd..812e8aa)
18 18 #pragma once #pragma once
19 19 #include <type_traits> #include <type_traits>
20 20 #include <cstdint> #include <cstdint>
21
21 #ifdef __clang__
22 22 #pragma clang diagnostic push #pragma clang diagnostic push
23 23 #pragma clang diagnostic ignored "-Weverything" #pragma clang diagnostic ignored "-Weverything"
24 24 #include <gcem.hpp> #include <gcem.hpp>
25 25 #pragma clang diagnostic pop #pragma clang diagnostic pop
26 #else
27 #include <gcem.hpp>
28 #endif
26 29
27 30 namespace jm namespace jm
28 31 { {
File include/jmath/geometry.h changed (mode: 100644) (index c402af9..26634f2)
... ... namespace jm
74 74 template<typename T> using circle = hypersphere<2,T>; template<typename T> using circle = hypersphere<2,T>;
75 75 template<typename T> struct circle_in3D { template<typename T> struct circle_in3D {
76 76 hypersphere<3,T> circle; hypersphere<3,T> circle;
77 plane<T> plane;
77 jm::plane<T> plane;
78 78 }; };
79 79
80 80 template<int VCOUNT, int D, typename T> using polygon = vector<D,T>[VCOUNT]; template<int VCOUNT, int D, typename T> using polygon = vector<D,T>[VCOUNT];
File include/jmath/matrix/base.h changed (mode: 100644) (index beed3be..d2363c0)
17 17 */ */
18 18 #pragma once #pragma once
19 19 #include "../vector/base.h" #include "../vector/base.h"
20 #include <type_traits>
21
22 #define T_NUMERIC template<typename numeric_t> constexpr
23 #define T_OTHER template<typename other_t> constexpr
24 20
25 21 namespace jm { namespace jm {
26 template<int size, int vector_size, typename type> struct matrix;
22 template<int size, int vector_size, typename T> struct matrix;
27 23 } }
28 24 //TODO make initialization without excess braces //TODO make initialization without excess braces
29 template<int size, int vector_size, typename type>
25 template<int size, int vector_size, typename T>
30 26 struct jm::matrix struct jm::matrix
31 27 { {
32 using vector = vector<vector_size, type>;
33 vector _[size];
28 vector<vector_size, T> _[size];
34 29
35 template<int other_size, int other_vector_size, typename other_t>
36 [[nodiscard]] constexpr inline static matrix
37 from(const matrix<other_size, other_vector_size, other_t> &);
30 template<int size2, int vsize2, typename T2> [[nodiscard]] constexpr static
31 matrix from(const matrix<size2, vsize2, T2> &);
38 32
39 T_OTHER operator matrix<size, vector_size, other_t> () {
40 return matrix<size, vector_size, other_t>::from(*this);
33 template<typename T2> constexpr
34 operator matrix<size, vector_size, T2> () {
35 return matrix<size, vector_size, T2>::from(*this);
41 36 } }
42 37
43 [[nodiscard]] constexpr bool operator==(const matrix &other) {
38 [[nodiscard]] constexpr
39 bool operator==(const matrix &other) {
44 40 return memcmp(this, &other, sizeof(*this)) == 0; return memcmp(this, &other, sizeof(*this)) == 0;
45 41 } }
46 constexpr inline bool operator!=(const matrix &m) { return *this != m; }
47
48 T_NUMERIC vector& operator[](numeric_t i) { return _[i]; }
49 T_NUMERIC vector operator[](numeric_t i) const { return _[i]; }
42 constexpr
43 bool operator!=(const matrix &m) {
44 return *this != m;
45 }
50 46
51 template<int other_size, int other_vector_size, typename other_t>
52 constexpr inline matrix&
53 operator *= (const matrix<other_size, other_vector_size, other_t>&);
47 template<typename N> [[nodiscard]] constexpr
48 vector<vector_size, T>& operator[](N i) {
49 return _[i];
50 }
51 template<typename N> [[nodiscard]] constexpr
52 vector<vector_size, T> operator[](N i) const {
53 return _[i];
54 }
54 55
55 template<int other_size, int other_vector_size, typename other_t>
56 constexpr inline matrix<size, other_vector_size, type>
57 operator *(const matrix<other_size, other_vector_size, other_t>&) const;
56 template<int size2, int vsize2, typename T2> constexpr
57 matrix& operator *= (const matrix<size2, vsize2, T2>&);
58 template<int size2, int vsize2, typename T2> [[nodiscard]] constexpr
59 matrix<size, vsize2, T> operator *(const matrix<size2, vsize2, T2>&) const;
58 60
59 template<typename other_t> [[nodiscard]] constexpr inline
60 vector operator *(const jm::vector<size, other_t>&) const;
61 template<typename T2> [[nodiscard]] constexpr
62 vector<vector_size, T>
63 operator *(const jm::vector<size, T2>&) const;
61 64
62 T_NUMERIC matrix& operator += (const numeric_t&);
63 T_NUMERIC matrix& operator -= (const numeric_t&);
64 T_NUMERIC matrix& operator /= (const numeric_t&);
65 T_NUMERIC matrix operator + (const numeric_t&n) const {return *this += n;}
66 T_NUMERIC matrix operator - (const numeric_t&n) const {return *this -= n;}
67 T_NUMERIC matrix operator / (const numeric_t&n) const {return *this /= n;}
65 template<typename N> constexpr
66 matrix&
67 operator += (const N&);
68 template<typename N> constexpr
69 matrix&
70 operator -= (const N&);
71 template<typename N> constexpr
72 matrix&
73 operator /= (const N&);
74 template<typename N> [[nodiscard]] constexpr
75 matrix
76 operator + (const N&n) const {
77 return *this += n;
78 }
79 template<typename N> [[nodiscard]] constexpr
80 matrix
81 operator - (const N&n) const {
82 return *this -= n;
83 }
84 template<typename N> [[nodiscard]] constexpr
85 matrix
86 operator / (const N&n) const {
87 return *this /= n;
88 }
68 89 }; };
69
70 #undef T_NUMERIC
71 #undef T_OTHER
File include/jmath/matrix/base.hpp changed (mode: 100644) (index 4c8a00b..170e592)
17 17 */ */
18 18 #pragma once #pragma once
19 19 #include "base.h" #include "base.h"
20 #include <cmath>
21 20
22 #define MATR_T \
23 template<int size, int vector_size, typename type>
24 #define T_OTHER_OTHER_IMP \
25 template<int size, int vector_size, typename type> \
26 template<int other_size, int other_vector_size, typename other_t> constexpr
27 #define T_NUMERIC_IMPL \
28 template<int size, int vector_size, typename type> \
29 template<typename numeric_t> constexpr
30 #define MATRIX \
31 jm::matrix<size, vector_size, type>
32 #define MATRIX_OTHER_OTHER \
33 jm::matrix<other_size, other_vector_size, other_t>
34
35 T_OTHER_OTHER_IMP MATRIX MATRIX::from(const MATRIX_OTHER_OTHER &other) {
36 MATRIX m{}; int i = 0, j = 0;
37 for (; i < size && i < other_size; ++i) {
38 for (j = 0; j < vector_size && j < other_vector_size; ++j)
39 m._[i][j] = type(other._[i][j]);
40 for (; j < vector_size; ++j)
41 m._[i][j] = type(0);
21 template<int S, int VS, typename T>
22 template<int S2, int VS2, typename T2> constexpr
23 jm::matrix<S, VS, T>
24 jm::matrix<S, VS, T>::from(const jm::matrix<S2, VS2, T2> &other) {
25 jm::matrix<S, VS, T> m{}; int i = 0, j = 0;
26 for (; i < S && i < S2; ++i) {
27 for (j = 0; j < VS && j < VS2; ++j)
28 m._[i][j] = T(other._[i][j]);
29 for (; j < VS; ++j)
30 m._[i][j] = T(0);
42 31 } }
43 for (; i < size; ++i)
44 for (; j < vector_size; ++j)
45 m._[i][j] = type(0);
32 for (; i < S; ++i)
33 for (; j < VS; ++j)
34 m._[i][j] = T(0);
46 35 return m; return m;
47 36 } }
48 MATR_T template<int other_size, int other_vector_size, typename other_t>
49 constexpr inline MATRIX&
50 MATRIX::operator*=(const matrix<other_size, other_vector_size, other_t>& m) {
51 static_assert(other_vector_size == vector_size);
52 return *this = (*this) * m;
53 }
54 MATR_T template<int other_size, int other_vector_size, typename other_t>
55 [[nodiscard]] constexpr jm::matrix<size, other_vector_size, type>
56 MATRIX::operator*(const matrix<other_size, other_vector_size, other_t>& other)
57 const {
58 static_assert(other_size == vector_size);
59 matrix<size, other_vector_size, type> m {};
60 for(int i = 0; i < size; i++)
61 for(int k = 0; k < vector_size; k++)
62 for(int j = 0; j < other_vector_size; j++)
37
38 template<int S, int VS, typename T>
39 template<int S2, int VS2, typename T2> [[nodiscard]] constexpr
40 jm::matrix<S, VS2, T>
41 jm::matrix<S, VS, T>::operator*(const matrix<S2, VS2, T2>& other) const {
42 static_assert(S2 == VS);
43 matrix<S, VS2, T> m {};
44 for(int i = 0; i < S; i++)
45 for(int k = 0; k < VS; k++)
46 for(int j = 0; j < VS2; j++)
63 47 m._[i][j] += _[i][k] * other._[k][j]; m._[i][j] += _[i][k] * other._[k][j];
64 48 return m; return m;
65 49 } }
66 MATR_T template<typename other_t>
67 [[nodiscard]] constexpr inline typename MATRIX::vector
68 MATRIX::operator *(const jm::vector<size, other_t>& vec) const
69 {
70 MATRIX::vector v{};
71 for(int i = 0; i < size; i++)
72 for(int k = 0; k < vector_size; k++)
50 template<int S, int VS, typename T>
51 template<int S2, int VS2, typename T2> constexpr
52 jm::matrix<S, VS, T>&
53 jm::matrix<S, VS, T>::operator*=(const matrix<S2, VS2, T2>& m) {
54 static_assert(VS2 == VS);
55 return *this = (*this) * m;
56 }
57
58 template<int S, int VS, typename T>
59 template<typename T2> [[nodiscard]] constexpr
60 jm::vector<VS, T>
61 jm::matrix<S, VS, T>::operator *(const jm::vector<S, T2>& vec) const {
62 vector<VS, T> v{};
63 for(int i = 0; i < S; i++)
64 for(int k = 0; k < VS; k++)
73 65 v[i] += (*this)[i][k] * vec[k]; v[i] += (*this)[i][k] * vec[k];
74 66 return v; return v;
75 67 } }
76 T_NUMERIC_IMPL MATRIX& MATRIX::operator += (const numeric_t& value) {
77 for (int i = 0; i < size; ++i)
68
69 template<int S, int VS, typename T>
70 template<typename N> constexpr
71 jm::matrix<S, VS, T>&
72 jm::matrix<S, VS, T>::operator += (const N& value) {
73 for (int i = 0; i < S; ++i)
78 74 (*this)[i] += value; (*this)[i] += value;
79 75 return *this; return *this;
80 76 } }
81 T_NUMERIC_IMPL MATRIX& MATRIX::operator -= (const numeric_t& value) {
82 for (int i = 0; i < size; ++i)
77 template<int S, int VS, typename T>
78 template<typename N> constexpr
79 jm::matrix<S, VS, T>&
80 jm::matrix<S, VS, T>::operator -= (const N& value) {
81 for (int i = 0; i < S; ++i)
83 82 (*this)[i] -= value; (*this)[i] -= value;
84 83 return *this; return *this;
85 84 } }
86 T_NUMERIC_IMPL MATRIX& MATRIX::operator /= (const numeric_t& value) {
87 for (int i = 0; i < size; ++i)
85 template<int S, int VS, typename T>
86 template<typename N> constexpr
87 jm::matrix<S, VS, T>&
88 jm::matrix<S, VS, T>::operator /= (const N& value) {
89 for (int i = 0; i < S; ++i)
88 90 (*this)[i] /= value; (*this)[i] /= value;
89 91 return *this; return *this;
90 92 } }
91
92 #undef MATRIX_OTHER_OTHER
93 #undef T_OTHER_OTHER_IMP
94 #undef T_NUMERIC_IMPL
95 #undef MATRIX
96 #undef MATRIX_OTHER
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/Jackalope/jmath

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/Jackalope/jmath

Clone this repository using git:
git clone git://git.rocketgit.com/user/Jackalope/jmath

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main