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)
 
constexpr Scalar Length () const
 
constexpr Vector3 Normalize () const
 
constexpr Scalar Dot (const Vector3 &other) const
 
constexpr Vector3 Abs () const
 
constexpr Vector3 Cross (const Vector3 &other) const
 
constexpr Vector3 Min (const Vector3 &p) const
 
constexpr Vector3 Max (const Vector3 &p) const
 
constexpr Vector3 Floor () const
 
constexpr Vector3 Ceil () const
 
constexpr 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 17 of file vector.h.

Constructor & Destructor Documentation

◆ Vector3() [1/6]

constexpr impeller::Vector3::Vector3 ( )
inlineconstexpr

Definition at line 27 of file vector.h.

27 {};

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

◆ Vector3() [2/6]

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

Definition at line 29 of file vector.h.

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

◆ Vector3() [3/6]

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

Definition at line 31 of file vector.h.

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

◆ Vector3() [4/6]

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

Definition at line 33 of file vector.h.

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

◆ Vector3() [5/6]

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

Definition at line 35 of file vector.h.

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

◆ Vector3() [6/6]

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

Definition at line 37 of file vector.h.

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

Member Function Documentation

◆ Abs()

constexpr Vector3 impeller::Vector3::Abs ( ) const
inlineconstexpr

Definition at line 55 of file vector.h.

55  {
56  return {std::fabs(x), std::fabs(y), std::fabs(z)};
57  }

References x, y, and z.

◆ Ceil()

constexpr Vector3 impeller::Vector3::Ceil ( ) const
inlineconstexpr

Definition at line 79 of file vector.h.

79  {
80  return {std::ceil(x), std::ceil(y), std::ceil(z)};
81  }

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 189 of file vector.h.

192  {
193  return {
194  aScale * a.x + bScale * b.x, //
195  aScale * a.y + bScale * b.y, //
196  aScale * a.z + bScale * b.z, //
197  };
198  }

References x, y, and z.

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

◆ Cross()

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

Definition at line 59 of file vector.h.

59  {
60  return {
61  (y * other.z) - (z * other.y), //
62  (z * other.x) - (x * other.z), //
63  (x * other.y) - (y * other.x) //
64  };
65  }

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 51 of file vector.h.

51  {
52  return ((x * other.x) + (y * other.y) + (z * other.z));
53  }

References x, y, and z.

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

◆ Floor()

constexpr Vector3 impeller::Vector3::Floor ( ) const
inlineconstexpr

Definition at line 75 of file vector.h.

75  {
76  return {std::floor(x), std::floor(y), std::floor(z)};
77  }

References x, y, and z.

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

◆ Length()

constexpr Scalar impeller::Vector3::Length ( ) const
inlineconstexpr

The length (or magnitude of the vector).

Returns
the calculated length.

Definition at line 44 of file vector.h.

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

References x, y, and z.

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

◆ Lerp()

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

Definition at line 175 of file vector.h.

175  {
176  return *this + (v - *this) * t;
177  }

Referenced by impeller::scene::ScaleTimelineResolver::Apply(), impeller::testing::TEST(), and impeller::scene::testing::TEST_P().

◆ Max()

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

Definition at line 71 of file vector.h.

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

References x, y, and z.

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

◆ Min()

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

Definition at line 67 of file vector.h.

67  {
68  return {std::min(x, p.x), std::min(y, p.y), std::min(z, p.z)};
69  }

References x, y, and z.

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

◆ Normalize()

constexpr Vector3 impeller::Vector3::Normalize ( ) const
inlineconstexpr

Definition at line 46 of file vector.h.

46  {
47  const auto len = Length();
48  return {x / len, y / len, z / len};
49  }

References Length(), 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 91 of file vector.h.

91  {
92  return v.x != x || v.y != y || v.z != z;
93  }

References x, y, and z.

◆ operator*() [1/2]

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

Definition at line 157 of file vector.h.

157  {
158  return Vector3(x * v.x, y * v.y, z * v.z);
159  }

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 162 of file vector.h.

162  {
163  return Vector3(x * scale, y * scale, z * scale);
164  }

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

◆ operator*=() [1/2]

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

Definition at line 109 of file vector.h.

109  {
110  x *= p.x;
111  y *= p.y;
112  z *= p.z;
113  return *this;
114  }

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 117 of file vector.h.

117  {
118  x *= scale;
119  y *= scale;
120  z *= scale;
121  return *this;
122  }

References x, y, and z.

◆ operator+() [1/2]

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

Definition at line 141 of file vector.h.

141  {
142  return Vector3(x + v.x, y + v.y, z + v.z);
143  }

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

◆ operator+() [2/2]

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

Definition at line 149 of file vector.h.

149  {
150  return Vector3(x + s, y + s, z + s);
151  }

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

◆ operator+=()

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

Definition at line 95 of file vector.h.

95  {
96  x += p.x;
97  y += p.y;
98  z += p.z;
99  return *this;
100  }

References x, y, and z.

◆ operator-() [1/3]

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

Definition at line 139 of file vector.h.

139 { 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 145 of file vector.h.

145  {
146  return Vector3(x - v.x, y - v.y, z - v.z);
147  }

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

◆ operator-() [3/3]

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

Definition at line 153 of file vector.h.

153  {
154  return Vector3(x - s, y - s, z - s);
155  }

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

◆ operator-=()

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

Definition at line 102 of file vector.h.

102  {
103  x -= p.x;
104  y -= p.y;
105  z -= p.z;
106  return *this;
107  }

References x, y, and z.

◆ operator/() [1/2]

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

Definition at line 166 of file vector.h.

166  {
167  return Vector3(x / v.x, y / v.y, z / v.z);
168  }

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 171 of file vector.h.

171  {
172  return Vector3(x / scale, y / scale, z / scale);
173  }

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

◆ operator/=() [1/2]

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

Definition at line 124 of file vector.h.

124  {
125  x /= p.x;
126  y /= p.y;
127  z /= p.z;
128  return *this;
129  }

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 132 of file vector.h.

132  {
133  x /= scale;
134  y /= scale;
135  z /= scale;
136  return *this;
137  }

References x, y, and z.

◆ operator==()

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

Definition at line 87 of file vector.h.

87  {
88  return v.x == x && v.y == y && v.z == z;
89  }

References x, y, and z.

◆ Round()

constexpr Vector3 impeller::Vector3::Round ( ) const
inlineconstexpr

Definition at line 83 of file vector.h.

83  {
84  return {std::round(x), std::round(y), std::round(z)};
85  }

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

◆ @23

union { ... }

◆ e

Scalar impeller::Vector3::e[3]

Definition at line 24 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:
impeller::Vector3::Vector3
constexpr Vector3()
Definition: vector.h:27
impeller::Vector3::x
Scalar x
Definition: vector.h:20
impeller::Vector3::z
Scalar z
Definition: vector.h:22
impeller::Vector3::Length
constexpr Scalar Length() const
Definition: vector.h:44
impeller::Vector3::y
Scalar y
Definition: vector.h:21