Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfVector4.h
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
20#ifndef _SOURCE_TYPES_TFVECTOR4_H_
21#define _SOURCE_TYPES_TFVECTOR4_H_
22
23#include "tfVector3.h"
24#include <Magnum/Math/Vector4.h>
25
26
27namespace TissueForge::types {
28
29
30 template<class T> using Vector4Base = Magnum::Math::Vector4<T>;
31
32 template<typename T>
33 class TVector4 : public Vector4Base<T> {
34 public:
41 template<class U = T, typename std::enable_if<std::is_floating_point<U>::value, bool>::type = true>
42 static TVector4<T> planeEquation(const TVector3<T> &normal, const TVector3<T> &point) {
43 return Magnum::Math::planeEquation(normal, point);
44 }
45
52 template<class U = T, typename std::enable_if<std::is_floating_point<U>::value, bool>::type = true>
53 static TVector4<T> planeEquation(const TVector3<T>& p0, const TVector3<T>& p1, const TVector3<T>& p2) {
54 return Magnum::Math::planeEquation(p0, p1, p2);
55 }
56
57 constexpr TVector4() noexcept: Vector4Base<T>() {}
58
59 constexpr explicit TVector4(T value) noexcept: Vector4Base<T>(value) {}
60
61 constexpr TVector4(T x, T y, T z, T w) noexcept: Vector4Base<T>(x, y, z, w) {}
62
63 constexpr TVector4(const TVector3<T>& xyz, T w) noexcept: Vector4Base<T>(xyz[0], xyz[1], xyz[2], w) {}
64
65 template<class U> constexpr explicit TVector4(const TVector4<U>& other) noexcept: Vector4Base<T>(other) {}
66
68 T& x() { return Vector4Base<T>::x(); }
69
71 T& y() { return Vector4Base<T>::y(); }
72
74 T& z() { return Vector4Base<T>::z(); }
75
77 T& w() { return Vector4Base<T>::w(); }
78
80 constexpr T x() const { return Vector4Base<T>::x(); }
81
83 constexpr T y() const { return Vector4Base<T>::y(); }
84
86 constexpr T z() const { return Vector4Base<T>::z(); }
87
89 constexpr T w() const { return Vector4Base<T>::w(); }
90
92 T& r() { return Vector4Base<T>::r(); }
93
95 T& g() { return Vector4Base<T>::g(); }
96
98 T& b() { return Vector4Base<T>::b(); }
99
101 T& a() { return Vector4Base<T>::a(); }
102
104 constexpr T r() const { return Vector4Base<T>::r(); }
105
107 constexpr T g() const { return Vector4Base<T>::g(); }
108
110 constexpr T b() const { return Vector4Base<T>::b(); }
111
113 constexpr T a() const { return Vector4Base<T>::a(); }
114
116 TVector3<T>& xyz() { return TVector3<T>::from(Vector4Base<T>::data()); }
117
119 constexpr const TVector3<T> xyz() const {
120 return {Vector4Base<T>::_data[0], Vector4Base<T>::_data[1], Vector4Base<T>::_data[2]};
121 }
122
124 TVector3<T>& rgb() { return TVector3<T>::from(Vector4Base<T>::data()); }
125
127 constexpr const TVector3<T> rgb() const {
128 return {Vector4Base<T>::_data[0], Vector4Base<T>::_data[1], Vector4Base<T>::_data[2]};
129 }
130
132 TVector2<T>& xy() { return TVector2<T>::from(Vector4Base<T>::data()); }
133
135 constexpr const TVector2<T> xy() const {
136 return {Vector4Base<T>::_data[0], Vector4Base<T>::_data[1]};
137 }
138
140 template<class U = T, typename std::enable_if<std::is_floating_point<U>::value, bool>::type = true>
141 T distance(const TVector3<T> &point) const {
142 return Magnum::Math::Distance::pointPlane(point, *this);
143 }
144
146 template<class U = T, typename std::enable_if<std::is_floating_point<U>::value, bool>::type = true>
147 T distanceScaled(const TVector3<T> &point) const {
148 return Magnum::Math::Distance::pointPlaneScaled(point, *this);
149 }
150
151 template<class U = T, typename std::enable_if<std::is_floating_point<U>::value, bool>::type = true>
152 TVector3<T> shortestDisplacementFrom(const TVector3<T> &pt) const {
153 return - distance(pt) * xyz().normalized();
154 }
155
156 MAGNUM_BASE_VECTOR_CAST_METHODS(4, TVector4, Vector4Base)
157
158 REVISED_MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(4, TVector4, Vector4Base)
159
160 #ifdef SWIGPYTHON
161 SWIGPYTHON_MAGNUM_VECTOR_SUBCLASS_IMPLEMENTATION(4, TVector4)
162 #endif
163 };
164
165}
166
167TF_VECTOR_IMPL_OSTREAM(TissueForge::types::TVector4)
168
169#endif // _SOURCE_TYPES_TFVECTOR4_H_
Definition tfVector2.h:35
static TVector2< T > & from(T *data)
Definition tfVector2.h:88
Definition tfVector3.h:35
std::enable_if< std::is_floating_point< U >::value, TVector3< T > >::type normalized() const
Definition tfVector3.h:150
static TVector3< T > & from(T *data)
Definition tfVector3.h:150
Definition tfVector4.h:33
constexpr const TVector2< T > xy() const
Definition tfVector4.h:135
constexpr T y() const
Definition tfVector4.h:83
T & a()
Definition tfVector4.h:101
TVector2< T > & xy()
Definition tfVector4.h:132
constexpr T z() const
Definition tfVector4.h:86
TVector3< T > & xyz()
Definition tfVector4.h:116
T & b()
Definition tfVector4.h:98
T & x()
Definition tfVector4.h:68
T distanceScaled(const TVector3< T > &point) const
Definition tfVector4.h:147
constexpr const TVector3< T > xyz() const
Definition tfVector4.h:119
constexpr T a() const
Definition tfVector4.h:113
T & w()
Definition tfVector4.h:77
constexpr T x() const
Definition tfVector4.h:80
T & r()
Definition tfVector4.h:92
static TVector4< T > planeEquation(const TVector3< T > &p0, const TVector3< T > &p1, const TVector3< T > &p2)
Initialize a plane equation.
Definition tfVector4.h:53
constexpr T w() const
Definition tfVector4.h:89
constexpr T g() const
Definition tfVector4.h:107
T & g()
Definition tfVector4.h:95
constexpr T r() const
Definition tfVector4.h:104
T & z()
Definition tfVector4.h:74
T distance(const TVector3< T > &point) const
Definition tfVector4.h:141
T & y()
Definition tfVector4.h:71
TVector3< T > & rgb()
Definition tfVector4.h:124
static TVector4< T > planeEquation(const TVector3< T > &normal, const TVector3< T > &point)
Initialize a plane equation.
Definition tfVector4.h:42
constexpr const TVector3< T > rgb() const
Definition tfVector4.h:127
constexpr T b() const
Definition tfVector4.h:110
Native Tissue Forge type definitions.
Definition tfMatrix.h:33