 |
Flutter Impeller
|
|
Go to the documentation of this file.
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)
33 constexpr
TPoint() =
default;
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>>>
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>>>
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>>>
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;
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); }
242 template <
class F,
class I,
class = MixedOp<F, I>>
244 return {p1.
x +
static_cast<F
>(p2.
x), p1.
y +
static_cast<F
>(p2.
y)};
247 template <
class F,
class I,
class = MixedOp<F, I>>
252 template <
class F,
class I,
class = MixedOp<F, I>>
254 return {p1.
x -
static_cast<F
>(p2.
x), p1.
y -
static_cast<F
>(p2.
y)};
257 template <
class F,
class I,
class = MixedOp<F, I>>
259 return {
static_cast<F
>(p1.
x) - p2.
x,
static_cast<F
>(p1.
y) - p2.
y};
262 template <
class F,
class I,
class = MixedOp<F, I>>
264 return {p1.
x *
static_cast<F
>(p2.
x), p1.
y *
static_cast<F
>(p2.
y)};
267 template <
class F,
class I,
class = MixedOp<F, I>>
272 template <
class F,
class I,
class = MixedOp<F, I>>
274 return {p1.
x /
static_cast<F
>(p2.
x), p1.
y /
static_cast<F
>(p2.
y)};
277 template <
class F,
class I,
class = MixedOp<F, I>>
279 return {
static_cast<F
>(p1.
x) / p2.
x,
static_cast<F
>(p1.
y) / p2.
y};
284 template <
class T,
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
289 template <
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};
296 template <
class T,
class U>
301 template <
class T,
class U>
303 return {
static_cast<T
>(s.
width) - p.
x,
static_cast<T
>(s.
height) - p.
y};
306 template <
class T,
class U>
311 template <
class T,
class U>
313 return {
static_cast<T
>(s.
width) / p.
x,
static_cast<T
>(s.
height) / p.
y};
321 using Quad = std::array<Point, 4>;
324 #undef ONLY_ON_FLOAT_M
333 out <<
"(" << p.
x <<
", " << p.
y <<
")";
339 #endif // FLUTTER_IMPELLER_GEOMETRY_POINT_H_
TPoint operator-=(const TSize< U > &s)
constexpr TPoint Ceil() const
constexpr TPoint(Type x, Type y)
TPoint operator+=(const TSize< U > &s)
constexpr TPoint Lerp(const TPoint &p, Scalar t) const
TPoint operator*=(U scale)
constexpr TPoint Min(const TPoint &p) const
static constexpr TPoint Round(const TPoint< U > &other)
constexpr TPoint operator*(const TSize< U > &s) const
constexpr TPoint()=default
TPoint operator/=(const TPoint< U > &p)
std::ostream & operator<<(std::ostream &out, const impeller::Color &c)
TPoint operator*=(const TPoint< U > &p)
constexpr Color operator*(T value, const Color &c)
TPoint operator/=(const TSize< U > &s)
constexpr TPoint Floor() const
constexpr Type Dot(const TPoint &p) const
constexpr TPoint operator/(U d) const
constexpr TPoint Round() const
constexpr bool IsZero() const
constexpr TPoint operator-() const
constexpr TPoint Reflect(const TPoint &axis) const
std::array< Point, 4 > Quad
constexpr TPoint operator-(const TPoint &p) const
constexpr Radians AngleTo(const TPoint &p) const
constexpr TPoint Max(const TPoint &p) const
constexpr TPoint operator/(const TSize< U > &s) const
#define ONLY_ON_FLOAT_M(Modifiers, Return)
constexpr TPoint(const TPoint< U > &other)
TPoint operator/=(U scale)
constexpr Type Cross(const TPoint &p) const
constexpr Color operator-(T value, const Color &c)
constexpr bool operator==(const TPoint &p) const
constexpr TPoint operator+(const TPoint &p) const
constexpr TPoint Abs() const
constexpr TPoint operator*(const TPoint &p) const
constexpr Type GetLengthSquared() const
constexpr TPoint operator/(const TPoint &p) const
constexpr Type GetLength() const
constexpr TPoint operator*(U scale) const
constexpr bool operator!=(const TPoint &p) const
constexpr Color operator/(T value, const Color &c)
constexpr Type GetDistance(const TPoint &p) const
constexpr TPoint Normalize() const
TPoint operator+=(const TPoint< U > &p)
constexpr TPoint(const TSize< U > &other)
TPoint operator-=(const TPoint< U > &p)
constexpr Type GetDistanceSquared(const TPoint &p) const
constexpr TPoint operator+(const TSize< U > &s) const
static constexpr TPoint< Type > MakeXY(Type x, Type y)
constexpr TPoint operator-(const TSize< U > &s) const
constexpr Color operator+(T value, const Color &c)
TPoint operator*=(const TSize< U > &s)