Flutter Impeller
impeller::Vector3 Struct Reference

#include <vector.h>

Public Member Functions

constexpr Vector3 ()
 
constexpr Vector3 (const Color &c)
 
constexpr Vector3 (const Point &p)
 
constexpr Vector3 (const Size &s)
 
constexpr Vector3 (Scalar x, Scalar y)
 
constexpr Vector3 (Scalar x, Scalar y, Scalar z)
 
Scalar GetLength () const
 
Vector3 Normalize () const
 
constexpr Scalar Dot (const Vector3 &other) const
 
Vector3 Abs () const
 
constexpr Vector3 Cross (const Vector3 &other) const
 
Vector3 Min (const Vector3 &p) const
 
Vector3 Max (const Vector3 &p) const
 
Vector3 Floor () const
 
Vector3 Ceil () const
 
Vector3 Round () const
 
constexpr bool operator== (const Vector3 &v) const
 
constexpr bool operator!= (const Vector3 &v) const
 
constexpr Vector3 operator+= (const Vector3 &p)
 
constexpr Vector3 operator-= (const Vector3 &p)
 
constexpr Vector3 operator*= (const Vector3 &p)
 
template<class U , class = std::enable_if_t<std::is_arithmetic_v<U>>>
constexpr Vector3 operator*= (U scale)
 
constexpr Vector3 operator/= (const Vector3 &p)
 
template<class U , class = std::enable_if_t<std::is_arithmetic_v<U>>>
constexpr Vector3 operator/= (U scale)
 
constexpr Vector3 operator- () const
 
constexpr Vector3 operator+ (const Vector3 &v) const
 
constexpr Vector3 operator- (const Vector3 &v) const
 
constexpr Vector3 operator+ (Scalar s) const
 
constexpr Vector3 operator- (Scalar s) const
 
constexpr Vector3 operator* (const Vector3 &v) const
 
template<class U , class = std::enable_if_t<std::is_arithmetic_v<U>>>
constexpr Vector3 operator* (U scale) const
 
constexpr Vector3 operator/ (const Vector3 &v) const
 
template<class U , class = std::enable_if_t<std::is_arithmetic_v<U>>>
constexpr Vector3 operator/ (U scale) const
 
constexpr Vector3 Lerp (const Vector3 &v, Scalar t) const
 
std::string ToString () const
 

Static Public Member Functions

static constexpr Vector3 Combine (const Vector3 &a, Scalar aScale, const Vector3 &b, Scalar bScale)
 

Public Attributes

union {
   struct {
      Scalar   x = 0.0f
 
      Scalar   y = 0.0f
 
      Scalar   z = 0.0f
 
   } 
 
   Scalar   e [3]
 
}; 
 

Detailed Description

Definition at line 20 of file vector.h.

Constructor & Destructor Documentation

◆ Vector3() [1/6]

constexpr impeller::Vector3::Vector3 ( )
inlineconstexpr

Definition at line 30 of file vector.h.

30 {};

Referenced by operator*(), operator+(), operator-(), and operator/().

◆ Vector3() [2/6]

constexpr impeller::Vector3::Vector3 ( const Color c)
inlineconstexpr

Definition at line 32 of file vector.h.

32 : x(c.red), y(c.green), z(c.blue) {}

◆ Vector3() [3/6]

constexpr impeller::Vector3::Vector3 ( const Point p)
inlineconstexpr

Definition at line 34 of file vector.h.

34 : x(p.x), y(p.y) {}

◆ Vector3() [4/6]

constexpr impeller::Vector3::Vector3 ( const Size s)
inlineconstexpr

Definition at line 36 of file vector.h.

36 : x(s.width), y(s.height) {}

◆ Vector3() [5/6]

constexpr impeller::Vector3::Vector3 ( Scalar  x,
Scalar  y 
)
inlineconstexpr

Definition at line 38 of file vector.h.

38 : x(x), y(y) {}

◆ Vector3() [6/6]

constexpr impeller::Vector3::Vector3 ( Scalar  x,
Scalar  y,
Scalar  z 
)
inlineconstexpr

Definition at line 40 of file vector.h.

40 : x(x), y(y), z(z) {}

Member Function Documentation

◆ Abs()

Vector3 impeller::Vector3::Abs ( ) const
inline

Definition at line 58 of file vector.h.

58  {
59  return {std::fabs(x), std::fabs(y), std::fabs(z)};
60  }

References x, y, and z.

◆ Ceil()

Vector3 impeller::Vector3::Ceil ( ) const
inline

Definition at line 82 of file vector.h.

82  {
83  return {std::ceil(x), std::ceil(y), std::ceil(z)};
84  }

References x, y, and z.

Referenced by impeller::testing::TEST().

◆ Combine()

static constexpr Vector3 impeller::Vector3::Combine ( const Vector3 a,
Scalar  aScale,
const Vector3 b,
Scalar  bScale 
)
inlinestaticconstexpr

Make a linear combination of two vectors and return the result.

Parameters
athe first vector.
aScalethe scale to use for the first vector.
bthe second vector.
bScalethe scale to use for the second vector.
Returns
the combined vector.

Definition at line 192 of file vector.h.

195  {
196  return {
197  aScale * a.x + bScale * b.x, //
198  aScale * a.y + bScale * b.y, //
199  aScale * a.z + bScale * b.z, //
200  };
201  }

References impeller::saturated::b, x, y, and z.

Referenced by impeller::Matrix::Decompose().

◆ Cross()

constexpr Vector3 impeller::Vector3::Cross ( const Vector3 other) const
inlineconstexpr

Definition at line 62 of file vector.h.

62  {
63  return {
64  (y * other.z) - (z * other.y), //
65  (z * other.x) - (x * other.z), //
66  (x * other.y) - (y * other.x) //
67  };
68  }

References x, y, and z.

Referenced by impeller::Matrix::MakeLookAt(), and impeller::Quaternion::operator*().

◆ Dot()

constexpr Scalar impeller::Vector3::Dot ( const Vector3 other) const
inlineconstexpr

Definition at line 54 of file vector.h.

54  {
55  return ((x * other.x) + (y * other.y) + (z * other.z));
56  }

References x, y, and z.

Referenced by impeller::Matrix::Decompose(), impeller::Matrix::MakeLookAt(), and impeller::Quaternion::operator*().

◆ Floor()

Vector3 impeller::Vector3::Floor ( ) const
inline

Definition at line 78 of file vector.h.

78  {
79  return {std::floor(x), std::floor(y), std::floor(z)};
80  }

References x, y, and z.

Referenced by impeller::testing::TEST().

◆ GetLength()

Scalar impeller::Vector3::GetLength ( ) const
inline

The length (or magnitude of the vector).

Returns
the calculated length.

Definition at line 47 of file vector.h.

47 { return sqrt(x * x + y * y + z * z); }

References x, y, and z.

Referenced by impeller::Paint::MaskBlurDescriptor::CreateMaskBlur(), impeller::Matrix::Decompose(), impeller::Matrix::GetDirectionScale(), and Normalize().

◆ Lerp()

constexpr Vector3 impeller::Vector3::Lerp ( const Vector3 v,
Scalar  t 
) const
inlineconstexpr

Definition at line 178 of file vector.h.

178  {
179  return *this + (v - *this) * t;
180  }

Referenced by impeller::testing::TEST().

◆ Max()

Vector3 impeller::Vector3::Max ( const Vector3 p) const
inline

Definition at line 74 of file vector.h.

74  {
75  return {std::max(x, p.x), std::max(y, p.y), std::max(z, p.z)};
76  }

References x, y, and z.

Referenced by impeller::Color::Blend(), and impeller::testing::TEST().

◆ Min()

Vector3 impeller::Vector3::Min ( const Vector3 p) const
inline

Definition at line 70 of file vector.h.

70  {
71  return {std::min(x, p.x), std::min(y, p.y), std::min(z, p.z)};
72  }

References x, y, and z.

Referenced by impeller::Color::Blend(), and impeller::testing::TEST().

◆ Normalize()

Vector3 impeller::Vector3::Normalize ( ) const
inline

Definition at line 49 of file vector.h.

49  {
50  const auto len = GetLength();
51  return {x / len, y / len, z / len};
52  }
Scalar GetLength() const
Definition: vector.h:47

References GetLength(), x, y, and z.

Referenced by impeller::Matrix::Decompose(), and impeller::Matrix::GetDirectionScale().

◆ operator!=()

constexpr bool impeller::Vector3::operator!= ( const Vector3 v) const
inlineconstexpr

Definition at line 94 of file vector.h.

94  {
95  return v.x != x || v.y != y || v.z != z;
96  }

References x, y, and z.

◆ operator*() [1/2]

constexpr Vector3 impeller::Vector3::operator* ( const Vector3 v) const
inlineconstexpr

Definition at line 160 of file vector.h.

160  {
161  return Vector3(x * v.x, y * v.y, z * v.z);
162  }
constexpr Vector3()
Definition: vector.h:30

References Vector3(), x, y, and z.

◆ operator*() [2/2]

template<class U , class = std::enable_if_t<std::is_arithmetic_v<U>>>
constexpr Vector3 impeller::Vector3::operator* ( scale) const
inlineconstexpr

Definition at line 165 of file vector.h.

165  {
166  return Vector3(x * scale, y * scale, z * scale);
167  }

References Vector3(), x, y, and z.

◆ operator*=() [1/2]

constexpr Vector3 impeller::Vector3::operator*= ( const Vector3 p)
inlineconstexpr

Definition at line 112 of file vector.h.

112  {
113  x *= p.x;
114  y *= p.y;
115  z *= p.z;
116  return *this;
117  }

References x, y, and z.

◆ operator*=() [2/2]

template<class U , class = std::enable_if_t<std::is_arithmetic_v<U>>>
constexpr Vector3 impeller::Vector3::operator*= ( scale)
inlineconstexpr

Definition at line 120 of file vector.h.

120  {
121  x *= scale;
122  y *= scale;
123  z *= scale;
124  return *this;
125  }

References x, y, and z.

◆ operator+() [1/2]

constexpr Vector3 impeller::Vector3::operator+ ( const Vector3 v) const
inlineconstexpr

Definition at line 144 of file vector.h.

144  {
145  return Vector3(x + v.x, y + v.y, z + v.z);
146  }

References Vector3(), x, y, and z.

◆ operator+() [2/2]

constexpr Vector3 impeller::Vector3::operator+ ( Scalar  s) const
inlineconstexpr

Definition at line 152 of file vector.h.

152  {
153  return Vector3(x + s, y + s, z + s);
154  }

References Vector3(), x, y, and z.

◆ operator+=()

constexpr Vector3 impeller::Vector3::operator+= ( const Vector3 p)
inlineconstexpr

Definition at line 98 of file vector.h.

98  {
99  x += p.x;
100  y += p.y;
101  z += p.z;
102  return *this;
103  }

References x, y, and z.

◆ operator-() [1/3]

constexpr Vector3 impeller::Vector3::operator- ( ) const
inlineconstexpr

Definition at line 142 of file vector.h.

142 { return Vector3(-x, -y, -z); }

References Vector3(), x, y, and z.

◆ operator-() [2/3]

constexpr Vector3 impeller::Vector3::operator- ( const Vector3 v) const
inlineconstexpr

Definition at line 148 of file vector.h.

148  {
149  return Vector3(x - v.x, y - v.y, z - v.z);
150  }

References Vector3(), x, y, and z.

◆ operator-() [3/3]

constexpr Vector3 impeller::Vector3::operator- ( Scalar  s) const
inlineconstexpr

Definition at line 156 of file vector.h.

156  {
157  return Vector3(x - s, y - s, z - s);
158  }

References Vector3(), x, y, and z.

◆ operator-=()

constexpr Vector3 impeller::Vector3::operator-= ( const Vector3 p)
inlineconstexpr

Definition at line 105 of file vector.h.

105  {
106  x -= p.x;
107  y -= p.y;
108  z -= p.z;
109  return *this;
110  }

References x, y, and z.

◆ operator/() [1/2]

constexpr Vector3 impeller::Vector3::operator/ ( const Vector3 v) const
inlineconstexpr

Definition at line 169 of file vector.h.

169  {
170  return Vector3(x / v.x, y / v.y, z / v.z);
171  }

References Vector3(), x, y, and z.

◆ operator/() [2/2]

template<class U , class = std::enable_if_t<std::is_arithmetic_v<U>>>
constexpr Vector3 impeller::Vector3::operator/ ( scale) const
inlineconstexpr

Definition at line 174 of file vector.h.

174  {
175  return Vector3(x / scale, y / scale, z / scale);
176  }

References Vector3(), x, y, and z.

◆ operator/=() [1/2]

constexpr Vector3 impeller::Vector3::operator/= ( const Vector3 p)
inlineconstexpr

Definition at line 127 of file vector.h.

127  {
128  x /= p.x;
129  y /= p.y;
130  z /= p.z;
131  return *this;
132  }

References x, y, and z.

◆ operator/=() [2/2]

template<class U , class = std::enable_if_t<std::is_arithmetic_v<U>>>
constexpr Vector3 impeller::Vector3::operator/= ( scale)
inlineconstexpr

Definition at line 135 of file vector.h.

135  {
136  x /= scale;
137  y /= scale;
138  z /= scale;
139  return *this;
140  }

References x, y, and z.

◆ operator==()

constexpr bool impeller::Vector3::operator== ( const Vector3 v) const
inlineconstexpr

Definition at line 90 of file vector.h.

90  {
91  return v.x == x && v.y == y && v.z == z;
92  }

References x, y, and z.

◆ Round()

Vector3 impeller::Vector3::Round ( ) const
inline

Definition at line 86 of file vector.h.

86  {
87  return {std::round(x), std::round(y), std::round(z)};
88  }

References x, y, and z.

Referenced by impeller::testing::TEST().

◆ ToString()

std::string impeller::Vector3::ToString ( ) const

Definition at line 10 of file vector.cc.

10  {
11  std::stringstream stream;
12  stream << "{" << x << ", " << y << ", " << z << "}";
13  return stream.str();
14 }

References x, y, and z.

Member Data Documentation

◆ 

union { ... }

◆ e

Scalar impeller::Vector3::e[3]

Definition at line 27 of file vector.h.

Referenced by impeller::Matrix::Decompose(), and impeller::Matrix::Matrix().

◆ x

◆ y

◆ z


The documentation for this struct was generated from the following files: