17 static_assert(D == 2 || D == 3,
"Only 2D or 3D translation-matrices are supported");
20 using array_type = simd<value_type, 4>;
27 [[nodiscard]]
constexpr operator matrix<2>()
const noexcept
28 requires std::is_same_v<value_type, float> and (D == 2)
31 hilet ones = array_type::broadcast(value_type{1});
32 return matrix<2>{ones.x000(), ones._0y00(), ones._00z0(), ones._000w() + _v};
35 [[nodiscard]]
constexpr operator matrix<3>()
const noexcept
36 requires std::is_same_v<value_type, float>
39 hilet ones = array_type::broadcast(value_type{1});
40 return matrix<3>{ones.x000(), ones._0y00(), ones._00z0(), ones._000w() + _v};
43 [[nodiscard]]
constexpr translate() noexcept : _v() {}
47 [[nodiscard]]
constexpr explicit operator array_type()
const noexcept
53 [[nodiscard]]
constexpr explicit translate(array_type
const& other) noexcept : _v(other)
58 [[nodiscard]]
constexpr explicit translate(axis_aligned_rectangle<value_type>
const& other) noexcept :
59 _v(
static_cast<array_type
>(get<0>(other)).xy00())
64 [[nodiscard]]
constexpr explicit translate(axis_aligned_rectangle<value_type>
const& other, value_type z)
noexcept
66 : _v(
static_cast<array_type
>(get<0>(other)).xy00())
82 _v(
static_cast<array_type
>(other))
98 _v(
static_cast<array_type
>(other).xyz0())
103 [[nodiscard]]
constexpr translate(value_type x, value_type y)
noexcept
105 : _v(x, y, value_type{0}, value_type{0})
109 [[nodiscard]]
constexpr translate(value_type x, value_type y, value_type z = value_type{0})
noexcept
111 : _v(x, y, z, value_type{0})
115 [[nodiscard]]
constexpr value_type x()
const noexcept
120 [[nodiscard]]
constexpr value_type y()
const noexcept requires(D >= 2)
125 [[nodiscard]]
constexpr value_type z()
const noexcept requires(D >= 3)
137 axis_aligned_rectangle<value_type> src_rectangle,
138 axis_aligned_rectangle<value_type> dst_rectangle,
141 auto x = value_type{0};
142 if (
alignment == horizontal_alignment::left) {
143 x = dst_rectangle.left();
145 }
else if (
alignment == horizontal_alignment::right) {
146 x = dst_rectangle.right() - src_rectangle.width();
148 }
else if (
alignment == horizontal_alignment::center) {
149 x = dst_rectangle.center() - src_rectangle.width() * 0.5f;
155 auto y = value_type{0};
156 if (
alignment == vertical_alignment::bottom) {
157 y = dst_rectangle.bottom();
159 }
else if (
alignment == vertical_alignment::top) {
160 y = dst_rectangle.top() - src_rectangle.height();
162 }
else if (
alignment == vertical_alignment::middle) {
163 y = dst_rectangle.middle() - src_rectangle.height() * 0.5f;
169 return translate{x - src_rectangle.left(), y - src_rectangle.bottom()};
176 hi_axiom(holds_invariant() && rhs.holds_invariant());
181 [[nodiscard]]
constexpr point<value_type,
std::max(D, E)> operator*(point<value_type, E>
const& rhs)
const noexcept
183 hi_axiom(holds_invariant() && rhs.holds_invariant());
184 return point<value_type,
std::max(D, E)>{_v +
static_cast<array_type
>(rhs)};
187 [[nodiscard]]
constexpr axis_aligned_rectangle<value_type>
188 operator*(axis_aligned_rectangle<value_type>
const& rhs)
const noexcept
191 return axis_aligned_rectangle<value_type>{*
this * get<0>(rhs), *
this * get<3>(rhs)};
194 [[nodiscard]]
constexpr rectangle operator*(axis_aligned_rectangle<value_type>
const& rhs)
const noexcept
195 requires std::is_same_v<value_type, float> and (D == 3)
200 [[nodiscard]]
constexpr rectangle operator*(rectangle
const& rhs)
const noexcept
201 requires std::is_same_v<value_type, float>
203 return rectangle{*
this * rhs.origin, rhs.right, rhs.up};
206 [[nodiscard]]
constexpr quad operator*(quad
const& rhs)
const noexcept
207 requires std::is_same_v<value_type, float>
209 return quad{*
this * rhs.p0, *
this * rhs.p1, *
this * rhs.p2, *
this * rhs.p3};
212 [[nodiscard]]
constexpr circle operator*(circle
const& rhs)
const noexcept
213 requires std::is_same_v<value_type, float>
215 return circle{array_type{rhs} + _v};
218 [[nodiscard]]
constexpr line_segment operator*(line_segment
const& rhs)
const noexcept
219 requires std::is_same_v<value_type, float>
221 return line_segment{*
this * rhs.origin(), rhs.direction()};
224 [[nodiscard]]
constexpr translate operator*(identity
const&)
const noexcept
231 [[nodiscard]]
constexpr auto operator*(matrix<E>
const& rhs)
const noexcept
232 requires std::is_same_v<value_type, float>
234 hi_axiom(holds_invariant() && rhs.holds_invariant());
235 return matrix<
std::max(D, E)>{get<0>(rhs), get<1>(rhs), get<2>(rhs), get<3>(rhs) + _v};
239 [[nodiscard]]
constexpr auto operator*(rotate<E>
const& rhs)
const noexcept
240 requires std::is_same_v<value_type, float>
242 return *
this * matrix<E>(rhs);
246 [[nodiscard]]
constexpr auto operator*(translate<value_type, E>
const& rhs)
const noexcept
248 hi_axiom(holds_invariant() && rhs.holds_invariant());
249 return translate<value_type,
std::max(D, E)>{_v +
static_cast<array_type
>(rhs)};
253 [[nodiscard]]
constexpr bool operator==(translate<value_type, E>
const& rhs)
const noexcept
255 hi_axiom(holds_invariant() && rhs.holds_invariant());
256 return equal(_v,
static_cast<array_type
>(rhs));
259 [[nodiscard]]
constexpr translate operator~() const noexcept
261 return translate{-_v};
264 [[nodiscard]]
constexpr bool holds_invariant() const noexcept
266 return _v.w() == value_type{0} && (D == 3 || _v.z() == value_type{0});
269 [[nodiscard]]
friend constexpr translate
round(translate
const& rhs)
noexcept
270 requires std::is_same_v<value_type, float>
272 return translate{
round(rhs._v)};
static constexpr translate align(axis_aligned_rectangle< value_type > src_rectangle, axis_aligned_rectangle< value_type > dst_rectangle, alignment alignment) noexcept
Align a rectangle within another rectangle.
Definition translate.hpp:136