Skip to content

Commit 3d37a29

Browse files
committed
Fixing issues with ranges being constructed from a single vector
1 parent 078f02c commit 3d37a29

2 files changed

Lines changed: 117 additions & 16 deletions

File tree

source/Ranges/TRange.inl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ namespace Langulus::Math
2323
/// Copy constructor
2424
TEMPLATE() LANGULUS(INLINED)
2525
constexpr TME()::TRange(const TRange& a) noexcept {
26-
SIMD::Convert<0>(a.mMinMax, mMinMax);
26+
SIMD::Convert<Default>(a.mMinMax, mMinMax);
2727
}
2828

2929
/// Construct the range sequentially, like so:
3030
/// minX, minY, minZ..., maxX, maxY, maxZ...
3131
TEMPLATE() LANGULUS(INLINED)
3232
constexpr TME()::TRange(const CT::Vector auto& other) noexcept {
33-
SIMD::Convert<0>(DeintCast(other), mMinMax);
33+
SIMD::Convert<Default>(DeintCast(other), mMinMax);
3434

3535
if constexpr (CT::Normalized<T>) {
3636
mMin = mMin.Normalize();
@@ -41,7 +41,7 @@ namespace Langulus::Math
4141
/// Construct the range from scalar
4242
TEMPLATE() LANGULUS(INLINED)
4343
constexpr TME()::TRange(const CT::Scalar auto& other) noexcept {
44-
SIMD::Convert<0>(DeintCast(other), mMinMax);
44+
SIMD::Convert<Default>(DeintCast(other), mMinMax);
4545

4646
if constexpr (CT::Normalized<T>) {
4747
mMin = mMin.Normalize();

test/TestRanges.cpp

Lines changed: 114 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ TEMPLATE_TEST_CASE("Ranges", "[range]",
7373
using Flow::Code;
7474
using T = TestType;
7575
using P = typename T::PointType;
76+
using P2 = typename T::CoalescedType;
7677
using E = TypeOf<T>;
7778
constexpr auto C = CountOf<T>;
7879
static_assert(CT::Exact<E, TypeOf<P>>);
@@ -135,25 +136,125 @@ TEMPLATE_TEST_CASE("Ranges", "[range]",
135136
}
136137

137138
WHEN("Assigning a range manually") {
138-
T x {P {1, 2, 3, 4}};
139+
T x {P {1, 2, 3, 4}, P {1, 2, 3, 4}};
139140
x = T {P {0, 5, 12, 1}, P {1, 7, 19, 100}};
141+
142+
if constexpr (not CT::Normalized<T>) {
143+
if constexpr (C == 8) {
144+
REQUIRE(x == T {P {0, 5, 12, 1}, P {1, 7, 19, 100}});
145+
REQUIRE(x == P2 {0, 5, 12, 1, 1, 7, 19, 100});
146+
REQUIRE(x.mMin == P {0, 5, 12, 1});
147+
REQUIRE(x.mMax == P {1, 7, 19, 100});
148+
}
149+
else if constexpr (C == 6) {
150+
REQUIRE(x == T {P {0, 5, 12}, P {1, 7, 19}});
151+
REQUIRE(x == P2 {0, 5, 12, 1, 7, 19});
152+
REQUIRE(x.mMin == P {0, 5, 12});
153+
REQUIRE(x.mMax == P {1, 7, 19});
154+
}
155+
else if constexpr (C == 4) {
156+
REQUIRE(x == T {P {0, 5}, P {1, 7}});
157+
REQUIRE(x == P2 {0, 5, 1, 7});
158+
REQUIRE(x.mMin == P {0, 5});
159+
REQUIRE(x.mMax == P {1, 7});
160+
}
161+
else if constexpr (C == 2) {
162+
REQUIRE(x == T {P {0}, P {1}});
163+
REQUIRE(x == P2 {0, 1});
164+
REQUIRE(x.mMin == 0);
165+
REQUIRE(x.mMax == 1);
166+
}
167+
else static_assert(false, "TODO");
168+
}
169+
else if constexpr (C == 8) {
170+
REQUIRE(x.mMin.x == Approx(0).margin(0.0001));
171+
REQUIRE(x.mMin.y == Approx(0.3835).margin(0.0001));
172+
REQUIRE(x.mMin.z == Approx(0.9204).margin(0.0001));
173+
REQUIRE(x.mMin.w == Approx(0.0767).margin(0.0001));
140174

141-
REQUIRE(x == T {P {0, 5, 12, 1}, P {1, 7, 19, 100}});
142-
REQUIRE(x != P {0, 5, 12, 1});
143-
REQUIRE(x.mMin == P {0, 5, 12, 1});
144-
REQUIRE(x.GetMin() == P {0, 5, 12, 1});
145-
REQUIRE(x.mMax == P {1, 7, 19, 100});
146-
REQUIRE(x.GetMax() == P {1, 7, 19, 100});
175+
REQUIRE(x.mMax.x == Approx(0.0098).margin(0.0001));
176+
REQUIRE(x.mMax.y == Approx(0.0686).margin(0.0001));
177+
REQUIRE(x.mMax.z == Approx(0.1862).margin(0.0001));
178+
REQUIRE(x.mMax.w == Approx(0.9801).margin(0.0001));
179+
}
180+
else if constexpr (C == 6) {
181+
REQUIRE(x.mMin.x == Approx(0).margin(0.0001));
182+
REQUIRE(x.mMin.y == Approx(0.3846).margin(0.0001));
183+
REQUIRE(x.mMin.z == Approx(0.9231).margin(0.0001));
184+
185+
REQUIRE(x.mMax.x == Approx(0.0493).margin(0.0001));
186+
REQUIRE(x.mMax.y == Approx(0.3453).margin(0.0001));
187+
REQUIRE(x.mMax.z == Approx(0.9372).margin(0.0001));
188+
}
189+
else if constexpr (C == 4) {
190+
REQUIRE(x.mMin.x == Approx(0).margin(0.0001));
191+
REQUIRE(x.mMin.y == Approx(1).margin(0.0001));
192+
193+
REQUIRE(x.mMax.x == Approx(0.1414).margin(0.0001));
194+
REQUIRE(x.mMax.y == Approx(0.9899).margin(0.0001));
195+
}
196+
else static_assert(false, "TODO");
147197
}
148198

149199
WHEN("Assigning a vector manually") {
150-
T x {P {1, 2, 3, 4}};
151-
x = P {0, 5, 12, 1};
200+
T x {P2 {1, 2, 3, 4}};
201+
x = P2 {0, 5, 12, 1};
152202

153-
REQUIRE(x == T {P {0, 5, 12, 1}, P {0, 0, 0, 0}});
154-
REQUIRE(x == P {0, 5, 12, 1});
155-
REQUIRE(x.mMin == P {0, 5, 12, 1});
156-
REQUIRE(x.mMax == P {0, 0, 0, 0});
203+
if constexpr (not CT::Normalized<T>) {
204+
if constexpr (C == 8) {
205+
REQUIRE(x == T {P {0, 5, 12, 1}, P {0, 0, 0, 0}});
206+
REQUIRE(x == P2 {0, 5, 12, 1});
207+
REQUIRE(x.mMin == P {0, 5, 12, 1});
208+
REQUIRE(x.mMax == P {0, 0, 0, 0});
209+
}
210+
else if constexpr (C == 6) {
211+
REQUIRE(x == T {P {0, 5, 12}, P {1, 0, 0}});
212+
REQUIRE(x == P2 {0, 5, 12, 1});
213+
REQUIRE(x.mMin == P {0, 5, 12});
214+
REQUIRE(x.mMax == P {1, 0, 0});
215+
}
216+
else if constexpr (C == 4) {
217+
REQUIRE(x == T {P {0, 5}, P {12, 1}});
218+
REQUIRE(x == P2 {0, 5, 12, 1});
219+
REQUIRE(x.mMin == P {0, 5});
220+
REQUIRE(x.mMax == P {12, 1});
221+
}
222+
else if constexpr (C == 2) {
223+
REQUIRE(x == T {P {0}, P {5}});
224+
REQUIRE(x == P2 {0, 5});
225+
REQUIRE(x.mMin == 0);
226+
REQUIRE(x.mMax == 5);
227+
}
228+
else static_assert(false, "TODO");
229+
}
230+
else if constexpr (C == 8) {
231+
REQUIRE(x.mMin.x == Approx(0).margin(0.0001));
232+
REQUIRE(x.mMin.y == Approx(0.3835).margin(0.0001));
233+
REQUIRE(x.mMin.z == Approx(0.9204).margin(0.0001));
234+
REQUIRE(x.mMin.w == Approx(0.0767).margin(0.0001));
235+
236+
REQUIRE(x.mMax.x == Approx(0).margin(0.0001));
237+
REQUIRE(x.mMax.y == Approx(0).margin(0.0001));
238+
REQUIRE(x.mMax.z == Approx(0).margin(0.0001));
239+
REQUIRE(x.mMax.w == Approx(0).margin(0.0001));
240+
}
241+
else if constexpr (C == 6) {
242+
REQUIRE(x.mMin.x == Approx(0).margin(0.0001));
243+
REQUIRE(x.mMin.y == Approx(0.3846).margin(0.0001));
244+
REQUIRE(x.mMin.z == Approx(0.9231).margin(0.0001));
245+
246+
REQUIRE(x.mMax.x == Approx(1).margin(0.0001));
247+
REQUIRE(x.mMax.y == Approx(0).margin(0.0001));
248+
REQUIRE(x.mMax.z == Approx(0).margin(0.0001));
249+
}
250+
else if constexpr (C == 4) {
251+
REQUIRE(x.mMin.x == Approx(0).margin(0.0001));
252+
REQUIRE(x.mMin.y == Approx(1).margin(0.0001));
253+
254+
REQUIRE(x.mMax.x == Approx(0.9965).margin(0.0001));
255+
REQUIRE(x.mMax.y == Approx(0.0830).margin(0.0001));
256+
}
257+
else static_assert(false, "TODO");
157258
}
158259

159260
WHEN("Assigning a scalar manually") {

0 commit comments

Comments
 (0)