| Flutter Impeller |

wangs_formula.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_WANGS_FORMULA_H_
6 #define FLUTTER_IMPELLER_GEOMETRY_WANGS_FORMULA_H_
7
8 #include "impeller/geometry/path_component.h"
9 #include "impeller/geometry/point.h"
10 #include "impeller/geometry/scalar.h"
11
12 // Skia GPU Ports
13
14 // Wang's formula gives the minimum number of evenly spaced (in the parametric
15 // sense) line segments that a bezier curve must be chopped into in order to
16 // guarantee all lines stay within a distance of "1/precision" pixels from the
17 // true curve. Its definition for a bezier curve of degree "n" is as follows:
18 //
19 // maxLength = max([length(p[i+2] - 2p[i+1] + p[i]) for (0 <= i <= n-2)])
20 // numParametricSegments = sqrt(maxLength * precision * n*(n - 1)/8)
21 //
22 // (Goldman, Ron. (2003). 5.6.3 Wang's Formula. "Pyramid Algorithms: A Dynamic
23 // Programming Approach to Curves and Surfaces for Geometric Modeling". Morgan
24 // Kaufmann Publishers.)
25 namespace impeller {
26
27 /// Returns the minimum number of evenly spaced (in the parametric sense) line
28 /// segments that the cubic must be chopped into in order to guarantee all lines
29 /// stay within a distance of "1/intolerance" pixels from the true curve.
30 ///
31 /// The scale_factor should be the max basis XY of the current transform.
32 Scalar ComputeCubicSubdivisions(Scalar scale_factor,
33 Point p0,
34 Point p1,
35 Point p2,
36 Point p3);
37
38 /// Returns the minimum number of evenly spaced (in the parametric sense) line
39 /// segments that the quadratic must be chopped into in order to guarantee all
40 /// lines stay within a distance of "1/intolerance" pixels from the true curve.
41 ///
42 /// The scale_factor should be the max basis XY of the current transform.
43 Scalar ComputeQuadradicSubdivisions(Scalar scale_factor,
44 Point p0,
45 Point p1,
46 Point p2);
47
48 /// Returns the minimum number of evenly spaced (in the parametric sense) line
49 /// segments that the conic must be chopped into in order to guarantee all
50 /// lines stay within a distance of "1/intolerance" pixels from the true curve.
51 ///
52 /// The scale_factor should be the max basis XY of the current transform.
53 Scalar ComputeConicSubdivisions(Scalar scale_factor,
54 Point p0,
55 Point p1,
56 Point p2,
57 Scalar w);
58
59 /// Returns the minimum number of evenly spaced (in the parametric sense) line
60 /// segments that the quadratic must be chopped into in order to guarantee all
61 /// lines stay within a distance of "1/intolerance" pixels from the true curve.
62 ///
63 /// The scale_factor should be the max basis XY of the current transform.
64 Scalar ComputeQuadradicSubdivisions(Scalar scale_factor,
65 const QuadraticPathComponent& quad);
66
67 /// Returns the minimum number of evenly spaced (in the parametric sense) line
68 /// segments that the cubic must be chopped into in order to guarantee all lines
69 /// stay within a distance of "1/intolerance" pixels from the true curve.
70 ///
71 /// The scale_factor should be the max basis XY of the current transform.
72 Scalar ComputeCubicSubdivisions(float scale_factor,
73 const CubicPathComponent& cub);
74
75 /// Returns the minimum number of evenly spaced (in the parametric sense) line
76 /// segments that the conic must be chopped into in order to guarantee all lines
77 /// stay within a distance of "1/intolerance" pixels from the true curve.
78 ///
79 /// The scale_factor should be the max basis XY of the current transform.
80 Scalar ComputeConicSubdivisions(float scale_factor,
81 const ConicPathComponent& conic);
82 } // namespace impeller
83
84 #endif // FLUTTER_IMPELLER_GEOMETRY_WANGS_FORMULA_H_
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::Point
TPoint< Scalar > Point
Definition: point.h:327
impeller::ComputeConicSubdivisions
Scalar ComputeConicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2, Scalar w)
Definition: wangs_formula.cc:48
impeller::ComputeQuadradicSubdivisions
Scalar ComputeQuadradicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2)
Definition: wangs_formula.cc:34
impeller::ComputeCubicSubdivisions
Scalar ComputeCubicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2, Point p3)
Definition: wangs_formula.cc:23
path_component.h
point.h
scalar.h