2
3
4
5
6
7
8
9
10
11
12
13
14
15
17#ifndef MIR_GEOMETRY_DISPLACEMENT_H_
18#define MIR_GEOMETRY_DISPLACEMENT_H_
44 Displacement&
operator=(Displacement
const&) =
default;
47 explicit constexpr Displacement(Displacement<U>
const& other)
noexcept
48 :
dx{DeltaX<T>{other.dx}},
49 dy{DeltaY<T>{other.dy}}
53 template<
typename DeltaXType,
typename DeltaYType>
56 template <
typename Q = T>
57 constexpr typename std::enable_if<std::is_integral<Q>::value,
long long>::
type length_squared()
const
59 long long x =
dx.as_value(), y =
dy.as_value();
63 template <
typename Q = T>
66 T x =
dx.as_value(), y =
dy.as_value();
75inline constexpr bool operator==(Displacement<T>
const& lhs, Displacement<T>
const& rhs)
77 return lhs.dx == rhs.dx && lhs.dy == rhs.dy;
81inline constexpr bool operator!=(Displacement<T>
const& lhs, Displacement<T>
const& rhs)
83 return lhs.dx != rhs.dx || lhs.dy != rhs.dy;
87std::ostream& operator<<(std::ostream& out, Displacement<T>
const& value)
89 out <<
'(' << value.dx <<
", " << value.dy <<
')';
94inline constexpr Displacement<T>
operator+(Displacement<T>
const& lhs, Displacement<T>
const& rhs)
96 return Displacement<T>{lhs.dx + rhs.dx, lhs.dy + rhs.dy};
100inline constexpr Displacement<T>
operator-(Displacement<T>
const& lhs, Displacement<T>
const& rhs)
102 return Displacement<T>{lhs.dx - rhs.dx, lhs.dy - rhs.dy};
106inline constexpr Displacement<T>
operator-(Displacement<T>
const& rhs)
108 return Displacement<T>{-rhs.dx, -rhs.dy};
112inline constexpr Point<T>
operator+(Point<T>
const& lhs, Displacement<T>
const& rhs)
114 return Point<T>{lhs.x + rhs.dx, lhs.y + rhs.dy};
118inline constexpr Point<T>
operator+(Displacement<T>
const& lhs, Point<T>
const& rhs)
120 return Point<T>{rhs.x + lhs.dx, rhs.y + lhs.dy};
124inline constexpr Point<T>
operator-(Point<T>
const& lhs, Displacement<T>
const& rhs)
126 return Point<T>{lhs.x - rhs.dx, lhs.y - rhs.dy};
130inline constexpr Displacement<T>
operator-(Point<T>
const& lhs, Point<T>
const& rhs)
132 return Displacement<T>{lhs.x - rhs.x, lhs.y - rhs.y};
136inline constexpr Point<T>&
operator+=(Point<T>& lhs, Displacement<T>
const& rhs)
138 return lhs = lhs + rhs;
142inline constexpr Point<T>&
operator-=(Point<T>& lhs, Displacement<T>
const& rhs)
144 return lhs = lhs - rhs;
148inline bool operator<(Displacement<T>
const& lhs, Displacement<T>
const& rhs)
150 return lhs.length_squared() < rhs.length_squared();
153template<
typename T,
typename Scalar>
154inline constexpr Displacement<T>
operator*(Scalar scale, Displacement<T>
const& disp)
156 return Displacement<T>{scale*disp.dx, scale*disp.dy};
159template<
typename T,
typename Scalar>
160inline constexpr Displacement<T>
operator*(Displacement<T>
const& disp, Scalar scale)
168 return Displacement<T>{size.width.as_value(), size.height.as_value()};
174 return Size<T>{disp.dx.as_value(), disp.dy.as_value()};
180 return Displacement<T>{point.x.as_value(), point.y.as_value()};
184inline constexpr Point<T>
as_point(Displacement<T>
const& disp)
186 return Point<T>{disp.dx.as_value(), disp.dy.as_value()};
constexpr Displacement< T > operator-(Displacement< T > const &rhs)
Definition: displacement.h:106
constexpr Point< T > operator+(Displacement< T > const &lhs, Point< T > const &rhs)
Definition: displacement.h:118
constexpr Point< T > & operator-=(Point< T > &lhs, Displacement< T > const &rhs)
Definition: displacement.h:142
constexpr Displacement< T > as_displacement(Point< T > const &point)
Definition: displacement.h:178
constexpr bool operator==(Displacement< T > const &lhs, Displacement< T > const &rhs)
Definition: displacement.h:75
bool operator<(Displacement< T > const &lhs, Displacement< T > const &rhs)
Definition: displacement.h:148
constexpr Point< T > operator-(Point< T > const &lhs, Displacement< T > const &rhs)
Definition: displacement.h:124
constexpr Displacement< T > operator-(Point< T > const &lhs, Point< T > const &rhs)
Definition: displacement.h:130
constexpr Displacement< T > operator*(Displacement< T > const &disp, Scalar scale)
Definition: displacement.h:160
constexpr Displacement< T > operator*(Scalar scale, Displacement< T > const &disp)
Definition: displacement.h:154
constexpr Displacement< T > as_displacement(Size< T > const &size)
Definition: displacement.h:166
constexpr Size< T > as_size(Displacement< T > const &disp)
Definition: displacement.h:172
constexpr bool operator!=(Displacement< T > const &lhs, Displacement< T > const &rhs)
Definition: displacement.h:81
constexpr Point< T > operator+(Point< T > const &lhs, Displacement< T > const &rhs)
Definition: displacement.h:112
constexpr Point< T > & operator+=(Point< T > &lhs, Displacement< T > const &rhs)
Definition: displacement.h:136
constexpr Displacement< T > operator-(Displacement< T > const &lhs, Displacement< T > const &rhs)
Definition: displacement.h:100
constexpr Point< T > as_point(Displacement< T > const &disp)
Definition: displacement.h:184
constexpr Displacement< T > operator+(Displacement< T > const &lhs, Displacement< T > const &rhs)
Definition: displacement.h:94
Basic geometry types. Types for dimensions, displacements, etc. and the operations that they support.
Definition: size.h:27
constexpr Displacement(Displacement< U > const &other) noexcept
Definition: displacement.h:47
Displacement & operator=(Displacement const &)=default
DeltaX< T > dx
Definition: displacement.h:70
DeltaY< T > dy
Definition: displacement.h:71
constexpr Displacement(Displacement const &)=default
constexpr std::enable_if<!std::is_integral< Q >::value, T >::type length_squared() const
Definition: displacement.h:64
constexpr Displacement()
Definition: displacement.h:42
constexpr std::enable_if< std::is_integral< Q >::value, longlong >::type length_squared() const
Definition: displacement.h:57
constexpr Displacement(DeltaXType &&dx, DeltaYType &&dy)
Definition: displacement.h:54