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 bool addCoincident(SkIntersectionHelper& other, const SkIntersections& ts, b
ool swap) { |
21 fContour->addCoincident(fIndex, other.fContour, other.fIndex, ts, swap); | 21 return 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, | 30 bool addPartialCoincident(SkIntersectionHelper& other, const SkIntersections
& ts, int index, |
31 bool swap) { | 31 bool swap) { |
32 fContour->addPartialCoincident(fIndex, other.fContour, other.fIndex, ts,
index, swap); | 32 return fContour->addPartialCoincident(fIndex, other.fContour, other.fInd
ex, ts, index, |
| 33 swap); |
33 } | 34 } |
34 | 35 |
35 // Avoid collapsing t values that are close to the same since | 36 // Avoid collapsing t values that are close to the same since |
36 // we walk ts to describe consecutive intersections. Since a pair of ts can | 37 // we walk ts to describe consecutive intersections. Since a pair of ts can |
37 // be nearly equal, any problems caused by this should be taken care | 38 // be nearly equal, any problems caused by this should be taken care |
38 // of later. | 39 // of later. |
39 // On the edge or out of range values are negative; add 2 to get end | 40 // On the edge or out of range values are negative; add 2 to get end |
40 int addT(const SkIntersectionHelper& other, const SkPoint& pt, double newT,
bool isNear) { | 41 int addT(const SkIntersectionHelper& other, const SkPoint& pt, double newT,
bool isNear) { |
41 return fContour->addT(fIndex, other.fContour, other.fIndex, pt, newT, is
Near); | 42 return fContour->addT(fIndex, other.fContour, other.fIndex, pt, newT, is
Near); |
42 } | 43 } |
(...skipping 27 matching lines...) Expand all Loading... |
70 bool isFirstLast(const SkIntersectionHelper& next) { | 71 bool isFirstLast(const SkIntersectionHelper& next) { |
71 return fContour == next.fContour && fIndex == 0 | 72 return fContour == next.fContour && fIndex == 0 |
72 && next.fIndex == fLast - 1; | 73 && next.fIndex == fLast - 1; |
73 } | 74 } |
74 | 75 |
75 bool isNear(double t1, double t2, const SkDPoint& pt1, const SkDPoint& pt2)
const { | 76 bool isNear(double t1, double t2, const SkDPoint& pt1, const SkDPoint& pt2)
const { |
76 const SkOpSegment& segment = fContour->segments()[fIndex]; | 77 const SkOpSegment& segment = fContour->segments()[fIndex]; |
77 double mid = (t1 + t2) / 2; | 78 double mid = (t1 + t2) / 2; |
78 SkDPoint midPtByT = segment.dPtAtT(mid); | 79 SkDPoint midPtByT = segment.dPtAtT(mid); |
79 SkDPoint midPtByAvg = SkDPoint::Mid(pt1, pt2); | 80 SkDPoint midPtByAvg = SkDPoint::Mid(pt1, pt2); |
80 return midPtByT.approximatelyEqualHalf(midPtByAvg); | 81 return midPtByT.approximatelyEqual(midPtByAvg); |
81 } | 82 } |
82 | 83 |
83 SkScalar left() const { | 84 SkScalar left() const { |
84 return bounds().fLeft; | 85 return bounds().fLeft; |
85 } | 86 } |
86 | 87 |
87 const SkPoint* pts() const { | 88 const SkPoint* pts() const { |
88 return fContour->segments()[fIndex].pts(); | 89 return fContour->segments()[fIndex].pts(); |
89 } | 90 } |
90 | 91 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 135 |
135 bool yFlipped() const { | 136 bool yFlipped() const { |
136 return y() != pts()[0].fY; | 137 return y() != pts()[0].fY; |
137 } | 138 } |
138 | 139 |
139 private: | 140 private: |
140 SkOpContour* fContour; | 141 SkOpContour* fContour; |
141 int fIndex; | 142 int fIndex; |
142 int fLast; | 143 int fLast; |
143 }; | 144 }; |
OLD | NEW |