Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
path_component.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_PATH_COMPONENT_H_
6#define FLUTTER_IMPELLER_GEOMETRY_PATH_COMPONENT_H_
7
8#include <functional>
9#include <type_traits>
10#include <variant>
11#include <vector>
12
16
17namespace impeller {
18
22
24
25 LinearPathComponent(Point ap1, Point ap2) : p1(ap1), p2(ap2) {}
26
27 Point Solve(Scalar time) const;
28
29 void AppendPolylinePoints(std::vector<Point>& points) const;
30
31 std::vector<Point> Extrema() const;
32
33 bool operator==(const LinearPathComponent& other) const {
34 return p1 == other.p1 && p2 == other.p2;
35 }
36
37 std::optional<Vector2> GetStartDirection() const;
38
39 std::optional<Vector2> GetEndDirection() const;
40};
41
42// A component that represets a Quadratic Bézier curve.
44 // Start point.
46 // Control point.
48 // End point.
50
52
54 : p1(ap1), cp(acp), p2(ap2) {}
55
56 Point Solve(Scalar time) const;
57
58 Point SolveDerivative(Scalar time) const;
59
60 void AppendPolylinePoints(Scalar scale_factor,
61 std::vector<Point>& points) const;
62
63 using PointProc = std::function<void(const Point& point)>;
64
65 void ToLinearPathComponents(Scalar scale_factor, const PointProc& proc) const;
66
67 std::vector<Point> Extrema() const;
68
69 bool operator==(const QuadraticPathComponent& other) const {
70 return p1 == other.p1 && cp == other.cp && p2 == other.p2;
71 }
72
73 std::optional<Vector2> GetStartDirection() const;
74
75 std::optional<Vector2> GetEndDirection() const;
76};
77
78// A component that represets a Cubic Bézier curve.
80 // Start point.
82 // The first control point.
84 // The second control point.
86 // End point.
88
90
92 : p1(q.p1),
93 cp1(q.p1 + (q.cp - q.p1) * (2.0 / 3.0)),
94 cp2(q.p2 + (q.cp - q.p2) * (2.0 / 3.0)),
95 p2(q.p2) {}
96
98 : p1(ap1), cp1(acp1), cp2(acp2), p2(ap2) {}
99
100 Point Solve(Scalar time) const;
101
102 Point SolveDerivative(Scalar time) const;
103
104 void AppendPolylinePoints(Scalar scale, std::vector<Point>& points) const;
105
106 std::vector<Point> Extrema() const;
107
108 using PointProc = std::function<void(const Point& point)>;
109
110 void ToLinearPathComponents(Scalar scale, const PointProc& proc) const;
111
113
114 bool operator==(const CubicPathComponent& other) const {
115 return p1 == other.p1 && cp1 == other.cp1 && cp2 == other.cp2 &&
116 p2 == other.p2;
117 }
118
119 std::optional<Vector2> GetStartDirection() const;
120
121 std::optional<Vector2> GetEndDirection() const;
122
123 private:
124 QuadraticPathComponent Lower() const;
125};
126
129 bool is_closed = false;
130
132
133 explicit ContourComponent(Point p, bool is_closed = false)
135
136 bool operator==(const ContourComponent& other) const {
137 return destination == other.destination && is_closed == other.is_closed;
138 }
139};
140
141using PathComponentVariant = std::variant<std::monostate,
142 const LinearPathComponent*,
144 const CubicPathComponent*>;
145
147 std::optional<Vector2> operator()(const LinearPathComponent* component);
148 std::optional<Vector2> operator()(const QuadraticPathComponent* component);
149 std::optional<Vector2> operator()(const CubicPathComponent* component);
150 std::optional<Vector2> operator()(std::monostate monostate) {
151 return std::nullopt;
152 }
153};
154
156 std::optional<Vector2> operator()(const LinearPathComponent* component);
157 std::optional<Vector2> operator()(const QuadraticPathComponent* component);
158 std::optional<Vector2> operator()(const CubicPathComponent* component);
159 std::optional<Vector2> operator()(std::monostate monostate) {
160 return std::nullopt;
161 }
162};
163
164static_assert(!std::is_polymorphic<LinearPathComponent>::value);
165static_assert(!std::is_polymorphic<QuadraticPathComponent>::value);
166static_assert(!std::is_polymorphic<CubicPathComponent>::value);
167
168} // namespace impeller
169
170#endif // FLUTTER_IMPELLER_GEOMETRY_PATH_COMPONENT_H_
static const int points[]
float Scalar
Definition scalar.h:18
std::variant< std::monostate, const LinearPathComponent *, const QuadraticPathComponent *, const CubicPathComponent * > PathComponentVariant
const Scalar scale
bool operator==(const ContourComponent &other) const
ContourComponent(Point p, bool is_closed=false)
void ToLinearPathComponents(Scalar scale, const PointProc &proc) const
void AppendPolylinePoints(Scalar scale, std::vector< Point > &points) const
CubicPathComponent(Point ap1, Point acp1, Point acp2, Point ap2)
bool operator==(const CubicPathComponent &other) const
std::function< void(const Point &point)> PointProc
CubicPathComponent Subsegment(Scalar t0, Scalar t1) const
Point Solve(Scalar time) const
std::optional< Vector2 > GetStartDirection() const
std::vector< Point > Extrema() const
std::optional< Vector2 > GetEndDirection() const
Point SolveDerivative(Scalar time) const
CubicPathComponent(const QuadraticPathComponent &q)
std::optional< Vector2 > GetEndDirection() const
LinearPathComponent(Point ap1, Point ap2)
std::optional< Vector2 > GetStartDirection() const
std::vector< Point > Extrema() const
bool operator==(const LinearPathComponent &other) const
Point Solve(Scalar time) const
void AppendPolylinePoints(std::vector< Point > &points) const
std::optional< Vector2 > operator()(const LinearPathComponent *component)
std::optional< Vector2 > operator()(std::monostate monostate)
std::optional< Vector2 > operator()(std::monostate monostate)
std::optional< Vector2 > operator()(const LinearPathComponent *component)
std::optional< Vector2 > GetEndDirection() const
QuadraticPathComponent(Point ap1, Point acp, Point ap2)
void AppendPolylinePoints(Scalar scale_factor, std::vector< Point > &points) const
bool operator==(const QuadraticPathComponent &other) const
std::function< void(const Point &point)> PointProc
std::vector< Point > Extrema() const
Point SolveDerivative(Scalar time) const
std::optional< Vector2 > GetStartDirection() const
void ToLinearPathComponents(Scalar scale_factor, const PointProc &proc) const
Point Solve(Scalar time) const