24 static_assert(D == 2 || D == 3,
"Only 2D or 3D rotation-matrices are supported");
28 constexpr matrix &operator=(
matrix const &)
noexcept =
default;
29 constexpr matrix &operator=(
matrix &&)
noexcept =
default;
31 constexpr matrix()
noexcept
33 hilet a = f32x4::broadcast(1.0f);
41 _col0(col0), _col1(col1), _col2(col2), _col3(col3)
46 _col0(
static_cast<f32x4>(col0)),
47 _col1(
static_cast<f32x4>(col1)),
48 _col2(
static_cast<f32x4>(col2)),
49 _col3{0.0f, 0.0f, 0.0f, 1.0f}
62 float c2r2)
noexcept requires(D == 3) :
63 _col0(c0r0, c0r1, c0r2, 0.0f), _col1(c1r0, c1r1, c1r2, 0.0f), _col2(c2r0, c2r1, c2r2, 0.0f), _col3(0.0f, 0.0f, 0.0f, 1.0f)
83 float c3r3)
noexcept requires(D == 3) :
84 _col0(c0r0, c0r1, c0r2, c0r3), _col1(c1r0, c1r1, c1r2, c1r3), _col2(c2r0, c2r1, c2r2, c2r3), _col3(c3r0, c3r1, c3r2, c3r3)
89 requires(E < D) [[nodiscard]]
constexpr matrix(
matrix<E> const &other) noexcept :
90 _col0(get<0>(other)), _col1(get<1>(other)), _col2(get<2>(other)), _col3(get<3>(other))
95 requires(E < D)
constexpr matrix &
operator=(
matrix<E> const &rhs)
noexcept
113 [[nodiscard]]
constexpr static matrix
117 [[nodiscard]]
friend constexpr f32x4 get(
matrix const &rhs)
noexcept
119 if constexpr (I == 0) {
121 }
else if constexpr (I == 1) {
123 }
else if constexpr (I == 2) {
125 }
else if constexpr (I == 3) {
128 hi_static_no_default();
132 [[nodiscard]]
constexpr bool holds_invariant()
const noexcept
137 [[nodiscard]]
constexpr auto operator*(
f32x4 const &rhs)
const noexcept
139 return f32x4{_col0 * rhs.xxxx() + _col1 * rhs.yyyy() + _col2 * rhs.zzzz() + _col3 * rhs.wwww()};
147 [[nodiscard]]
constexpr float operator*(
float const &rhs)
const noexcept
150 auto abs_scale = hypot<D>(_col0 * f32x4::broadcast(rhs));
163 return {*
this * get<0>(rhs), *
this * get<1>(rhs), *
this * get<2>(rhs), *
this * get<3>(rhs)};
167 [[nodiscard]]
constexpr auto operator*(
vector<E> const &rhs)
const noexcept
169 hi_axiom(rhs.holds_invariant());
171 _col0 *
static_cast<f32x4>(rhs).xxxx() + _col1 *
static_cast<f32x4>(rhs).yyyy() +
172 _col2 *
static_cast<f32x4>(rhs).zzzz()};
176 [[nodiscard]]
constexpr auto operator*(extent<E>
const &rhs)
const noexcept
178 hi_axiom(rhs.holds_invariant());
180 _col0 *
static_cast<f32x4
>(rhs).xxxx() + _col1 *
static_cast<f32x4
>(rhs).yyyy() +
181 _col2 *
static_cast<f32x4
>(rhs).zzzz()};
185 [[nodiscard]]
constexpr auto operator*(point<E>
const &rhs)
const noexcept
187 hi_axiom(rhs.holds_invariant());
189 _col0 *
static_cast<f32x4
>(rhs).xxxx() + _col1 *
static_cast<f32x4
>(rhs).yyyy() +
190 _col2 *
static_cast<f32x4
>(rhs).zzzz() + _col3 *
static_cast<f32x4
>(rhs).wwww()};
193 [[nodiscard]]
constexpr rectangle operator*(aarectangle
const &rhs)
const noexcept
195 return *
this * rectangle{rhs};
199 [[nodiscard]]
constexpr rectangle operator*(rectangle
const &rhs)
const noexcept
201 return rectangle{*
this * rhs.origin, *
this * rhs.right, *
this * rhs.up};
204 [[nodiscard]]
constexpr quad operator*(quad
const &rhs)
const noexcept
206 return quad{*
this * rhs.p0, *
this * rhs.p1, *
this * rhs.p2, *
this * rhs.p3};
209 [[nodiscard]]
constexpr circle operator*(circle
const &rhs)
const noexcept
211 return circle{*
this * midpoint(rhs), *
this * rhs.radius()};
214 [[nodiscard]]
constexpr line_segment operator*(line_segment
const &rhs)
const noexcept
216 return line_segment{*
this * rhs.origin(), *
this * rhs.direction()};
225 hi_axiom(rhs.holds_invariant());
227 _col0 *
static_cast<f32x4>(rhs).xxxx() + _col1 *
static_cast<f32x4>(rhs).yyyy() +
228 _col2 *
static_cast<f32x4>(rhs).zzzz() + _col3};
238 return matrix{*
this * get<0>(rhs), *
this * get<1>(rhs), *
this * get<2>(rhs), *
this * get<3>(rhs)};
245 auto tmp = transpose(rhs._col0, rhs._col1, rhs._col2, rhs._col3);
246 return {std::get<0>(tmp), std::get<1>(tmp), std::get<2>(tmp), std::get<3>(tmp)};
250 [[nodiscard]]
constexpr bool operator==(
matrix<E> const &rhs)
const noexcept
252 return _col0 == rhs._col0 && _col1 == rhs._col1 && _col2 == rhs._col2 && _col3 == rhs._col3;
264 hilet s0c0 = _col0 * _col1.yxwz();
270 hilet s1c1 = _col0 * _col2.yxwz();
271 hilet s0c0s1c1 = hsub(s0c0, s1c1);
277 hilet s2c2 = _col0 * _col3.yxwz();
283 hilet s3c3 = _col1 * _col2.yxwz();
284 hilet s2c2s3c3 = hsub(s2c2, s3c3);
290 hilet s4c4 = _col1 * _col3.yxwz();
296 hilet s5c5 = _col2 * _col3.yxwz();
297 hilet s4c4s5c5 = hsub(s4c4, s5c5);
305 hilet s0123 = s0c0s1c1.xz00() + s2c2s3c3._00xz();
306 hilet s45__ = s4c4s5c5.xz00();
308 hilet c5432 = s4c4s5c5.wy00() + s2c2s3c3._00wy();
309 hilet c10__ = s0c0s1c1.wy00();
311 hilet det_prod_half0 = neg<0b0010>(s0123 * c5432);
312 hilet det_prod_half1 = neg<0b0001>(s45__ * c10__);
314 hilet det_sum0 = hadd(det_prod_half0, det_prod_half1);
315 hilet det_sum1 = hadd(det_sum0, det_sum0);
316 hilet det = hadd(det_sum1, det_sum1).xxxx();
318 if (det.x() == 0.0f) {
322 hilet invdet = rcp(det);
324 hilet t = transpose(*
this);
331 auto tmp_c5543 = neg<0b1010>(c5432.xxyz());
332 auto tmp_c4221 = neg<0b0101>(c5432.yww0() + c10__._000x());
333 auto tmp_c3100 = neg<0b1010>(c5432.z000() + c10__._0xyy());
334 hilet inv_col0 = ((t._col1.yxxx() * tmp_c5543) + (t._col1.zzyy() * tmp_c4221) + (t._col1.wwwz() * tmp_c3100)) * invdet;
340 tmp_c5543 = -tmp_c5543;
341 tmp_c4221 = -tmp_c4221;
342 tmp_c3100 = -tmp_c3100;
343 hilet inv_col1 = ((t._col0.yxxx() * tmp_c5543) + (t._col0.zzyy() * tmp_c4221) + (t._col0.wwwz() * tmp_c3100)) * invdet;
349 auto tmp_s5543 = neg<0b1010>(s45__.yyx0() + s0123._000w());
350 auto tmp_s4221 = neg<0b0101>(s45__.x000() + s0123._0zzy());
351 auto tmp_s3100 = neg<0b1010>(s0123.wyxx());
352 hilet inv_col2 = ((t._col3.yxxx() * tmp_s5543) + (t._col3.zzyy() * tmp_s4221) + (t._col3.wwwz() * tmp_s3100)) * invdet;
358 tmp_s5543 = -tmp_s5543;
359 tmp_s4221 = -tmp_s4221;
360 tmp_s3100 = -tmp_s3100;
361 hilet inv_col3 = ((t._col2.yxxx() * tmp_s5543) + (t._col2.zzyy() * tmp_s4221) + (t._col2.wwwz() * tmp_s3100)) * invdet;
363 return {inv_col0, inv_col1, inv_col2, inv_col3};
constexpr corner_radii operator*(corner_radii const &rhs) const noexcept
Transform a float by the scaling factor of the matrix.
Definition matrix.hpp:161
constexpr float operator*(float const &rhs) const noexcept
Transform a float by the scaling factor of the matrix.
Definition matrix.hpp:147