OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #include "SkGeometry.h" | 7 #include "SkGeometry.h" |
8 #include "SkLineParameters.h" | 8 #include "SkLineParameters.h" |
9 #include "SkPathOpsConic.h" | 9 #include "SkPathOpsConic.h" |
10 #include "SkPathOpsCubic.h" | 10 #include "SkPathOpsCubic.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 SkScalar d[3]; | 233 SkScalar d[3]; |
234 SkCubicType cubicType = SkClassifyCubic(pointsPtr, d); | 234 SkCubicType cubicType = SkClassifyCubic(pointsPtr, d); |
235 if (cubicType == kLoop_SkCubicType) { | 235 if (cubicType == kLoop_SkCubicType) { |
236 // crib code from gpu path utils that finds t values where loop self-int ersects | 236 // crib code from gpu path utils that finds t values where loop self-int ersects |
237 // use it to find mid of t values which should be a friendly place to ch op | 237 // use it to find mid of t values which should be a friendly place to ch op |
238 SkScalar tempSqrt = SkScalarSqrt(4.f * d[0] * d[2] - 3.f * d[1] * d[1]); | 238 SkScalar tempSqrt = SkScalarSqrt(4.f * d[0] * d[2] - 3.f * d[1] * d[1]); |
239 SkScalar ls = d[1] - tempSqrt; | 239 SkScalar ls = d[1] - tempSqrt; |
240 SkScalar lt = 2.f * d[0]; | 240 SkScalar lt = 2.f * d[0]; |
241 SkScalar ms = d[1] + tempSqrt; | 241 SkScalar ms = d[1] + tempSqrt; |
242 SkScalar mt = 2.f * d[0]; | 242 SkScalar mt = 2.f * d[0]; |
243 if (between(0, ls, lt) || between(0, ms, mt)) { | 243 if (between(0, ls, lt) && between(0, ms, mt)) { // Both in [0, 1] inter val. |
244 ls = ls / lt; | 244 ls = ls / lt; |
245 ms = ms / mt; | 245 ms = ms / mt; |
246 SkScalar smaller = SkTMax(0.f, SkTMin(ls, ms)); | 246 SkASSERT(ls >= 0 && ls <= 1 && ms >= 0 && ms <= 1); // Both in [0, 1]. |
caryclark
2016/04/25 14:46:30
use between, e.g.:
SkASSERT(between(0, ls, 1) &&
| |
247 SkScalar larger = SkTMin(1.f, SkTMax(ls, ms)); | 247 *t = (ls + ms) / 2; |
248 *t = (smaller + larger) / 2; | 248 SkASSERT(*t >= 0 && *t <= 1); // Average should also be in [0, 1]. |
caryclark
2016/04/25 14:46:30
use between
| |
249 return *t > 0 && *t < 1; | 249 return *t > 0 && *t < 1; // Check that the cut isn't on an endpoint . |
caryclark
2016/04/25 14:46:30
use zero_or_one(t)
| |
250 } | 250 } |
251 } else if (kSerpentine_SkCubicType == cubicType || kCusp_SkCubicType == cubi cType) { | 251 } else if (kSerpentine_SkCubicType == cubicType || kCusp_SkCubicType == cubi cType) { |
252 SkDCubic cubic; | 252 SkDCubic cubic; |
253 cubic.set(pointsPtr); | 253 cubic.set(pointsPtr); |
254 double inflectionTs[2]; | 254 double inflectionTs[2]; |
255 int infTCount = cubic.findInflections(inflectionTs); | 255 int infTCount = cubic.findInflections(inflectionTs); |
256 if (infTCount == 2) { | 256 if (infTCount == 2) { |
257 double maxCurvature[3]; | 257 double maxCurvature[3]; |
258 int roots = cubic.findMaxCurvature(maxCurvature); | 258 int roots = cubic.findMaxCurvature(maxCurvature); |
259 #if DEBUG_CUBIC_SPLIT | 259 #if DEBUG_CUBIC_SPLIT |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 for (int index = 0; index < roots; ++index) { | 689 for (int index = 0; index < roots; ++index) { |
690 double t = startT + (endT - startT) * extremeTs[index]; | 690 double t = startT + (endT - startT) * extremeTs[index]; |
691 SkDPoint mid = dCurve.ptAtT(t); | 691 SkDPoint mid = dCurve.ptAtT(t); |
692 if (topPt->fY > mid.fY || (topPt->fY == mid.fY && topPt->fX > mid.fX)) { | 692 if (topPt->fY > mid.fY || (topPt->fY == mid.fY && topPt->fX > mid.fX)) { |
693 topT = t; | 693 topT = t; |
694 *topPt = mid; | 694 *topPt = mid; |
695 } | 695 } |
696 } | 696 } |
697 return topT; | 697 return topT; |
698 } | 698 } |
OLD | NEW |