| Flutter Impeller |

wangs_formula.cc
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 #include "impeller/geometry/wangs_formula.h"
6
7 namespace impeller {
8
9 namespace {
10
11 // Don't allow linearized segments to be off by more than 1/4th of a pixel from
12 // the true curve. This value should be scaled by the max basis of the
13 // X and Y directions.
14 constexpr static Scalar kPrecision = 4;
15
16 constexpr Scalar length(Point n) {
17 Point nn = n * n;
18 return std::sqrt(nn.x + nn.y);
19 }
20
21 } // namespace
22
23 Scalar ComputeCubicSubdivisions(Scalar scale_factor,
24 Point p0,
25 Point p1,
26 Point p2,
27 Point p3) {
28 Scalar k = scale_factor * .75f * kPrecision;
29 Point a = (p0 - p1 * 2 + p2).Abs();
30 Point b = (p1 - p2 * 2 + p3).Abs();
31 return std::sqrt(k * length(a.Max(b)));
32 }
33
34 Scalar ComputeQuadradicSubdivisions(Scalar scale_factor,
35 Point p0,
36 Point p1,
37 Point p2) {
38 Scalar k = scale_factor * .25f * kPrecision;
39 return std::sqrt(k * length(p0 - p1 * 2 + p2));
40 }
41
42 Scalar ComputeQuadradicSubdivisions(Scalar scale_factor,
43 const QuadraticPathComponent& quad) {
44 return ComputeQuadradicSubdivisions(scale_factor, quad.p1, quad.cp, quad.p2);
45 }
46
47 Scalar ComputeCubicSubdivisions(float scale_factor,
48 const CubicPathComponent& cub) {
49 return ComputeCubicSubdivisions(scale_factor, cub.p1, cub.cp1, cub.cp2,
50 cub.p2);
51 }
52
53 } // namespace impeller
impeller::ComputeQuadradicSubdivisions
Scalar ComputeQuadradicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2)
Definition: wangs_formula.cc:34
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::CubicPathComponent::p1
Point p1
Definition: path_component.h:103
impeller::QuadraticPathComponent::p1
Point p1
Definition: path_component.h:65
impeller::CubicPathComponent::cp2
Point cp2
Definition: path_component.h:107
impeller::QuadraticPathComponent::cp
Point cp
Definition: path_component.h:67
impeller::CubicPathComponent::cp1
Point cp1
Definition: path_component.h:105
impeller::Point
TPoint< Scalar > Point
Definition: point.h:322
impeller::TPoint::Max
constexpr TPoint Max(const TPoint &p) const
Definition: point.h:190
impeller::CubicPathComponent
Definition: path_component.h:101
impeller::ComputeCubicSubdivisions
Scalar ComputeCubicSubdivisions(Scalar scale_factor, Point p0, Point p1, Point p2, Point p3)
Definition: wangs_formula.cc:23
impeller::QuadraticPathComponent::p2
Point p2
Definition: path_component.h:69
impeller::TPoint
Definition: point.h:27
impeller::saturated::b
SI b
Definition: saturated_math.h:87
impeller::CubicPathComponent::p2
Point p2
Definition: path_component.h:109
impeller
Definition: aiks_blend_unittests.cc:18
impeller::QuadraticPathComponent
Definition: path_component.h:63
wangs_formula.h