22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- part of engine;
5+ import 'dart:typed_data' ;
6+ import 'dart:math' as math;
7+
8+ import 'package:ui/ui.dart' as ui;
9+
10+ import 'path_utils.dart' ;
611
712/// Converts conic curve to a list of quadratic curves for rendering on
813/// canvas or conversion to svg.
@@ -198,7 +203,7 @@ class Conic {
198203 final double coeff0 = fW * p20 - p20;
199204 final double coeff1 = p20 - 2 * wP10;
200205 final double coeff2 = wP10;
201- final _QuadRoots quadRoots = _QuadRoots ();
206+ final QuadRoots quadRoots = QuadRoots ();
202207 int rootCount = quadRoots.findRoots (coeff0, coeff1, coeff2);
203208 assert (rootCount == 0 || rootCount == 1 );
204209 if (rootCount == 1 ) {
@@ -230,12 +235,12 @@ class Conic {
230235 final double dz1 = dz0 + (dz2 - dz0) * t;
231236 // Compute new weights.
232237 final double root = math.sqrt (dz1);
233- if (_nearlyEqual (root, 0 )) {
238+ if (SPath . nearlyEqual (root, 0 )) {
234239 return false ;
235240 }
236241 final double w0 = dz0 / root;
237242 final double w2 = dz2 / root;
238- if (_nearlyEqual (dz0, 0 ) || _nearlyEqual (dz1, 0 ) || _nearlyEqual (dz2, 0 )) {
243+ if (SPath . nearlyEqual (dz0, 0 ) || SPath . nearlyEqual (dz1, 0 ) || SPath . nearlyEqual (dz2, 0 )) {
239244 return false ;
240245 }
241246 // Now we can construct the 2 conics by projecting 3D down to 2D.
@@ -314,33 +319,34 @@ class Conic {
314319 double ay = fW * p20y - p20y;
315320 double bx = p20x - cx - cx;
316321 double by = p20y - cy - cy;
317- _SkQuadCoefficients quadC = _SkQuadCoefficients (ax, ay, bx, by, cx, cy);
322+ SkQuadCoefficients quadC = SkQuadCoefficients (ax, ay, bx, by, cx, cy);
318323 return ui.Offset (quadC.evalX (t), quadC.evalY (t));
319324 }
320- }
321325
322- double _conicEvalNumerator (
323- double p0, double p1, double p2, double w, double t) {
324- assert (t >= 0 && t <= 1 );
325- final double src2w = p1 * w;
326- final C = p0;
327- final A = p2 - 2 * src2w + C ;
328- final B = 2 * (src2w - C );
329- return polyEval (A , B , C , t);
330- }
326+ static double evalNumerator (
327+ double p0, double p1, double p2, double w, double t) {
328+ assert (t >= 0 && t <= 1 );
329+ final double src2w = p1 * w;
330+ final C = p0;
331+ final A = p2 - 2 * src2w + C ;
332+ final B = 2 * (src2w - C );
333+ return polyEval (A , B , C , t);
334+ }
331335
332- double _conicEvalDenominator (double w, double t) {
333- double B = 2 * (w - 1 );
334- double C = 1 ;
335- double A = - B ;
336- return polyEval (A , B , C , t);
336+ static double evalDenominator (double w, double t) {
337+ double B = 2 * (w - 1 );
338+ double C = 1 ;
339+ double A = - B ;
340+ return polyEval (A , B , C , t);
341+ }
337342}
338343
339- class _QuadBounds {
344+ class QuadBounds {
340345 double minX = 0 ;
341346 double minY = 0 ;
342347 double maxX = 0 ;
343348 double maxY = 0 ;
349+
344350 void calculateBounds (Float32List points, int pointIndex) {
345351 final double x1 = points[pointIndex++ ];
346352 final double y1 = points[pointIndex++ ];
@@ -398,7 +404,7 @@ class _QuadBounds {
398404 }
399405}
400406
401- class _ConicBounds {
407+ class ConicBounds {
402408 double minX = 0 ;
403409 double minY = 0 ;
404410 double maxX = 0 ;
@@ -420,7 +426,7 @@ class _ConicBounds {
420426 // ------------------------------------------------
421427 // {t^2 (2 - 2 w), t (-2 + 2 w), 1}
422428 // Calculate coefficients and solve root.
423- _QuadRoots roots = _QuadRoots ();
429+ QuadRoots roots = QuadRoots ();
424430 final double P20x = x2 - x1;
425431 final double P10x = cpX - x1;
426432 final double wP10x = w * P10x ;
@@ -431,10 +437,10 @@ class _ConicBounds {
431437 if (n != 0 ) {
432438 final double t1 = roots.root0! ;
433439 if ((t1 >= 0 ) && (t1 <= 1.0 )) {
434- final double denom = _conicEvalDenominator (w, t1);
435- double numerator = _conicEvalNumerator (x1, cpX, x2, w, t1);
440+ final double denom = Conic . evalDenominator (w, t1);
441+ double numerator = Conic . evalNumerator (x1, cpX, x2, w, t1);
436442 final double extremaX = numerator / denom;
437- numerator = _conicEvalNumerator (y1, cpY, y2, w, t1);
443+ numerator = Conic . evalNumerator (y1, cpY, y2, w, t1);
438444 final double extremaY = numerator / denom;
439445 // Expand bounds.
440446 minX = math.min (minX, extremaX);
@@ -454,10 +460,10 @@ class _ConicBounds {
454460 if (n != 0 ) {
455461 final double t2 = roots.root0! ;
456462 if ((t2 >= 0 ) && (t2 <= 1.0 )) {
457- final double denom = _conicEvalDenominator (w, t2);
458- double numerator = _conicEvalNumerator (x1, cpX, x2, w, t2);
463+ final double denom = Conic . evalDenominator (w, t2);
464+ double numerator = Conic . evalNumerator (x1, cpX, x2, w, t2);
459465 final double extrema2X = numerator / denom;
460- numerator = _conicEvalNumerator (y1, cpY, y2, w, t2);
466+ numerator = Conic . evalNumerator (y1, cpY, y2, w, t2);
461467 final double extrema2Y = numerator / denom;
462468 // Expand bounds.
463469 minX = math.min (minX, extrema2X);
0 commit comments