Skip to content

Commit c9ff5dc

Browse files
committed
Implicitly converting 1D vectors to scalars; Improved TRange constructors; Other minor improvements and code cleanup
1 parent 2c698b2 commit c9ff5dc

File tree

5 files changed

+38
-59
lines changed

5 files changed

+38
-59
lines changed

source/Matrices/TMatrix.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,19 @@ namespace Langulus
6262

6363
template<CT::VectorBased V> static constexpr auto
6464
From(const Math::TQuaternion<TypeOf<V>>&, const V& = 0, const V& = 1) noexcept
65-
-> Math::TMatrix<TypeOf<V>, V::MemberCount + 1>;
65+
-> Math::TMatrix<TypeOf<V>, V::MemberCount + 1>;
6666

67-
static constexpr auto
68-
PerspectiveFOV(const CT::Angle auto&, CT::ScalarBased auto, CT::ScalarBased auto, CT::ScalarBased auto);
67+
template<CT::ScalarBased T> static constexpr auto
68+
PerspectiveFOV(const CT::Angle auto&, const T& aspect, const T& near, const T& far)
69+
-> Math::TMatrix<T, 4>;
6970

7071
template<CT::ScalarBased T> static constexpr auto
71-
PerspectiveRegion(const T&, const T&, const T&, const T&, const T&, const T&)
72-
-> Math::TMatrix<T, 4>;
72+
PerspectiveRegion(const T& left, const T& right, const T& top, const T& bottom, const T& near, const T& far)
73+
-> Math::TMatrix<T, 4>;
7374

7475
template<CT::ScalarBased T> static constexpr auto
75-
Orthographic(const T&, const T&, const T&, const T&)
76-
-> Math::TMatrix<T, 4>;
76+
Orthographic(const T& width, const T& height, const T& near, const T& far)
77+
-> Math::TMatrix<T, 4>;
7778
};
7879

7980
/// Used as an imposed base for any type that can be interpretable as a

source/Matrices/TMatrix.inl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -847,13 +847,11 @@ namespace Langulus::A
847847
/// @param near - the distance to the near clipping plane
848848
/// @param far - the distance to the far clipping plane
849849
/// @return the projection matrix
850+
template<CT::ScalarBased T>
850851
constexpr auto A::Matrix::PerspectiveFOV(
851-
const CT::Angle auto& fieldOfView,
852-
CT::ScalarBased auto aspect,
853-
CT::ScalarBased auto near,
854-
CT::ScalarBased auto far
855-
) {
856-
using T = Lossless<decltype(aspect), decltype(near), decltype(far)>;
852+
const CT::Angle auto& fieldOfView, const T& aspect,
853+
const T& near, const T& far
854+
) -> Math::TMatrix<T, 4> {
857855
// https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/opengl-perspective-projection-matrix.html
858856
const T scale = ::std::tan(T {fieldOfView.GetRadians()} * T {0.5}) * near;
859857
const T r = scale;

source/Ranges/TRange.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ namespace Langulus::Math
182182
constexpr TRange(const CT::Scalar auto&) noexcept;
183183
constexpr TRange(const PointType&, const PointType&) noexcept;
184184
constexpr TRange(const MemberType&, const MemberType&) noexcept;
185+
constexpr TRange(const CT::ScalarBased auto&, const CT::ScalarBased auto&) noexcept;
186+
constexpr TRange(const CT::VectorBased auto&, const CT::VectorBased auto&) noexcept;
185187

186188
TRange(const CT::SIMD auto&) noexcept;
187189
TRange(Describe&&);

source/Ranges/TRange.inl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,29 @@ namespace Langulus::Math
7171
mMax = mMax.Normalize();
7272
}
7373
}
74+
75+
/// Create range from a min and a max vectors
76+
TEMPLATE() LANGULUS(INLINED)
77+
constexpr TME()::TRange(const CT::VectorBased auto& min, const CT::VectorBased auto& max) noexcept {
78+
for (Count i = 0; i < CountOf<T>; ++i) {
79+
mMinMax[i] = min.all[i];
80+
mMinMax[i + CountOf<T>] = max.all[i];
81+
}
82+
}
83+
84+
/// Create range from a min and a max scalars
85+
TEMPLATE() LANGULUS(INLINED)
86+
constexpr TME()::TRange(const CT::ScalarBased auto& min, const CT::ScalarBased auto& max) noexcept {
87+
for (Count i = 0; i < CountOf<T>; ++i) {
88+
mMinMax[i] = min;
89+
mMinMax[i + CountOf<T>] = max;
90+
}
91+
92+
if constexpr (CT::Normalized<T>) {
93+
mMin = mMin.Normalize();
94+
mMax = mMax.Normalize();
95+
}
96+
}
7497

7598
/// Create from registers
7699
TEMPLATE() LANGULUS(INLINED)

source/Vectors/TVector.hpp

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -160,27 +160,6 @@ namespace Langulus::Math
160160
union { RTTI::Tag<TYPE, Traits::X, Traits::R, Traits::U> x, first, r, red, u; };
161161
};
162162

163-
// Declare the rest as functions, so that they don't take up space
164-
// This is necessary to work around the dependent names in TVector
165-
// This will also error out, when missing (), but if you happen to
166-
// call them by accident, you will get a proper compile error
167-
/*void y() { static_assert(false, "1D vector doesn't have 'y' component"); }
168-
void second() { static_assert(false, "1D vector doesn't have 'second' component"); }
169-
void g() { static_assert(false, "1D vector doesn't have 'g' component"); }
170-
void green() { static_assert(false, "1D vector doesn't have 'green' component"); }
171-
void v() { static_assert(false, "1D vector doesn't have 'v' component"); }
172-
173-
void z() { static_assert(false, "1D vector doesn't have 'z' component"); }
174-
void third() { static_assert(false, "1D vector doesn't have 'third' component"); }
175-
void b() { static_assert(false, "1D vector doesn't have 'b' component"); }
176-
void blue() { static_assert(false, "1D vector doesn't have 'blue' component"); }
177-
void s() { static_assert(false, "1D vector doesn't have 's' component"); }
178-
179-
void w() { static_assert(false, "1D vector doesn't have 'w' component"); }
180-
void fourth() { static_assert(false, "1D vector doesn't have 'fourth' component"); }
181-
void a() { static_assert(false, "1D vector doesn't have 'a' component"); }
182-
void alpha() { static_assert(false, "1D vector doesn't have 'alpha' component"); }
183-
void t() { static_assert(false, "1D vector doesn't have 't' component"); }*/
184163
static constexpr TYPE y = static_cast<TYPE>(DEFAULT);
185164
static constexpr TYPE second = static_cast<TYPE>(DEFAULT);
186165
static constexpr TYPE g = static_cast<TYPE>(DEFAULT);
@@ -239,21 +218,6 @@ namespace Langulus::Math
239218
};
240219
};
241220

242-
// Declare the rest as functions, so that they don't take up space
243-
// This is necessary to work around the dependent names in TVector
244-
// This will also error out, when missing (), but if you happen to
245-
// call them by accident, you will get a proper compile error
246-
/*void z() { static_assert(false, "2D vector doesn't have 'z' component"); }
247-
void third() { static_assert(false, "2D vector doesn't have 'third' component"); }
248-
void b() { static_assert(false, "2D vector doesn't have 'b' component"); }
249-
void blue() { static_assert(false, "2D vector doesn't have 'blue' component"); }
250-
void s() { static_assert(false, "2D vector doesn't have 's' component"); }
251-
252-
void w() { static_assert(false, "2D vector doesn't have 'w' component"); }
253-
void fourth() { static_assert(false, "2D vector doesn't have 'fourth' component"); }
254-
void a() { static_assert(false, "2D vector doesn't have 'a' component"); }
255-
void alpha() { static_assert(false, "2D vector doesn't have 'alpha' component"); }
256-
void t() { static_assert(false, "2D vector doesn't have 't' component"); }*/
257221
static constexpr TYPE z = static_cast<TYPE>(DEFAULT);
258222
static constexpr TYPE third = static_cast<TYPE>(DEFAULT);
259223
static constexpr TYPE b = static_cast<TYPE>(DEFAULT);
@@ -312,15 +276,6 @@ namespace Langulus::Math
312276
};
313277
};
314278

315-
// Declare the rest as functions, so that they don't take up space
316-
// This is necessary to work around the dependent names in TVector
317-
// This will also error out, when missing (), but if you happen to
318-
// call them by accident, you will get a proper compile error
319-
/*void w() { static_assert(false, "3D vector doesn't have 'w' component"); }
320-
void fourth() { static_assert(false, "3D vector doesn't have 'fourth' component"); }
321-
void a() { static_assert(false, "3D vector doesn't have 'a' component"); }
322-
void alpha() { static_assert(false, "3D vector doesn't have 'alpha' component"); }
323-
void t() { static_assert(false, "3D vector doesn't have 't' component"); }*/
324279
static constexpr TYPE w = static_cast<TYPE>(DEFAULT);
325280
static constexpr TYPE fourth = static_cast<TYPE>(DEFAULT);
326281
static constexpr TYPE a = static_cast<TYPE>(DEFAULT);
@@ -713,7 +668,7 @@ namespace Langulus::Math
713668
constexpr explicit operator bool () const noexcept;
714669

715670
template<CT::ScalarBased N> requires (S == 1 and CT::Convertible<N, T>)
716-
explicit constexpr operator N () const noexcept;
671+
/*explicit*/ constexpr operator N () const noexcept;
717672

718673
template<Count ALTS> requires (ALTS < S)
719674
operator TVector<T, ALTS>& () const noexcept;

0 commit comments

Comments
 (0)