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