5 #ifndef FLUTTER_IMPELLER_GEOMETRY_POINT_H_
6 #define FLUTTER_IMPELLER_GEOMETRY_POINT_H_
13 #include <type_traits>
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)
42 static_cast<
Type>(other.height)) {}
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);
78 x -=
static_cast<Type>(p.
x);
79 y -=
static_cast<Type>(p.
y);
92 x *=
static_cast<Type>(p.
x);
93 y *=
static_cast<Type>(p.
y);
104 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
106 x *=
static_cast<Type>(scale);
107 y *=
static_cast<Type>(scale);
113 x /=
static_cast<Type>(p.
x);
114 y /=
static_cast<Type>(p.
y);
125 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
127 x /=
static_cast<Type>(scale);
128 y /=
static_cast<Type>(scale);
135 return {
x + p.
x,
y + p.
y};
144 return {
x - p.
x,
y - p.
y};
152 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
154 return {
static_cast<Type>(
x * scale),
static_cast<Type>(
y * scale)};
158 return {
x * p.
x,
y * p.
y};
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};
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)};
213 return {
x / length,
y / length};
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; }
243 IsFinite()
const {
return std::isfinite(
x) && std::isfinite(
y); }
248 template <
class F,
class I,
class = MixedOp<F, I>>
250 return {p1.
x +
static_cast<F
>(p2.
x), p1.
y +
static_cast<F
>(p2.
y)};
253 template <
class F,
class I,
class = MixedOp<F, I>>
258 template <
class F,
class I,
class = MixedOp<F, I>>
260 return {p1.
x -
static_cast<F
>(p2.
x), p1.
y -
static_cast<F
>(p2.
y)};
263 template <
class F,
class I,
class = MixedOp<F, I>>
265 return {
static_cast<F
>(p1.
x) - p2.
x,
static_cast<F
>(p1.
y) - p2.
y};
268 template <
class F,
class I,
class = MixedOp<F, I>>
270 return {p1.
x *
static_cast<F
>(p2.
x), p1.
y *
static_cast<F
>(p2.
y)};
273 template <
class F,
class I,
class = MixedOp<F, I>>
278 template <
class F,
class I,
class = MixedOp<F, I>>
280 return {p1.
x /
static_cast<F
>(p2.
x), p1.
y /
static_cast<F
>(p2.
y)};
283 template <
class F,
class I,
class = MixedOp<F, I>>
285 return {
static_cast<F
>(p1.
x) / p2.
x,
static_cast<F
>(p1.
y) / p2.
y};
290 template <
class T,
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
295 template <
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};
302 template <
class T,
class U>
307 template <
class T,
class U>
309 return {
static_cast<T
>(s.
width) - p.
x,
static_cast<T
>(s.
height) - p.
y};
312 template <
class T,
class U>
317 template <
class T,
class U>
319 return {
static_cast<T
>(s.
width) / p.
x,
static_cast<T
>(s.
height) / p.
y};
324 return {p.
x - v, p.
y - v};
332 using Quad = std::array<Point, 4>;
343 #undef ONLY_ON_FLOAT_M
352 out <<
"(" << p.
x <<
", " << p.
y <<
")";
constexpr Color operator-(T value, const Color &c)
constexpr Color operator/(T value, const Color &c)
constexpr Color operator+(T value, const Color &c)
static constexpr impeller::Vector2 kQuadrantAxes[4]
constexpr Color operator*(T value, const Color &c)
std::array< Point, 4 > Quad
std::ostream & operator<<(std::ostream &out, const impeller::Arc &a)
#define ONLY_ON_FLOAT_M(Modifiers, Return)
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
static constexpr TPoint< Type > MakeXY(Type x, Type y)
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
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