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 
9 
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.
22  /// The normalized direction of the vector.
24 
25  /// The magnitude of the vector.
27 
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
float Scalar
Definition: scalar.h:19
A Vector2, broken down as a separate magnitude and direction. Assumes that the direction given is nor...
Radians AngleTo(const SeparatedVector2 &other) const
Returns the scalar angle between the two rays.
Scalar Cross(const SeparatedVector2 &other) const
Returns the cross product of the two direction vectors.
Scalar GetAlignment(const SeparatedVector2 &other) const
Vector2 direction
The normalized direction of the vector.
Vector2 GetDirection() const
Returns just the normalized direction vector.
Vector2 GetVector() const
Returns the vector representation of the vector.
Scalar magnitude
The magnitude of the vector.