OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 | 7 |
8 #include <cmath> | |
8 #include "SkBuffer.h" | 9 #include "SkBuffer.h" |
9 #include "SkCubicClipper.h" | 10 #include "SkCubicClipper.h" |
10 #include "SkErrorInternals.h" | 11 #include "SkErrorInternals.h" |
11 #include "SkGeometry.h" | 12 #include "SkGeometry.h" |
12 #include "SkMath.h" | 13 #include "SkMath.h" |
13 #include "SkPathPriv.h" | 14 #include "SkPathPriv.h" |
14 #include "SkPathRef.h" | 15 #include "SkPathRef.h" |
15 #include "SkRRect.h" | 16 #include "SkRRect.h" |
16 | 17 |
17 //////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////// |
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1412 this->getLastPt(¤tPoint); | 1413 this->getLastPt(¤tPoint); |
1413 this->arcTo(rx, ry, xAxisRotate, largeArc, sweep, currentPoint.fX + dx, curr entPoint.fY + dy); | 1414 this->arcTo(rx, ry, xAxisRotate, largeArc, sweep, currentPoint.fX + dx, curr entPoint.fY + dy); |
1414 } | 1415 } |
1415 | 1416 |
1416 void SkPath::addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle ) { | 1417 void SkPath::addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle ) { |
1417 if (oval.isEmpty() || 0 == sweepAngle) { | 1418 if (oval.isEmpty() || 0 == sweepAngle) { |
1418 return; | 1419 return; |
1419 } | 1420 } |
1420 | 1421 |
1421 const SkScalar kFullCircleAngle = SkIntToScalar(360); | 1422 const SkScalar kFullCircleAngle = SkIntToScalar(360); |
1422 | 1423 |
robertphillips
2016/05/27 12:12:29
It is unfortunate we have to always do this since
bsalomon
2016/05/27 14:29:32
I agree that this is painful. The problem is that
| |
1423 if (sweepAngle >= kFullCircleAngle || sweepAngle <= -kFullCircleAngle) { | 1424 if (sweepAngle >= kFullCircleAngle || sweepAngle <= -kFullCircleAngle) { |
1424 this->addOval(oval, sweepAngle > 0 ? kCW_Direction : kCCW_Direction); | 1425 // We can treat the arc as an oval if it begins at one of our legal star ting positions. |
1425 } else { | 1426 // See SkPath::addOval() docs. |
1426 this->arcTo(oval, startAngle, sweepAngle, true); | 1427 float n = startAngle / 90.f; |
robertphillips
2016/05/27 12:12:29
i -> intPortion, r -> remainder ?
bsalomon
2016/05/27 14:29:32
This code wasn't quite correct. The new version is
| |
1428 float i; | |
1429 float r = std::modf(n, &i); | |
1430 if (SkScalarNearlyEqual(r, 0.f)) { | |
1431 if (r < 0) { | |
1432 // If we were just under an integer multiple of 90, bump up. | |
1433 i += 1.f; | |
1434 } | |
1435 i += 1; // index 1 is at angle 0. | |
robertphillips
2016/05/27 12:12:30
Maybe introduce a new variable (int startIndex) he
bsalomon
2016/05/27 14:29:33
Done.
| |
1436 r = std::fmod(i, 4.f); | |
1437 r = r < 0 ? r + 4.f : r; | |
1438 this->addOval(oval, sweepAngle > 0 ? kCW_Direction : kCCW_Direction, (unsigned) r); | |
1439 return; | |
1440 } | |
1427 } | 1441 } |
1442 this->arcTo(oval, startAngle, sweepAngle, true); | |
1428 } | 1443 } |
1429 | 1444 |
1430 /* | 1445 /* |
1431 Need to handle the case when the angle is sharp, and our computed end-points | 1446 Need to handle the case when the angle is sharp, and our computed end-points |
1432 for the arc go behind pt1 and/or p2... | 1447 for the arc go behind pt1 and/or p2... |
1433 */ | 1448 */ |
1434 void SkPath::arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius) { | 1449 void SkPath::arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius) { |
1435 if (radius == 0) { | 1450 if (radius == 0) { |
1436 this->lineTo(x1, y1); | 1451 this->lineTo(x1, y1); |
1437 return; | 1452 return; |
(...skipping 1788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3226 } | 3241 } |
3227 } while (!done); | 3242 } while (!done); |
3228 return SkToBool(tangents.count()) ^ isInverse; | 3243 return SkToBool(tangents.count()) ^ isInverse; |
3229 } | 3244 } |
3230 | 3245 |
3231 int SkPath::ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPo int& p2, | 3246 int SkPath::ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPo int& p2, |
3232 SkScalar w, SkPoint pts[], int pow2) { | 3247 SkScalar w, SkPoint pts[], int pow2) { |
3233 const SkConic conic(p0, p1, p2, w); | 3248 const SkConic conic(p0, p1, p2, w); |
3234 return conic.chopIntoQuadsPOW2(pts, pow2); | 3249 return conic.chopIntoQuadsPOW2(pts, pow2); |
3235 } | 3250 } |
OLD | NEW |