| Flutter Impeller |

separated_vector.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_GEOMETRY_SEPARATED_VECTOR_H_
6 #define FLUTTER_IMPELLER_GEOMETRY_SEPARATED_VECTOR_H_
7
8 #include "impeller/geometry/point.h"
9
10 #include "impeller/geometry/scalar.h"
11
12 namespace impeller {
13
14 /// @brief A Vector2, broken down as a separate magnitude and direction.
15 /// Assumes that the direction given is normalized.
16 ///
17 /// This is a simple convenience struct for handling polyline offset
18 /// values when generating stroke geometry. For performance reasons,
19 /// it's sometimes adventageous to track the direction and magnitude
20 /// for offsets separately.
21 struct SeparatedVector2 {
22 /// The normalized direction of the vector.
23 Vector2 direction;
24
25 /// The magnitude of the vector.
26 Scalar magnitude = 0.0;
27
28 SeparatedVector2();
29 SeparatedVector2(Vector2 direction, Scalar magnitude);
30 explicit SeparatedVector2(Vector2 vector);
31
32 /// Returns the vector representation of the vector.
33 Vector2 GetVector() const;
34
35 /// Returns just the normalized direction vector.
36 Vector2 GetDirection() const;
37
38 /// Returns the scalar alignment of the two vectors.
39 /// In other words, the dot product of the two normalized vectors.
40 ///
41 /// Range: [-1, 1]
42 /// A value of 1 indicates the directions are parallel and pointing in the
43 /// same direction. A value of -1 indicates the vectors are parallel and
44 /// pointing in opposite directions. A value of 0 indicates the vectors are
45 /// perpendicular.
46 Scalar GetAlignment(const SeparatedVector2& other) const;
47
48 /// Returns the scalar angle between the two rays.
49 Radians AngleTo(const SeparatedVector2& other) const;
50
51 /// Returns the cross product of the two direction vectors.
52 Scalar Cross(const SeparatedVector2& other) const;
53 };
54
55 #endif // FLUTTER_IMPELLER_GEOMETRY_SEPARATED_VECTOR_H_
56
57 } // namespace impeller
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:19
point.h
scalar.h
impeller::Radians
Definition: scalar.h:44
impeller::SeparatedVector2
A Vector2, broken down as a separate magnitude and direction. Assumes that the direction given is nor...
Definition: separated_vector.h:21
impeller::SeparatedVector2::AngleTo
Radians AngleTo(const SeparatedVector2 &other) const
Returns the scalar angle between the two rays.
Definition: separated_vector.cc:29
impeller::SeparatedVector2::Cross
Scalar Cross(const SeparatedVector2 &other) const
Returns the cross product of the two direction vectors.
Definition: separated_vector.cc:33
impeller::SeparatedVector2::GetAlignment
Scalar GetAlignment(const SeparatedVector2 &other) const
Definition: separated_vector.cc:25
impeller::SeparatedVector2::direction
Vector2 direction
The normalized direction of the vector.
Definition: separated_vector.h:23
impeller::SeparatedVector2::SeparatedVector2
SeparatedVector2()
impeller::SeparatedVector2::GetDirection
Vector2 GetDirection() const
Returns just the normalized direction vector.
Definition: separated_vector.cc:21
impeller::SeparatedVector2::GetVector
Vector2 GetVector() const
Returns the vector representation of the vector.
Definition: separated_vector.cc:17
impeller::SeparatedVector2::magnitude
Scalar magnitude
The magnitude of the vector.
Definition: separated_vector.h:26
impeller::TPoint< Scalar >