Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
12ed7b5
feat: add basic Vector3d functionality
ape33 Jun 26, 2026
9619201
fix: header guard macro
ape33 Jun 26, 2026
fc1c715
ci: rename .tpp.hpp files to .tpp
ape33 Jun 29, 2026
d50a9ba
internal: update Vector3d constructors
ape33 Jun 29, 2026
05b5c45
feat: add binary operator overloads for Vector3d
ape33 Jun 29, 2026
4e34642
internal: update .clangd
ape33 Jun 29, 2026
511ff2c
feat: add binary operator overloads for Vector3d
ape33 Jul 2, 2026
abae3c5
feat: add unary +/- operator and != operator overloads for Vector3d
ape33 Jul 2, 2026
903145b
feat: add unit conversion functions in() and force_in() for Vector3d
ape33 Jul 2, 2026
ef94829
feat: add unit conversion functions numerical_value_in() and force_nu…
ape33 Jul 3, 2026
3e59a30
feat: add norm functions for Vector3d
ape33 Jul 3, 2026
53373d8
refactor: Vector3d unit test into two files with and without mp-units
ape33 Jul 8, 2026
ef0bf2a
refactor: Vector3d comparison operators requires clauses
ape33 Jul 8, 2026
4e7e6e2
refactor: Vector3d binary "+" operator
ape33 Jul 8, 2026
97d1c89
refactor: consider nested Vector3d of same depth and disallow scalar …
ape33 Jul 9, 2026
160abf6
test: add tests for unary +/- for nested Vector3d
ape33 Jul 9, 2026
fc440a1
test: add tests for Vector3d indexing operator
ape33 Jul 9, 2026
9961138
test: add tests for Vector3d constructors
ape33 Jul 9, 2026
05c76e6
test: add tests for Vector3d ostream << operator
ape33 Jul 9, 2026
0487c12
refactor: update requires expression for Vector3d norm function
ape33 Jul 9, 2026
3d686cf
style: remove redundant IWYU pragma
ape33 Aug 6, 2026
dfce8e4
fix: cppcheck warning about unitialized member variable in Vector3d c…
ape33 Aug 6, 2026
11bed29
Merge: branch 'dev' into feat/linalg
ape33 Aug 6, 2026
0494146
style: remove "noexcept" qualifiers from Vector3d class functions
ape33 Aug 6, 2026
fa08e0e
feat: add Vector3d += and -= operators
ape33 Aug 6, 2026
a8703d0
test: add tests for += and -= Vector3d with mp-units
ape33 Aug 6, 2026
65b18cf
feat: add Vector3d *= and /= operators
ape33 Aug 6, 2026
27eaaeb
feat: add Vector3d static_cast
ape33 Aug 7, 2026
7747ef1
feat: add Vector3d dot and cross product functions
ape33 Aug 7, 2026
cd7ba03
feat: add Vector3d normalize function
ape33 Aug 7, 2026
3829e42
feat: add Vector3d normalize in-place function
ape33 Aug 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .clangd
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
CompileFlags:
CompilationDatabase: .build
CompilationDatabase: .build
Add:
- -Wno-c2y-extensions
- -Wno-double-promotion

Diagnostics:
Suppress:
- c2y-extensions
- -Wc2y-extensions
- typecheck_expression_not_modifiable_lvalue
- pp_including_mainfile_in_preamble
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"-i ${workspaceFolder}/external/Catch2/src" // adjust path as needed
],
"files.associations": {
"*.tpp": "c++",
"*.tpp": "cpp",
"type_traits": "cpp",
"functional": "cpp",
"array": "cpp",
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

## Next Release

### Feature

- add static Vector3d with mp-units support

<!-- insertion marker -->
## [0.1.4](https://github.com/repo/owner/releases/tag/0.1.4) - 2026-07-26

Expand Down
45 changes: 45 additions & 0 deletions include/mstd/linAlg/concepts/vector3dConcepts.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*****************************************************************************
<GPL_HEADER>

mstd library
Copyright (C) 2025-now Jakob Gamper

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

<GPL_HEADER>
******************************************************************************/

#ifndef __MSTD__LINALG__CONCEPTS__VECTOR3DCONCEPTS_HPP__
#define __MSTD__LINALG__CONCEPTS__VECTOR3DCONCEPTS_HPP__

#include <concepts>

#include "vector3dDepth.hpp"

namespace mstd
{
template <class T>
class Vector3d;

/**
* @brief Concept for Vector3d types
*
* @tparam T
*/
template <class T>
concept Vector3dConcept = std::same_as<T, Vector3d<typename T::value_type>>;

} // namespace mstd

#endif // __MSTD__LINALG__CONCEPTS__VECTOR3DCONCEPTS_HPP__
75 changes: 75 additions & 0 deletions include/mstd/linAlg/concepts/vector3dDepth.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*****************************************************************************
<GPL_HEADER>

mstd library
Copyright (C) 2025-now Jakob Gamper

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

<GPL_HEADER>
******************************************************************************/

#ifndef __MSTD__LINALG__CONCEPTS__VECTOR3DDEPTH_HPP__
#define __MSTD__LINALG__CONCEPTS__VECTOR3DDEPTH_HPP__

namespace mstd
{
template <class T>
class Vector3d;

/**
* @brief type trait to determine the depth of a Vector3d
*
* @tparam T
*/
template <class T>
struct Vector3dDepth
{
static constexpr int value = 0;
};

/**
* @brief type trait to determine the depth of a Vector3d
*
* @details specialization for Vector3d
*
* @tparam T
*/
template <class T>
struct Vector3dDepth<Vector3d<T>>
{
static constexpr int value = 1 + Vector3dDepth<T>::value;
};

/**
* @brief constexpr variable to check the depth of a Vector3d
*
* @tparam T
*/
template <class T>
constexpr int Vector3dDepth_v = Vector3dDepth<T>::value;

/**
* @brief constexpr variable to check the depth difference of two Vector3ds
*
* @tparam T
* @tparam U
*/
template <class T, class U>
constexpr int Vector3dDepthDifference_v =
Vector3dDepth_v<T> - Vector3dDepth_v<U>;

} // namespace mstd

#endif // __MSTD__LINALG__CONCEPTS__VECTOR3DDEPTH_HPP__
210 changes: 210 additions & 0 deletions include/mstd/linAlg/vector3d.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/*****************************************************************************
<GPL_HEADER>

mstd library
Copyright (C) 2025-now Jakob Gamper

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

<GPL_HEADER>
******************************************************************************/

#ifndef __MSTD__LINALG__VECTOR3D_HPP__
#define __MSTD__LINALG__VECTOR3D_HPP__

#include <mp-units/math.h> // for mp_units::sqrt

#include <cmath> // for std:sqrt
#include <concepts>
#include <ostream> // for std::ostream
#include <utility>

#include "concepts/vector3dConcepts.hpp"
#include "vector3dClass.hpp"

namespace mstd
{
/************************
* comparison operators *
************************/

template <typename U, typename V>
requires std::equality_comparable_with<U, V>
[[nodiscard]] constexpr bool operator==(
const Vector3d<U> &lhs,
const Vector3d<V> &rhs
);

template <typename U, typename V>
requires std::equality_comparable_with<U, V>
[[nodiscard]] constexpr bool operator!=(
const Vector3d<U> &lhs,
const Vector3d<V> &rhs
);

/*********************
* binary + operator *
*********************/

template <typename U, typename V>
requires requires(const U &u, const V &v) { u + v; } &&
(Vector3dDepthDifference_v<U, V> == 0)
[[nodiscard]] constexpr auto operator+(
const Vector3d<U> &lhs,
const Vector3d<V> &rhs
) -> Vector3d<decltype(std::declval<U>() + std::declval<V>())>;

template <typename U, typename V>
requires requires(const U &u, const V &v) { u + v; }
[[nodiscard]] constexpr auto operator+(
const U &scalar,
const Vector3d<V> &vector
) -> Vector3d<decltype(std::declval<U>() + std::declval<V>())>;

template <typename U, typename V>
requires requires(const U &u, const V &v) { u + v; }
[[nodiscard]] constexpr auto operator+(
const Vector3d<U> &vector,
const V &scalar
) -> Vector3d<decltype(std::declval<U>() + std::declval<V>())>;

/*********************
* binary - operator *
*********************/

template <typename U, typename V>
requires requires(const U &u, const V &v) { u - v; } &&
(Vector3dDepthDifference_v<U, V> == 0)
[[nodiscard]] constexpr auto operator-(
const Vector3d<U> &lhs,
const Vector3d<V> &rhs
) -> Vector3d<decltype(std::declval<U>() - std::declval<V>())>;

template <typename U, typename V>
requires requires(const U &u, const V &v) { u - v; }
[[nodiscard]] constexpr auto operator-(
const Vector3d<U> &vector,
const V &scalar
) -> Vector3d<decltype(std::declval<U>() - std::declval<V>())>;

/*********************
* binary * operator *
*********************/

template <typename U, typename V>
requires requires(const U &u, const V &v) { u * v; } &&
(Vector3dDepthDifference_v<U, V> == 0)
[[nodiscard]] constexpr auto operator*(
const Vector3d<U> &lhs,
const Vector3d<V> &rhs
) -> Vector3d<decltype(std::declval<U>() * std::declval<V>())>;

template <typename U, typename V>
requires requires(const U &u, const V &v) { u * v; }
[[nodiscard]] constexpr auto operator*(
const U &scalar,
const Vector3d<V> &vector
) -> Vector3d<decltype(std::declval<U>() * std::declval<V>())>;

template <typename U, typename V>
requires requires(const U &u, const V &v) { u * v; }
[[nodiscard]] constexpr auto operator*(
const Vector3d<U> &vector,
const V &scalar
) -> Vector3d<decltype(std::declval<U>() * std::declval<V>())>;

/*********************
* binary / operator *
*********************/

template <typename U, typename V>
requires requires(const U &u, const V &v) { u / v; } &&
(Vector3dDepthDifference_v<U, V> == 0)
[[nodiscard]] constexpr auto operator/(
const Vector3d<U> &lhs,
const Vector3d<V> &rhs
) -> Vector3d<decltype(std::declval<U>() / std::declval<V>())>;

template <typename U, typename V>
requires requires(const U &u, const V &v) { u / v; }
[[nodiscard]] constexpr auto operator/(
const Vector3d<U> &vector,
const V &scalar
) -> Vector3d<decltype(std::declval<U>() / std::declval<V>())>;

/******************
* norm functions *
******************/

template <typename U>
requires requires(const U &u) { u * u + u * u; }
[[nodiscard]] constexpr auto normSquared(const Vector3d<U> &vec)
-> decltype(std::declval<U>() * std::declval<U>());

template <Vector3dConcept U>
requires requires(const U &vec) { std::sqrt(normSquared(vec)); }
[[nodiscard]] auto norm(const U &vec)
-> decltype(std::sqrt(normSquared(vec)));

template <Vector3dConcept U>
requires requires(const U &vec) { mp_units::sqrt(normSquared(vec)); }
[[nodiscard]] auto norm(const U &vec)
-> decltype(mp_units::sqrt(normSquared(vec)));

template <typename U>
requires requires(const Vector3d<U> &vec) { vec[0] / norm(vec); }
[[nodiscard]] auto normalize(const Vector3d<U> &vec) -> Vector3d<
decltype(std::declval<U>() / norm(std::declval<const Vector3d<U> &>()))>;

template <typename U>
requires requires(Vector3d<U> &vec) { vec /= norm(vec); }
void normalize(Vector3d<U> &vec);

/*********************
* product functions *
*********************/

template <typename U, typename V>
requires requires(const U &u, const V &v) { u * v + u * v; } &&
(Vector3dDepthDifference_v<U, V> == 0)
[[nodiscard]] constexpr auto dot(
const Vector3d<U> &lhs,
const Vector3d<V> &rhs
) -> decltype(std::declval<U>() * std::declval<V>() + std::declval<U>() * std::declval<V>());

template <typename U, typename V>
requires requires(const U &u, const V &v) { u * v - u * v; } &&
(Vector3dDepthDifference_v<U, V> == 0)
[[nodiscard]] constexpr auto cross(
const Vector3d<U> &lhs,
const Vector3d<V> &rhs
)
-> Vector3d<
decltype(std::declval<U>() * std::declval<V>() - std::declval<U>() * std::declval<V>())>;

/**************
* ostream << *
**************/

template <typename U>
requires requires(std::ostream &os, const U &u) {
{ os << u } -> std::same_as<std::ostream &>;
}
std::ostream &operator<<(std::ostream &os, const Vector3d<U> &vector);

} // namespace mstd

#include "vector3d.tpp"

#endif // __MSTD__LINALG__VECTOR3D_HPP__
Loading
Loading