forked from Hartmut/paradiso
- add instructions for cross-compilation - add utility function for Windows and Linux executable path
85 lines
2.8 KiB
C++
85 lines
2.8 KiB
C++
/*
|
|
* Copyright 2023-2025 Hartmut Seichter and Contributors
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
*/
|
|
#ifndef PARADISO_VECTOR_HPP
|
|
#define PARADISO_VECTOR_HPP
|
|
|
|
#include <paradiso/globals.hpp>
|
|
#include <paradiso/matrix.hpp>
|
|
|
|
namespace paradiso {
|
|
|
|
/**
|
|
* Basic vector types used in pixwerx.
|
|
*/
|
|
|
|
template <typename T> struct Vector2 : Matrix<2, 1, T> {
|
|
|
|
using base_type = Matrix<2, 1, T>;
|
|
|
|
constexpr const T& x() const noexcept { return (*this)[0]; }
|
|
constexpr T& x() { return (*this)[0]; }
|
|
|
|
constexpr const T& y() const { return (*this)[1]; }
|
|
constexpr T& y() { return (*this)[1]; }
|
|
|
|
inline auto homogenous(T w = 1) const {
|
|
return Matrix<3, 1, T>({x(), y(), w});
|
|
}
|
|
|
|
static T angle_between(const Vector2& a, const Vector2& b) {
|
|
return std::acos(dot(a.normalized(), b.normalized()));
|
|
}
|
|
};
|
|
|
|
template <typename T> struct Vector3 : Matrix<3, 1, T> {
|
|
|
|
using base_type = Matrix<3, 1, T>;
|
|
|
|
constexpr const T& x() const { return (*this)[0]; }
|
|
constexpr T& x() { return (*this)[0]; }
|
|
|
|
constexpr const T& y() const { return (*this)[1]; }
|
|
constexpr T& y() { return (*this)[1]; }
|
|
|
|
constexpr Vector2<T> xy() const noexcept { return {x(), y()}; }
|
|
|
|
static constexpr Vector3 cross(const Vector3& lhs, const Vector3& rhs) {
|
|
return vector3_({lhs[1] * rhs[2] - rhs[1] * lhs[2],
|
|
lhs[2] * rhs[0] - rhs[2] * lhs[0],
|
|
lhs[0] * rhs[1] - rhs[0] * lhs[1]});
|
|
}
|
|
|
|
static constexpr auto x_axis() noexcept {
|
|
return Vector3::make(T{1}, T{0}, T{0});
|
|
}
|
|
static constexpr auto y_axis() noexcept {
|
|
return Vector3::make(T{0}, T{1}, T{0});
|
|
}
|
|
static constexpr auto z_axis() noexcept {
|
|
return Vector3<T>::make(T{0}, T{0}, T{1});
|
|
}
|
|
};
|
|
|
|
}; // namespace paradiso
|
|
|
|
#endif
|