5 #ifndef FLUTTER_IMPELLER_GEOMETRY_VECTOR_H_
6 #define FLUTTER_IMPELLER_GEOMETRY_VECTOR_H_
51 return {
x / len,
y / len,
z / len};
55 return ((
x * other.
x) + (
y * other.
y) + (
z * other.
z));
59 return {std::fabs(
x), std::fabs(
y), std::fabs(
z)};
64 (
y * other.
z) - (
z * other.
y),
65 (
z * other.
x) - (
x * other.
z),
66 (
x * other.
y) - (
y * other.
x)
71 return {std::min(
x, p.
x), std::min(
y, p.
y), std::min(
z, p.
z)};
75 return {std::max(
x, p.
x), std::max(
y, p.
y), std::max(
z, p.
z)};
79 return {std::floor(
x), std::floor(
y), std::floor(
z)};
83 return {std::ceil(
x), std::ceil(
y), std::ceil(
z)};
87 return {std::round(
x), std::round(
y), std::round(
z)};
91 return v.
x ==
x && v.
y ==
y && v.
z ==
z;
95 return v.
x !=
x || v.
y !=
y || v.
z !=
z;
119 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
134 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
164 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
166 return Vector3(
x * scale,
y * scale,
z * scale);
173 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
175 return Vector3(
x / scale,
y / scale,
z / scale);
179 return *
this + (v - *
this) * t;
197 aScale * a.
x + bScale *
b.x,
198 aScale * a.
y + bScale *
b.y,
199 aScale * a.
z + bScale *
b.z,
208 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
213 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
218 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
223 template <
class U,
class = std::enable_if_t<std::is_arithmetic_v<U>>>
246 :
x(c.red),
y(c.green),
z(c.blue),
w(c.alpha) {}
255 constexpr
Vector4(std::array<Scalar, 4> values)
256 :
x(values[0]),
y(values[1]),
z(values[2]),
w(values[3]) {}
259 return std::isfinite(
x) && std::isfinite(
y) && std::isfinite(
z) &&
264 const Scalar inverse = 1.0f / sqrt(
x *
x +
y *
y +
z *
z +
w *
w);
265 return Vector4(
x * inverse,
y * inverse,
z * inverse,
w * inverse);
269 return (
x == v.
x) && (
y == v.
y) && (
z == v.
z) && (
w == v.
w);
273 return (
x != v.
x) || (
y != v.
y) || (
z != v.
z) || (
w != v.
w);
293 return {std::min(
x, p.
x), std::min(
y, p.
y), std::min(
z, p.
z),
298 return {std::max(
x, p.
x), std::max(
y, p.
y), std::max(
z, p.
z),
303 return {std::floor(
x), std::floor(
y), std::floor(
z), std::floor(
w)};
307 return {std::ceil(
x), std::ceil(
y), std::ceil(
z), std::ceil(
w)};
311 return {std::round(
x), std::round(
y), std::round(
z), std::round(
w)};
315 return *
this + (v - *
this) * t;
323 static_assert(
sizeof(Vector3) == 3 *
sizeof(
Scalar));
324 static_assert(
sizeof(Vector4) == 4 *
sizeof(
Scalar));
331 out <<
"(" << p.
x <<
", " << p.
y <<
", " << p.
z <<
")";
336 out <<
"(" << p.
x <<
", " << p.
y <<
", " << p.
z <<
", " << p.
w <<
")";
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::ostream & operator<<(std::ostream &out, const impeller::Arc &a)
Vector3 Min(const Vector3 &p) const
Vector3 Normalize() const
constexpr Vector3 operator-(const Vector3 &v) const
constexpr Vector3 Lerp(const Vector3 &v, Scalar t) const
constexpr Vector3 operator*=(U scale)
constexpr Vector3 operator*(U scale) const
constexpr Vector3 Cross(const Vector3 &other) const
constexpr Vector3(Scalar x, Scalar y, Scalar z)
constexpr Vector3 operator/(const Vector3 &v) const
constexpr Vector3 operator-() const
constexpr Vector3(const Color &c)
constexpr Vector3(Scalar x, Scalar y)
constexpr Vector3(const Size &s)
constexpr Vector3 operator+(const Vector3 &v) const
std::string ToString() const
constexpr Vector3 operator+=(const Vector3 &p)
constexpr Vector3 operator-(Scalar s) const
constexpr Vector3 operator/=(U scale)
constexpr bool operator==(const Vector3 &v) const
constexpr Vector3 operator+(Scalar s) const
constexpr Vector3 operator/=(const Vector3 &p)
constexpr Vector3 operator/(U scale) const
constexpr bool operator!=(const Vector3 &v) const
static constexpr Vector3 Combine(const Vector3 &a, Scalar aScale, const Vector3 &b, Scalar bScale)
constexpr Vector3(const Point &p)
Vector3 Max(const Vector3 &p) const
constexpr Scalar Dot(const Vector3 &other) const
constexpr Vector3 operator*=(const Vector3 &p)
constexpr Vector3 operator*(const Vector3 &v) const
constexpr Vector3 operator-=(const Vector3 &p)
constexpr Vector4(const Point &p)
constexpr Vector4 Min(const Vector4 &p) const
constexpr Vector4(Scalar x, Scalar y, Scalar z, Scalar w)
constexpr Vector4 Lerp(const Vector4 &v, Scalar t) const
Vector4 Normalize() const
constexpr Vector4 operator+(const Vector4 &v) const
std::string ToString() const
constexpr Vector4(std::array< Scalar, 4 > values)
constexpr Vector4(const Color &c)
constexpr Vector4 Max(const Vector4 &p) const
constexpr bool operator!=(const Vector4 &v) const
constexpr Vector4 operator-(const Vector4 &v) const
constexpr Vector4 operator*(const Vector4 &v) const
constexpr Vector2 xy() const
constexpr Vector4(const Vector3 &v)
constexpr Vector4 operator*(Scalar f) const
constexpr bool operator==(const Vector4 &v) const