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 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
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 SkScalar startOver90 = startAngle / 90.f; |
| 1428 SkScalar startOver90I = SkScalarRoundToScalar(startOver90); |
| 1429 SkScalar error = startOver90 - startOver90I; |
| 1430 if (SkScalarNearlyEqual(error, 0)) { |
| 1431 // Index 1 is at startAngle == 0. |
| 1432 SkScalar startIndex = std::fmod(startOver90I + 1.f, 4.f); |
| 1433 startIndex = startIndex < 0 ? startIndex + 4.f : startIndex; |
| 1434 this->addOval(oval, sweepAngle > 0 ? kCW_Direction : kCCW_Direction, |
| 1435 (unsigned) startIndex); |
| 1436 return; |
| 1437 } |
1427 } | 1438 } |
| 1439 this->arcTo(oval, startAngle, sweepAngle, true); |
1428 } | 1440 } |
1429 | 1441 |
1430 /* | 1442 /* |
1431 Need to handle the case when the angle is sharp, and our computed end-points | 1443 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... | 1444 for the arc go behind pt1 and/or p2... |
1433 */ | 1445 */ |
1434 void SkPath::arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar
radius) { | 1446 void SkPath::arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar
radius) { |
1435 if (radius == 0) { | 1447 if (radius == 0) { |
1436 this->lineTo(x1, y1); | 1448 this->lineTo(x1, y1); |
1437 return; | 1449 return; |
(...skipping 1788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3226 } | 3238 } |
3227 } while (!done); | 3239 } while (!done); |
3228 return SkToBool(tangents.count()) ^ isInverse; | 3240 return SkToBool(tangents.count()) ^ isInverse; |
3229 } | 3241 } |
3230 | 3242 |
3231 int SkPath::ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPo
int& p2, | 3243 int SkPath::ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPo
int& p2, |
3232 SkScalar w, SkPoint pts[], int pow2) { | 3244 SkScalar w, SkPoint pts[], int pow2) { |
3233 const SkConic conic(p0, p1, p2, w); | 3245 const SkConic conic(p0, p1, p2, w); |
3234 return conic.chopIntoQuadsPOW2(pts, pow2); | 3246 return conic.chopIntoQuadsPOW2(pts, pow2); |
3235 } | 3247 } |
OLD | NEW |