| 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 "SkOpContour.h" | 7 #include "SkOpContour.h" |
| 8 #include "SkPath.h" | 8 #include "SkPath.h" |
| 9 | 9 |
| 10 class SkIntersectionHelper { | 10 class SkIntersectionHelper { |
| 11 public: | 11 public: |
| 12 enum SegmentType { | 12 enum SegmentType { |
| 13 kHorizontalLine_Segment = -1, | 13 kHorizontalLine_Segment = -1, |
| 14 kVerticalLine_Segment = 0, | 14 kVerticalLine_Segment = 0, |
| 15 kLine_Segment = SkPath::kLine_Verb, | 15 kLine_Segment = SkPath::kLine_Verb, |
| 16 kQuad_Segment = SkPath::kQuad_Verb, | 16 kQuad_Segment = SkPath::kQuad_Verb, |
| 17 kCubic_Segment = SkPath::kCubic_Verb, | 17 kCubic_Segment = SkPath::kCubic_Verb, |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 void addCoincident(SkIntersectionHelper& other, const SkIntersections& ts, b
ool swap) { | 20 void addCoincident(SkIntersectionHelper& other, const SkIntersections& ts, b
ool swap) { |
| 21 fContour->addCoincident(fIndex, other.fContour, other.fIndex, ts, swap); | 21 fContour->addCoincident(fIndex, other.fContour, other.fIndex, ts, swap); |
| 22 } | 22 } |
| 23 | 23 |
| 24 // FIXME: does it make sense to write otherIndex now if we're going to | 24 // FIXME: does it make sense to write otherIndex now if we're going to |
| 25 // fix it up later? | 25 // fix it up later? |
| 26 void addOtherT(int index, double otherT, int otherIndex) { | 26 void addOtherT(int index, double otherT, int otherIndex) { |
| 27 fContour->addOtherT(fIndex, index, otherT, otherIndex); | 27 fContour->addOtherT(fIndex, index, otherT, otherIndex); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void addPartialCoincident(SkIntersectionHelper& other, const SkIntersections
& ts, int index, |
| 31 bool swap) { |
| 32 fContour->addPartialCoincident(fIndex, other.fContour, other.fIndex, ts,
index, swap); |
| 33 } |
| 34 |
| 30 // Avoid collapsing t values that are close to the same since | 35 // Avoid collapsing t values that are close to the same since |
| 31 // we walk ts to describe consecutive intersections. Since a pair of ts can | 36 // we walk ts to describe consecutive intersections. Since a pair of ts can |
| 32 // be nearly equal, any problems caused by this should be taken care | 37 // be nearly equal, any problems caused by this should be taken care |
| 33 // of later. | 38 // of later. |
| 34 // On the edge or out of range values are negative; add 2 to get end | 39 // On the edge or out of range values are negative; add 2 to get end |
| 35 int addT(const SkIntersectionHelper& other, const SkPoint& pt, double newT)
{ | 40 int addT(const SkIntersectionHelper& other, const SkPoint& pt, double newT,
bool isNear) { |
| 36 return fContour->addT(fIndex, other.fContour, other.fIndex, pt, newT); | 41 return fContour->addT(fIndex, other.fContour, other.fIndex, pt, newT, is
Near); |
| 37 } | 42 } |
| 38 | 43 |
| 39 int addSelfT(const SkIntersectionHelper& other, const SkPoint& pt, double ne
wT) { | 44 int addSelfT(const SkIntersectionHelper& other, const SkPoint& pt, double ne
wT) { |
| 40 return fContour->addSelfT(fIndex, other.fContour, other.fIndex, pt, newT
); | 45 return fContour->addSelfT(fIndex, other.fContour, other.fIndex, pt, newT
); |
| 41 } | 46 } |
| 42 | 47 |
| 43 int addUnsortableT(const SkIntersectionHelper& other, bool start, const SkPo
int& pt, | |
| 44 double newT) { | |
| 45 return fContour->addUnsortableT(fIndex, other.fContour, other.fIndex, st
art, pt, newT); | |
| 46 } | |
| 47 | |
| 48 bool advance() { | 48 bool advance() { |
| 49 return ++fIndex < fLast; | 49 return ++fIndex < fLast; |
| 50 } | 50 } |
| 51 | 51 |
| 52 SkScalar bottom() const { | 52 SkScalar bottom() const { |
| 53 return bounds().fBottom; | 53 return bounds().fBottom; |
| 54 } | 54 } |
| 55 | 55 |
| 56 const SkPathOpsBounds& bounds() const { | 56 const SkPathOpsBounds& bounds() const { |
| 57 return fContour->segments()[fIndex].bounds(); | 57 return fContour->segments()[fIndex].bounds(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void init(SkOpContour* contour) { | 60 void init(SkOpContour* contour) { |
| 61 fContour = contour; | 61 fContour = contour; |
| 62 fIndex = 0; | 62 fIndex = 0; |
| 63 fLast = contour->segments().count(); | 63 fLast = contour->segments().count(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool isAdjacent(const SkIntersectionHelper& next) { | 66 bool isAdjacent(const SkIntersectionHelper& next) { |
| 67 return fContour == next.fContour && fIndex + 1 == next.fIndex; | 67 return fContour == next.fContour && fIndex + 1 == next.fIndex; |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool isFirstLast(const SkIntersectionHelper& next) { | 70 bool isFirstLast(const SkIntersectionHelper& next) { |
| 71 return fContour == next.fContour && fIndex == 0 | 71 return fContour == next.fContour && fIndex == 0 |
| 72 && next.fIndex == fLast - 1; | 72 && next.fIndex == fLast - 1; |
| 73 } | 73 } |
| 74 | 74 |
| 75 bool isNear(double t1, double t2, const SkDPoint& pt1, const SkDPoint& pt2)
const { |
| 76 const SkOpSegment& segment = fContour->segments()[fIndex]; |
| 77 double mid = (t1 + t2) / 2; |
| 78 SkDPoint midPtByT = segment.dPtAtT(mid); |
| 79 SkDPoint midPtByAvg = SkDPoint::Mid(pt1, pt2); |
| 80 return midPtByT.approximatelyEqualHalf(midPtByAvg); |
| 81 } |
| 82 |
| 75 SkScalar left() const { | 83 SkScalar left() const { |
| 76 return bounds().fLeft; | 84 return bounds().fLeft; |
| 77 } | 85 } |
| 78 | 86 |
| 79 const SkPoint* pts() const { | 87 const SkPoint* pts() const { |
| 80 return fContour->segments()[fIndex].pts(); | 88 return fContour->segments()[fIndex].pts(); |
| 81 } | 89 } |
| 82 | 90 |
| 83 SkScalar right() const { | 91 SkScalar right() const { |
| 84 return bounds().fRight; | 92 return bounds().fRight; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 134 |
| 127 bool yFlipped() const { | 135 bool yFlipped() const { |
| 128 return y() != pts()[0].fY; | 136 return y() != pts()[0].fY; |
| 129 } | 137 } |
| 130 | 138 |
| 131 private: | 139 private: |
| 132 SkOpContour* fContour; | 140 SkOpContour* fContour; |
| 133 int fIndex; | 141 int fIndex; |
| 134 int fLast; | 142 int fLast; |
| 135 }; | 143 }; |
| OLD | NEW |