| 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 "SkPathOpsCubic.h" | 10 #include "SkPathOpsCubic.h" |
| 10 #include "SkPathOpsLine.h" | 11 #include "SkPathOpsLine.h" |
| 11 #include "SkPathOpsQuad.h" | 12 #include "SkPathOpsQuad.h" |
| 12 #include "SkPathOpsRect.h" | 13 #include "SkPathOpsRect.h" |
| 13 #include "SkTSort.h" | 14 #include "SkTSort.h" |
| 14 | 15 |
| 15 const int SkDCubic::gPrecisionUnit = 256; // FIXME: test different values in te
st framework | 16 const int SkDCubic::gPrecisionUnit = 256; // FIXME: test different values in te
st framework |
| 16 | 17 |
| 17 // give up when changing t no longer moves point | 18 // give up when changing t no longer moves point |
| 18 // also, copy point rather than recompute it when it does change | 19 // also, copy point rather than recompute it when it does change |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 && between(fPts[0].fY, fPts[2].fY, fPts[3].fY)); | 99 && between(fPts[0].fY, fPts[2].fY, fPts[3].fY)); |
| 99 } | 100 } |
| 100 | 101 |
| 101 // Do a quick reject by rotating all points relative to a line formed by | 102 // Do a quick reject by rotating all points relative to a line formed by |
| 102 // a pair of one cubic's points. If the 2nd cubic's points | 103 // a pair of one cubic's points. If the 2nd cubic's points |
| 103 // are on the line or on the opposite side from the 1st cubic's 'odd man', the | 104 // are on the line or on the opposite side from the 1st cubic's 'odd man', the |
| 104 // curves at most intersect at the endpoints. | 105 // curves at most intersect at the endpoints. |
| 105 /* if returning true, check contains true if cubic's hull collapsed, making the
cubic linear | 106 /* if returning true, check contains true if cubic's hull collapsed, making the
cubic linear |
| 106 if returning false, check contains true if the the cubic pair have only the e
nd point in common | 107 if returning false, check contains true if the the cubic pair have only the e
nd point in common |
| 107 */ | 108 */ |
| 108 bool SkDCubic::hullIntersects(const SkDCubic& c2, bool* isLinear) const { | 109 bool SkDCubic::hullIntersects(const SkDPoint* pts, int ptCount, bool* isLinear)
const { |
| 109 bool linear = true; | 110 bool linear = true; |
| 110 char hullOrder[4]; | 111 char hullOrder[4]; |
| 111 int hullCount = convexHull(hullOrder); | 112 int hullCount = convexHull(hullOrder); |
| 112 int end1 = hullOrder[0]; | 113 int end1 = hullOrder[0]; |
| 113 int hullIndex = 0; | 114 int hullIndex = 0; |
| 114 const SkDPoint* endPt[2]; | 115 const SkDPoint* endPt[2]; |
| 115 endPt[0] = &fPts[end1]; | 116 endPt[0] = &fPts[end1]; |
| 116 do { | 117 do { |
| 117 hullIndex = (hullIndex + 1) % hullCount; | 118 hullIndex = (hullIndex + 1) % hullCount; |
| 118 int end2 = hullOrder[hullIndex]; | 119 int end2 = hullOrder[hullIndex]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 130 continue; | 131 continue; |
| 131 } | 132 } |
| 132 if (approximately_zero(sign)) { | 133 if (approximately_zero(sign)) { |
| 133 sign = sign2; | 134 sign = sign2; |
| 134 if (approximately_zero(sign)) { | 135 if (approximately_zero(sign)) { |
| 135 continue; | 136 continue; |
| 136 } | 137 } |
| 137 } | 138 } |
| 138 linear = false; | 139 linear = false; |
| 139 bool foundOutlier = false; | 140 bool foundOutlier = false; |
| 140 for (int n = 0; n < kPointCount; ++n) { | 141 for (int n = 0; n < ptCount; ++n) { |
| 141 double test = (c2[n].fY - origY) * adj - (c2[n].fX - origX) * opp; | 142 double test = (pts[n].fY - origY) * adj - (pts[n].fX - origX) * opp; |
| 142 if (test * sign > 0 && !precisely_zero(test)) { | 143 if (test * sign > 0 && !precisely_zero(test)) { |
| 143 foundOutlier = true; | 144 foundOutlier = true; |
| 144 break; | 145 break; |
| 145 } | 146 } |
| 146 } | 147 } |
| 147 if (!foundOutlier) { | 148 if (!foundOutlier) { |
| 148 return false; | 149 return false; |
| 149 } | 150 } |
| 150 endPt[0] = endPt[1]; | 151 endPt[0] = endPt[1]; |
| 151 end1 = end2; | 152 end1 = end2; |
| 152 } while (hullIndex); | 153 } while (hullIndex); |
| 153 *isLinear = linear; | 154 *isLinear = linear; |
| 154 return true; | 155 return true; |
| 155 } | 156 } |
| 156 | 157 |
| 158 bool SkDCubic::hullIntersects(const SkDCubic& c2, bool* isLinear) const { |
| 159 return hullIntersects(c2.fPts, c2.kPointCount, isLinear); |
| 160 } |
| 161 |
| 162 bool SkDCubic::hullIntersects(const SkDQuad& quad, bool* isLinear) const { |
| 163 return hullIntersects(quad.fPts, quad.kPointCount, isLinear); |
| 164 } |
| 165 |
| 166 bool SkDCubic::hullIntersects(const SkDConic& conic, bool* isLinear) const { |
| 167 |
| 168 return hullIntersects(conic.fPts, isLinear); |
| 169 } |
| 170 |
| 157 bool SkDCubic::isLinear(int startIndex, int endIndex) const { | 171 bool SkDCubic::isLinear(int startIndex, int endIndex) const { |
| 158 SkLineParameters lineParameters; | 172 SkLineParameters lineParameters; |
| 159 lineParameters.cubicEndPoints(*this, startIndex, endIndex); | 173 lineParameters.cubicEndPoints(*this, startIndex, endIndex); |
| 160 // FIXME: maybe it's possible to avoid this and compare non-normalized | 174 // FIXME: maybe it's possible to avoid this and compare non-normalized |
| 161 lineParameters.normalize(); | 175 lineParameters.normalize(); |
| 162 double tiniest = SkTMin(SkTMin(SkTMin(SkTMin(SkTMin(SkTMin(SkTMin(fPts[0].fX
, fPts[0].fY), | 176 double tiniest = SkTMin(SkTMin(SkTMin(SkTMin(SkTMin(SkTMin(SkTMin(fPts[0].fX
, fPts[0].fY), |
| 163 fPts[1].fX), fPts[1].fY), fPts[2].fX), fPts[2].fY), fPts[3].fX), fPt
s[3].fY); | 177 fPts[1].fX), fPts[1].fY), fPts[2].fX), fPts[2].fY), fPts[3].fX), fPt
s[3].fY); |
| 164 double largest = SkTMax(SkTMax(SkTMax(SkTMax(SkTMax(SkTMax(SkTMax(fPts[0].fX
, fPts[0].fY), | 178 double largest = SkTMax(SkTMax(SkTMax(SkTMax(SkTMax(SkTMax(SkTMax(fPts[0].fX
, fPts[0].fY), |
| 165 fPts[1].fX), fPts[1].fY), fPts[2].fX), fPts[2].fY), fPts[3].fX), fPt
s[3].fY); | 179 fPts[1].fX), fPts[1].fY), fPts[2].fX), fPts[2].fY), fPts[3].fX), fPt
s[3].fY); |
| 166 largest = SkTMax(largest, -tiniest); | 180 largest = SkTMax(largest, -tiniest); |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 dst.pts[4].fY = (fPts[1].fY + 2 * fPts[2].fY + fPts[3].fY) / 4; | 639 dst.pts[4].fY = (fPts[1].fY + 2 * fPts[2].fY + fPts[3].fY) / 4; |
| 626 dst.pts[5].fX = (fPts[2].fX + fPts[3].fX) / 2; | 640 dst.pts[5].fX = (fPts[2].fX + fPts[3].fX) / 2; |
| 627 dst.pts[5].fY = (fPts[2].fY + fPts[3].fY) / 2; | 641 dst.pts[5].fY = (fPts[2].fY + fPts[3].fY) / 2; |
| 628 dst.pts[6] = fPts[3]; | 642 dst.pts[6] = fPts[3]; |
| 629 return dst; | 643 return dst; |
| 630 } | 644 } |
| 631 interp_cubic_coords(&fPts[0].fX, &dst.pts[0].fX, t); | 645 interp_cubic_coords(&fPts[0].fX, &dst.pts[0].fX, t); |
| 632 interp_cubic_coords(&fPts[0].fY, &dst.pts[0].fY, t); | 646 interp_cubic_coords(&fPts[0].fY, &dst.pts[0].fY, t); |
| 633 return dst; | 647 return dst; |
| 634 } | 648 } |
| OLD | NEW |