| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2012 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 #include "CubicLineSegments.h" | |
| 8 #include "QuadraticLineSegments.h" | |
| 9 | |
| 10 // http://cagd.cs.byu.edu/~557/text/cagd.pdf 2.7 | |
| 11 // A hodograph is the first derivative curve | |
| 12 void hodograph(const Cubic& cubic, Quadratic& hodo) { | |
| 13 hodo[0].x = 3 * (cubic[1].x - cubic[0].x); | |
| 14 hodo[0].y = 3 * (cubic[1].y - cubic[0].y); | |
| 15 hodo[1].x = 3 * (cubic[2].x - cubic[1].x); | |
| 16 hodo[1].y = 3 * (cubic[2].y - cubic[1].y); | |
| 17 hodo[2].x = 3 * (cubic[3].x - cubic[2].x); | |
| 18 hodo[2].y = 3 * (cubic[3].y - cubic[2].y); | |
| 19 } | |
| 20 | |
| 21 // A 2nd hodograph is the second derivative curve | |
| 22 void secondHodograph(const Cubic& cubic, _Line& hodo2) { | |
| 23 Quadratic hodo; | |
| 24 hodograph(cubic, hodo); | |
| 25 hodograph(hodo, hodo2); | |
| 26 } | |
| 27 | |
| 28 // The number of line segments required to approximate the cubic | |
| 29 // see http://cagd.cs.byu.edu/~557/text/cagd.pdf 10.6 | |
| 30 double subDivisions(const Cubic& cubic) { | |
| 31 _Line hodo2; | |
| 32 secondHodograph(cubic, hodo2); | |
| 33 double maxX = SkTMax(hodo2[1].x, hodo2[1].x); | |
| 34 double maxY = SkTMax(hodo2[1].y, hodo2[1].y); | |
| 35 double dist = sqrt(maxX * maxX + maxY * maxY); | |
| 36 double segments = sqrt(dist / (8 * FLT_EPSILON)); | |
| 37 return segments; | |
| 38 } | |
| OLD | NEW |