5#ifndef FLUTTER_IMPELLER_GEOMETRY_POINT_H_
6#define FLUTTER_IMPELLER_GEOMETRY_POINT_H_
22#define ONLY_ON_FLOAT_M(Modifiers, Return) \
23 template <typename U = T> \
24 Modifiers std::enable_if_t<std::is_floating_point_v<U>, Return>
25#define ONLY_ON_FLOAT(Return) DL_ONLY_ON_FLOAT_M(, Return)
51 return TPoint{
static_cast<Type>(std::round(other.
x)),
52 static_cast<Type>(std::round(other.
y))};
56 return p.
x ==
x && p.
y ==
y;
60 return p.
x !=
x || p.
y !=
y;
65 x +=
static_cast<Type>(p.
x);
66 y +=
static_cast<Type>(p.
y);
79 x -=
static_cast<Type>(p.
x);
80 y -=
static_cast<Type>(p.
y);
93 x *=
static_cast<Type>(p.
x);
94 y *=
static_cast<Type>(p.
y);
105 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
107 x *=
static_cast<Type>(scale);
108 y *=
static_cast<Type>(scale);
114 x /=
static_cast<Type>(p.
x);
115 y /=
static_cast<Type>(p.
y);
126 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
128 x /=
static_cast<Type>(scale);
129 y /=
static_cast<Type>(scale);
136 return {
x + p.
x,
y + p.
y};
145 return {
x - p.
x,
y - p.
y};
153 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
155 return {
static_cast<Type>(
x * scale),
static_cast<Type>(
y * scale)};
159 return {
x * p.
x,
y * p.
y};
167 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
169 return {
static_cast<Type>(
x /
d),
static_cast<Type>(
y /
d)};
173 return {
x / p.
x,
y / p.
y};
184 return dx * dx + dy * dy;
188 return {std::min<Type>(
x, p.
x), std::min<Type>(
y, p.
y)};
192 return {std::max<Type>(
x, p.
x), std::max<Type>(
y, p.
y)};
206 return static_cast<double>(
x) *
x +
static_cast<double>(
y) *
y;
246 if (dot >= uLengthSquared) {
271 return (cross / uLengthSquared) * cross;
293 constexpr TPoint Abs()
const {
return {std::fabs(
x), std::fabs(
y)}; }
305 return (p1 - p0).Cross(p2 - p0);
311 return *
this - axis * this->
Dot(axis) * 2;
315 const auto cos_a = std::cosf(angle.
radians);
316 const auto sin_a = std::sinf(angle.
radians);
317 return {
x * cos_a -
y * sin_a,
x * sin_a +
y * cos_a};
335 return *
this + (p - *
this) * t;
338 constexpr bool IsZero()
const {
return x == 0 &&
y == 0; }
341 IsFinite()
const {
return std::isfinite(
x) && std::isfinite(
y); }
346template <
class F,
class I,
class = MixedOp<F, I>>
348 return {p1.
x +
static_cast<F
>(p2.
x), p1.
y +
static_cast<F
>(p2.
y)};
351template <
class F,
class I,
class = MixedOp<F, I>>
356template <
class F,
class I,
class = MixedOp<F, I>>
358 return {p1.
x -
static_cast<F
>(p2.
x), p1.
y -
static_cast<F
>(p2.
y)};
361template <
class F,
class I,
class = MixedOp<F, I>>
363 return {
static_cast<F
>(p1.
x) - p2.
x,
static_cast<F
>(p1.
y) - p2.
y};
366template <
class F,
class I,
class = MixedOp<F, I>>
368 return {p1.
x *
static_cast<F
>(p2.
x), p1.
y *
static_cast<F
>(p2.
y)};
371template <
class F,
class I,
class = MixedOp<F, I>>
376template <
class F,
class I,
class = MixedOp<F, I>>
378 return {p1.
x /
static_cast<F
>(p2.
x), p1.
y /
static_cast<F
>(p2.
y)};
381template <
class F,
class I,
class = MixedOp<F, I>>
383 return {
static_cast<F
>(p1.
x) / p2.
x,
static_cast<F
>(p1.
y) / p2.
y};
388template <
class T,
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
393template <
class T,
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
395 return {
static_cast<T
>(s) / p.
x,
static_cast<T
>(s) / p.
y};
400template <
class T,
class U>
405template <
class T,
class U>
407 return {
static_cast<T
>(s.
width) - p.
x,
static_cast<T
>(s.
height) - p.
y};
410template <
class T,
class U>
415template <
class T,
class U>
417 return {
static_cast<T
>(s.
width) / p.
x,
static_cast<T
>(s.
height) / p.
y};
422 return {p.
x - v, p.
y - v};
430using Quad = std::array<Point, 4>;
441#undef ONLY_ON_FLOAT_M
450 out <<
"(" << p.
x <<
", " << p.
y <<
")";
#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)
TPoint< int32_t > IPoint32
static constexpr impeller::Vector2 kQuadrantAxes[4]
constexpr Color operator*(T value, const Color &c)
TPoint< uint32_t > UintPoint32
std::array< Point, 4 > Quad
std::ostream & operator<<(std::ostream &out, const impeller::Arc &a)
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)
Type GetDistanceToSegmentSquared(TPoint p0, TPoint p1) const
constexpr Type GetLength() const
constexpr TPoint operator/(const TSize< U > &s) const
constexpr Type GetDistanceToSegment(TPoint p0, TPoint p1) 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 TPoint PerpendicularLeft() 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 PerpendicularRight() const
static constexpr Type Cross(const TPoint &p0, const TPoint &p1, const TPoint &p2)
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