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)
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;
227 const auto cos_a = std::cosf(angle.
radians);
228 const auto sin_a = std::sinf(angle.
radians);
229 return {
x * cos_a -
y * sin_a,
x * sin_a +
y * cos_a};
237 return *
this + (
p - *
this) * t;
240 constexpr bool IsZero()
const {
return x == 0 &&
y == 0; }
248template <
class F,
class I,
class = MixedOp<F, I>>
250 return {p1.
x +
static_cast<F>(p2.
x), p1.
y +
static_cast<F>(p2.
y)};
253template <
class F,
class I,
class = MixedOp<F, I>>
258template <
class F,
class I,
class = MixedOp<F, I>>
260 return {p1.
x -
static_cast<F>(p2.
x), p1.
y -
static_cast<F>(p2.
y)};
263template <
class F,
class I,
class = MixedOp<F, I>>
265 return {
static_cast<F>(p1.
x) - p2.
x,
static_cast<F>(p1.
y) - p2.
y};
268template <
class F,
class I,
class = MixedOp<F, I>>
270 return {p1.
x *
static_cast<F>(p2.
x), p1.
y *
static_cast<F>(p2.
y)};
273template <
class F,
class I,
class = MixedOp<F, I>>
278template <
class F,
class I,
class = MixedOp<F, I>>
280 return {p1.
x /
static_cast<F>(p2.
x), p1.
y /
static_cast<F>(p2.
y)};
283template <
class F,
class I,
class = MixedOp<F, I>>
285 return {
static_cast<F>(p1.
x) / p2.
x,
static_cast<F>(p1.
y) / p2.
y};
290template <
class T,
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
295template <
class T,
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
297 return {
static_cast<T>(
s) /
p.x,
static_cast<T>(
s) /
p.y};
302template <
class T,
class U>
307template <
class T,
class U>
309 return {
static_cast<T>(
s.width) -
p.x,
static_cast<T>(
s.height) -
p.y};
312template <
class T,
class U>
317template <
class T,
class U>
319 return {
static_cast<T>(
s.width) /
p.x,
static_cast<T>(
s.height) /
p.y};
327using Quad = std::array<Point, 4>;
330#undef ONLY_ON_FLOAT_M
339 out <<
"(" <<
p.x <<
", " <<
p.y <<
")";
static void round(SkPoint *p)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
#define ONLY_ON_FLOAT_M(Modifiers, Return)
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
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
SINT bool isfinite(const Vec< N, T > &v)
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
SIN Vec< N, float > floor(const Vec< N, float > &x)
SIN Vec< N, float > ceil(const Vec< N, float > &x)
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 Rotate(const Radians &angle) 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