5#ifndef FLUTTER_IMPELLER_GEOMETRY_POINT_H_
6#define FLUTTER_IMPELLER_GEOMETRY_POINT_H_
21#define ONLY_ON_FLOAT_M(Modifiers, Return) \
22 template <typename U = T> \
23 Modifiers std::enable_if_t<std::is_floating_point_v<U>, Return>
24#define ONLY_ON_FLOAT(Return) DL_ONLY_ON_FLOAT_M(, Return)
50 return TPoint{
static_cast<Type>(std::round(other.
x)),
51 static_cast<Type>(std::round(other.
y))};
55 return p.x ==
x && p.y ==
y;
59 return p.x !=
x || p.y !=
y;
64 x +=
static_cast<Type>(p.x);
65 y +=
static_cast<Type>(p.y);
71 x +=
static_cast<Type>(
s.width);
72 y +=
static_cast<Type>(
s.height);
78 x -=
static_cast<Type>(p.x);
79 y -=
static_cast<Type>(p.y);
85 x -=
static_cast<Type>(
s.width);
86 y -=
static_cast<Type>(
s.height);
92 x *=
static_cast<Type>(p.x);
93 y *=
static_cast<Type>(p.y);
99 x *=
static_cast<Type>(
s.width);
100 y *=
static_cast<Type>(
s.height);
104 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
113 x /=
static_cast<Type>(p.x);
114 y /=
static_cast<Type>(p.y);
120 x /=
static_cast<Type>(
s.width);
121 y /=
static_cast<Type>(
s.height);
125 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
135 return {
x + p.x,
y + p.y};
140 return {
x +
static_cast<Type>(
s.width),
y +
static_cast<Type>(
s.height)};
144 return {
x - p.x,
y - p.y};
149 return {
x -
static_cast<Type>(
s.width),
y -
static_cast<Type>(
s.height)};
152 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
158 return {
x * p.x,
y * p.y};
163 return {
x *
static_cast<Type>(
s.width),
y *
static_cast<Type>(
s.height)};
166 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
168 return {
static_cast<Type>(
x /
d),
static_cast<Type>(
y /
d)};
172 return {
x / p.x,
y / p.y};
177 return {
x /
static_cast<Type>(
s.width),
y /
static_cast<Type>(
s.height)};
183 return dx * dx + dy * dy;
187 return {std::min<Type>(
x, p.x), std::min<Type>(
y, p.y)};
191 return {std::max<Type>(
x, p.x), std::max<Type>(
y, p.y)};
216 constexpr TPoint Abs()
const {
return {std::fabs(
x), std::fabs(
y)}; }
223 return *
this - axis * this->
Dot(axis) * 2;
231 return *
this + (p - *
this) * t;
234 constexpr bool IsZero()
const {
return x == 0 &&
y == 0; }
237 IsFinite()
const {
return std::isfinite(
x) && std::isfinite(
y); }
242template <
class F,
class I,
class = MixedOp<F, I>>
244 return {p1.
x +
static_cast<F>(p2.
x), p1.
y +
static_cast<F>(p2.
y)};
247template <
class F,
class I,
class = MixedOp<F, I>>
252template <
class F,
class I,
class = MixedOp<F, I>>
254 return {p1.
x -
static_cast<F>(p2.
x), p1.
y -
static_cast<F>(p2.
y)};
257template <
class F,
class I,
class = MixedOp<F, I>>
259 return {
static_cast<F>(p1.
x) - p2.
x,
static_cast<F>(p1.
y) - p2.
y};
262template <
class F,
class I,
class = MixedOp<F, I>>
264 return {p1.
x *
static_cast<F>(p2.
x), p1.
y *
static_cast<F>(p2.
y)};
267template <
class F,
class I,
class = MixedOp<F, I>>
272template <
class F,
class I,
class = MixedOp<F, I>>
274 return {p1.
x /
static_cast<F>(p2.
x), p1.
y /
static_cast<F>(p2.
y)};
277template <
class F,
class I,
class = MixedOp<F, I>>
279 return {
static_cast<F>(p1.
x) / p2.
x,
static_cast<F>(p1.
y) / p2.
y};
284template <
class T,
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
289template <
class T,
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
291 return {
static_cast<T>(
s) / p.x,
static_cast<T>(
s) / p.y};
296template <
class T,
class U>
301template <
class T,
class U>
303 return {
static_cast<T>(
s.width) - p.x,
static_cast<T>(
s.height) - p.y};
306template <
class T,
class U>
311template <
class T,
class U>
313 return {
static_cast<T>(
s.width) / p.x,
static_cast<T>(
s.height) / p.y};
321using Quad = std::array<Point, 4>;
324#undef ONLY_ON_FLOAT_M
333 out <<
"(" << p.x <<
", " << p.y <<
")";
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
#define ONLY_ON_FLOAT_M(Modifiers, Return)
constexpr Color operator-(T value, const Color &c)
constexpr Color operator/(T value, const Color &c)
constexpr Color operator+(T value, const Color &c)
constexpr Color operator*(T value, const Color &c)
std::array< Point, 4 > Quad
std::ostream & operator<<(std::ostream &out, const impeller::Color &c)
constexpr TPoint Abs() const
static constexpr TPoint Round(const TPoint< U > &other)
constexpr TPoint Max(const TPoint &p) const
TPoint operator/=(U scale)
TPoint operator-=(const TSize< U > &s)
constexpr Type GetLength() const
constexpr TPoint operator/(const TSize< U > &s) const
constexpr TPoint Ceil() const
constexpr bool operator!=(const TPoint &p) const
constexpr TPoint(Type x, Type y)
constexpr TPoint Normalize() const
constexpr Type Cross(const TPoint &p) const
constexpr bool IsZero() const
constexpr Type GetLengthSquared() const
constexpr Type GetDistance(const TPoint &p) const
constexpr TPoint Lerp(const TPoint &p, Scalar t) const
TPoint operator+=(const TSize< U > &s)
constexpr TPoint operator-(const TPoint &p) const
constexpr TPoint operator/(U d) const
static constexpr TPoint< Type > MakeXY(Type x, Type y)
constexpr TPoint Floor() const
constexpr TPoint operator*(const TSize< U > &s) const
constexpr TPoint()=default
constexpr bool operator==(const TPoint &p) const
constexpr TPoint operator/(const TPoint &p) const
constexpr TPoint operator+(const TSize< U > &s) const
TPoint operator/=(const TPoint< U > &p)
constexpr TPoint Round() const
TPoint operator+=(const TPoint< U > &p)
constexpr TPoint(const TPoint< U > &other)
constexpr TPoint operator-(const TSize< U > &s) const
constexpr TPoint operator+(const TPoint &p) const
TPoint operator*=(const TPoint< U > &p)
constexpr TPoint Reflect(const TPoint &axis) const
constexpr TPoint Min(const TPoint &p) const
TPoint operator/=(const TSize< U > &s)
TPoint operator-=(const TPoint< U > &p)
constexpr TPoint operator-() const
constexpr TPoint(const TSize< U > &other)
TPoint operator*=(U scale)
constexpr Type Dot(const TPoint &p) const
constexpr Type GetDistanceSquared(const TPoint &p) const
constexpr Radians AngleTo(const TPoint &p) const
TPoint operator*=(const TSize< U > &s)
constexpr TPoint operator*(const TPoint &p) const
constexpr TPoint operator*(U scale) const