caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 7 | #include "src/pathops/SkOpAngle.h" |
| 8 | #include "src/pathops/SkOpSegment.h" |
| 9 | #include "src/pathops/SkPathOpsCurve.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 10 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 11 | /* Angles are sorted counterclockwise. The smallest angle has a positive x and the smallest |
| 12 | positive y. The largest angle has a positive x and a zero y. */ |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 13 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 14 | #if DEBUG_ANGLE |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 15 | static bool CompareResult(const char* func, SkString* bugOut, SkString* bugPart, int append, |
| 16 | bool compare) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 17 | SkDebugf("%s %c %d\n", bugOut->c_str(), compare ? 'T' : 'F', append); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 18 | SkDebugf("%sPart %s\n", func, bugPart[0].c_str()); |
| 19 | SkDebugf("%sPart %s\n", func, bugPart[1].c_str()); |
| 20 | SkDebugf("%sPart %s\n", func, bugPart[2].c_str()); |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 21 | return compare; |
| 22 | } |
| 23 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 24 | #define COMPARE_RESULT(append, compare) CompareResult(__FUNCTION__, &bugOut, bugPart, append, \ |
| 25 | compare) |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 26 | #else |
skia.committer@gmail.com | 8f6ef40 | 2013-06-05 07:01:06 +0000 | [diff] [blame] | 27 | #define COMPARE_RESULT(append, compare) compare |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 28 | #endif |
| 29 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 30 | /* quarter angle values for sector |
| 31 | |
| 32 | 31 x > 0, y == 0 horizontal line (to the right) |
| 33 | 0 x > 0, y == epsilon quad/cubic horizontal tangent eventually going +y |
| 34 | 1 x > 0, y > 0, x > y nearer horizontal angle |
| 35 | 2 x + e == y quad/cubic 45 going horiz |
| 36 | 3 x > 0, y > 0, x == y 45 angle |
| 37 | 4 x == y + e quad/cubic 45 going vert |
| 38 | 5 x > 0, y > 0, x < y nearer vertical angle |
| 39 | 6 x == epsilon, y > 0 quad/cubic vertical tangent eventually going +x |
| 40 | 7 x == 0, y > 0 vertical line (to the top) |
| 41 | |
| 42 | 8 7 6 |
| 43 | 9 | 5 |
| 44 | 10 | 4 |
| 45 | 11 | 3 |
| 46 | 12 \ | / 2 |
| 47 | 13 | 1 |
| 48 | 14 | 0 |
| 49 | 15 --------------+------------- 31 |
| 50 | 16 | 30 |
| 51 | 17 | 29 |
| 52 | 18 / | \ 28 |
| 53 | 19 | 27 |
| 54 | 20 | 26 |
| 55 | 21 | 25 |
| 56 | 22 23 24 |
| 57 | */ |
| 58 | |
| 59 | // return true if lh < this < rh |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 60 | bool SkOpAngle::after(SkOpAngle* test) { |
| 61 | SkOpAngle* lh = test; |
| 62 | SkOpAngle* rh = lh->fNext; |
| 63 | SkASSERT(lh != rh); |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 64 | fPart.fCurve = fOriginalCurvePart; |
| 65 | lh->fPart.fCurve = lh->fOriginalCurvePart; |
| 66 | lh->fPart.fCurve.offset(lh->segment()->verb(), fPart.fCurve[0] - lh->fPart.fCurve[0]); |
| 67 | rh->fPart.fCurve = rh->fOriginalCurvePart; |
| 68 | rh->fPart.fCurve.offset(rh->segment()->verb(), fPart.fCurve[0] - rh->fPart.fCurve[0]); |
| 69 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 70 | #if DEBUG_ANGLE |
| 71 | SkString bugOut; |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 72 | bugOut.printf("%s [%d/%d] %d/%d tStart=%1.9g tEnd=%1.9g" |
| 73 | " < [%d/%d] %d/%d tStart=%1.9g tEnd=%1.9g" |
| 74 | " < [%d/%d] %d/%d tStart=%1.9g tEnd=%1.9g ", __FUNCTION__, |
| 75 | lh->segment()->debugID(), lh->debugID(), lh->fSectorStart, lh->fSectorEnd, |
| 76 | lh->fStart->t(), lh->fEnd->t(), |
| 77 | segment()->debugID(), debugID(), fSectorStart, fSectorEnd, fStart->t(), fEnd->t(), |
| 78 | rh->segment()->debugID(), rh->debugID(), rh->fSectorStart, rh->fSectorEnd, |
| 79 | rh->fStart->t(), rh->fEnd->t()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 80 | SkString bugPart[3] = { lh->debugPart(), this->debugPart(), rh->debugPart() }; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 81 | #endif |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 82 | if (lh->fComputeSector && !lh->computeSector()) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 83 | return COMPARE_RESULT(1, true); |
| 84 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 85 | if (fComputeSector && !this->computeSector()) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 86 | return COMPARE_RESULT(2, true); |
| 87 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 88 | if (rh->fComputeSector && !rh->computeSector()) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 89 | return COMPARE_RESULT(3, true); |
| 90 | } |
| 91 | #if DEBUG_ANGLE // reset bugOut with computed sectors |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 92 | bugOut.printf("%s [%d/%d] %d/%d tStart=%1.9g tEnd=%1.9g" |
| 93 | " < [%d/%d] %d/%d tStart=%1.9g tEnd=%1.9g" |
| 94 | " < [%d/%d] %d/%d tStart=%1.9g tEnd=%1.9g ", __FUNCTION__, |
| 95 | lh->segment()->debugID(), lh->debugID(), lh->fSectorStart, lh->fSectorEnd, |
| 96 | lh->fStart->t(), lh->fEnd->t(), |
| 97 | segment()->debugID(), debugID(), fSectorStart, fSectorEnd, fStart->t(), fEnd->t(), |
| 98 | rh->segment()->debugID(), rh->debugID(), rh->fSectorStart, rh->fSectorEnd, |
| 99 | rh->fStart->t(), rh->fEnd->t()); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 100 | #endif |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 101 | bool ltrOverlap = (lh->fSectorMask | rh->fSectorMask) & fSectorMask; |
| 102 | bool lrOverlap = lh->fSectorMask & rh->fSectorMask; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 103 | int lrOrder; // set to -1 if either order works |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 104 | if (!lrOverlap) { // no lh/rh sector overlap |
| 105 | if (!ltrOverlap) { // no lh/this/rh sector overlap |
| 106 | return COMPARE_RESULT(4, (lh->fSectorEnd > rh->fSectorStart) |
| 107 | ^ (fSectorStart > lh->fSectorEnd) ^ (fSectorStart > rh->fSectorStart)); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 108 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 109 | int lrGap = (rh->fSectorStart - lh->fSectorStart + 32) & 0x1f; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 110 | /* A tiny change can move the start +/- 4. The order can only be determined if |
| 111 | lr gap is not 12 to 20 or -12 to -20. |
| 112 | -31 ..-21 1 |
| 113 | -20 ..-12 -1 |
| 114 | -11 .. -1 0 |
| 115 | 0 shouldn't get here |
| 116 | 11 .. 1 1 |
| 117 | 12 .. 20 -1 |
| 118 | 21 .. 31 0 |
| 119 | */ |
| 120 | lrOrder = lrGap > 20 ? 0 : lrGap > 11 ? -1 : 1; |
| 121 | } else { |
Cary Clark | ea2a632 | 2018-08-27 13:19:09 -0400 | [diff] [blame] | 122 | lrOrder = lh->orderable(rh); |
| 123 | if (!ltrOverlap && lrOrder >= 0) { |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 124 | return COMPARE_RESULT(5, !lrOrder); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | int ltOrder; |
Cary Clark | ea2a632 | 2018-08-27 13:19:09 -0400 | [diff] [blame] | 128 | SkASSERT((lh->fSectorMask & fSectorMask) || (rh->fSectorMask & fSectorMask) || -1 == lrOrder); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 129 | if (lh->fSectorMask & fSectorMask) { |
Cary Clark | ea2a632 | 2018-08-27 13:19:09 -0400 | [diff] [blame] | 130 | ltOrder = lh->orderable(this); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 131 | } else { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 132 | int ltGap = (fSectorStart - lh->fSectorStart + 32) & 0x1f; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 133 | ltOrder = ltGap > 20 ? 0 : ltGap > 11 ? -1 : 1; |
| 134 | } |
| 135 | int trOrder; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 136 | if (rh->fSectorMask & fSectorMask) { |
Cary Clark | ea2a632 | 2018-08-27 13:19:09 -0400 | [diff] [blame] | 137 | trOrder = this->orderable(rh); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 138 | } else { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 139 | int trGap = (rh->fSectorStart - fSectorStart + 32) & 0x1f; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 140 | trOrder = trGap > 20 ? 0 : trGap > 11 ? -1 : 1; |
| 141 | } |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 142 | this->alignmentSameSide(lh, <Order); |
| 143 | this->alignmentSameSide(rh, &trOrder); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 144 | if (lrOrder >= 0 && ltOrder >= 0 && trOrder >= 0) { |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 145 | return COMPARE_RESULT(7, lrOrder ? (ltOrder & trOrder) : (ltOrder | trOrder)); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 146 | } |
Cary Clark | ea2a632 | 2018-08-27 13:19:09 -0400 | [diff] [blame] | 147 | // SkASSERT(lrOrder >= 0 || ltOrder >= 0 || trOrder >= 0); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 148 | // There's not enough information to sort. Get the pairs of angles in opposite planes. |
| 149 | // If an order is < 0, the pair is already in an opposite plane. Check the remaining pairs. |
| 150 | // FIXME : once all variants are understood, rewrite this more simply |
| 151 | if (ltOrder == 0 && lrOrder == 0) { |
| 152 | SkASSERT(trOrder < 0); |
| 153 | // FIXME : once this is verified to work, remove one opposite angle call |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 154 | SkDEBUGCODE(bool lrOpposite = lh->oppositePlanes(rh)); |
| 155 | bool ltOpposite = lh->oppositePlanes(this); |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 156 | SkOPASSERT(lrOpposite != ltOpposite); |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 157 | return COMPARE_RESULT(8, ltOpposite); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 158 | } else if (ltOrder == 1 && trOrder == 0) { |
| 159 | SkASSERT(lrOrder < 0); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 160 | bool trOpposite = oppositePlanes(rh); |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 161 | return COMPARE_RESULT(9, trOpposite); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 162 | } else if (lrOrder == 1 && trOrder == 1) { |
| 163 | SkASSERT(ltOrder < 0); |
caryclark | 78a37a5 | 2016-10-20 12:36:16 -0700 | [diff] [blame] | 164 | // SkDEBUGCODE(bool trOpposite = oppositePlanes(rh)); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 165 | bool lrOpposite = lh->oppositePlanes(rh); |
caryclark | 78a37a5 | 2016-10-20 12:36:16 -0700 | [diff] [blame] | 166 | // SkASSERT(lrOpposite != trOpposite); |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 167 | return COMPARE_RESULT(10, lrOpposite); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 168 | } |
Cary Clark | 7db95a6 | 2018-06-06 16:56:23 -0400 | [diff] [blame] | 169 | // If a pair couldn't be ordered, there's not enough information to determine the sort. |
| 170 | // Refer to: https://docs.google.com/drawings/d/1KV-8SJTedku9fj4K6fd1SB-8divuV_uivHVsSgwXICQ |
Cary Clark | 3a4a321 | 2018-06-06 15:22:08 -0400 | [diff] [blame] | 171 | if (fUnorderable || lh->fUnorderable || rh->fUnorderable) { |
| 172 | // limit to lines; should work with curves, but wait for a failing test to verify |
| 173 | if (!fPart.isCurve() && !lh->fPart.isCurve() && !rh->fPart.isCurve()) { |
| 174 | // see if original raw data is orderable |
| 175 | // if two share a point, check if third has both points in same half plane |
| 176 | int ltShare = lh->fOriginalCurvePart[0] == fOriginalCurvePart[0]; |
| 177 | int lrShare = lh->fOriginalCurvePart[0] == rh->fOriginalCurvePart[0]; |
| 178 | int trShare = fOriginalCurvePart[0] == rh->fOriginalCurvePart[0]; |
| 179 | // if only one pair are the same, the third point touches neither of the pair |
| 180 | if (ltShare + lrShare + trShare == 1) { |
Cary Clark | 7db95a6 | 2018-06-06 16:56:23 -0400 | [diff] [blame] | 181 | if (lrShare) { |
Cary Clark | 9d6049a | 2018-12-21 13:13:10 -0500 | [diff] [blame] | 182 | int ltOOrder = lh->linesOnOriginalSide(this); |
| 183 | int rtOOrder = rh->linesOnOriginalSide(this); |
Cary Clark | 7db95a6 | 2018-06-06 16:56:23 -0400 | [diff] [blame] | 184 | if ((rtOOrder ^ ltOOrder) == 1) { |
| 185 | return ltOOrder; |
| 186 | } |
| 187 | } else if (trShare) { |
Cary Clark | 9d6049a | 2018-12-21 13:13:10 -0500 | [diff] [blame] | 188 | int tlOOrder = this->linesOnOriginalSide(lh); |
| 189 | int rlOOrder = rh->linesOnOriginalSide(lh); |
Cary Clark | 7db95a6 | 2018-06-06 16:56:23 -0400 | [diff] [blame] | 190 | if ((tlOOrder ^ rlOOrder) == 1) { |
| 191 | return rlOOrder; |
| 192 | } |
| 193 | } else { |
| 194 | SkASSERT(ltShare); |
Cary Clark | 9d6049a | 2018-12-21 13:13:10 -0500 | [diff] [blame] | 195 | int trOOrder = rh->linesOnOriginalSide(this); |
| 196 | int lrOOrder = lh->linesOnOriginalSide(rh); |
Cary Clark | 3a4a321 | 2018-06-06 15:22:08 -0400 | [diff] [blame] | 197 | // result must be 0 and 1 or 1 and 0 to be valid |
| 198 | if ((lrOOrder ^ trOOrder) == 1) { |
| 199 | return trOOrder; |
| 200 | } |
Cary Clark | 3a4a321 | 2018-06-06 15:22:08 -0400 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | } |
| 204 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 205 | if (lrOrder < 0) { |
| 206 | if (ltOrder < 0) { |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 207 | return COMPARE_RESULT(11, trOrder); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 208 | } |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 209 | return COMPARE_RESULT(12, ltOrder); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 210 | } |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 211 | return COMPARE_RESULT(13, !lrOrder); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Cary Clark | 9d6049a | 2018-12-21 13:13:10 -0500 | [diff] [blame] | 214 | int SkOpAngle::lineOnOneSide(const SkDPoint& origin, const SkDVector& line, const SkOpAngle* test, |
| 215 | bool useOriginal) const { |
caryclark | 8168194 | 2016-07-21 10:44:07 -0700 | [diff] [blame] | 216 | double crosses[3]; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 217 | SkPath::Verb testVerb = test->segment()->verb(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 218 | int iMax = SkPathOpsVerbToPoints(testVerb); |
| 219 | // SkASSERT(origin == test.fCurveHalf[0]); |
Cary Clark | 9d6049a | 2018-12-21 13:13:10 -0500 | [diff] [blame] | 220 | const SkDCurve& testCurve = useOriginal ? test->fOriginalCurvePart : test->fPart.fCurve; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 221 | for (int index = 1; index <= iMax; ++index) { |
caryclark | 8168194 | 2016-07-21 10:44:07 -0700 | [diff] [blame] | 222 | double xy1 = line.fX * (testCurve[index].fY - origin.fY); |
| 223 | double xy2 = line.fY * (testCurve[index].fX - origin.fX); |
| 224 | crosses[index - 1] = AlmostBequalUlps(xy1, xy2) ? 0 : xy1 - xy2; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 225 | } |
| 226 | if (crosses[0] * crosses[1] < 0) { |
| 227 | return -1; |
| 228 | } |
| 229 | if (SkPath::kCubic_Verb == testVerb) { |
| 230 | if (crosses[0] * crosses[2] < 0 || crosses[1] * crosses[2] < 0) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 231 | return -1; |
| 232 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 233 | } |
| 234 | if (crosses[0]) { |
| 235 | return crosses[0] < 0; |
| 236 | } |
| 237 | if (crosses[1]) { |
| 238 | return crosses[1] < 0; |
| 239 | } |
| 240 | if (SkPath::kCubic_Verb == testVerb && crosses[2]) { |
| 241 | return crosses[2] < 0; |
| 242 | } |
Cary Clark | 9d6049a | 2018-12-21 13:13:10 -0500 | [diff] [blame] | 243 | return -2; |
| 244 | } |
| 245 | |
| 246 | // given a line, see if the opposite curve's convex hull is all on one side |
| 247 | // returns -1=not on one side 0=this CW of test 1=this CCW of test |
| 248 | int SkOpAngle::lineOnOneSide(const SkOpAngle* test, bool useOriginal) { |
| 249 | SkASSERT(!fPart.isCurve()); |
| 250 | SkASSERT(test->fPart.isCurve()); |
| 251 | SkDPoint origin = fPart.fCurve[0]; |
| 252 | SkDVector line = fPart.fCurve[1] - origin; |
| 253 | int result = this->lineOnOneSide(origin, line, test, useOriginal); |
| 254 | if (-2 == result) { |
| 255 | fUnorderable = true; |
| 256 | result = -1; |
| 257 | } |
| 258 | return result; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Cary Clark | 3a4a321 | 2018-06-06 15:22:08 -0400 | [diff] [blame] | 261 | // experiment works only with lines for now |
Cary Clark | 9d6049a | 2018-12-21 13:13:10 -0500 | [diff] [blame] | 262 | int SkOpAngle::linesOnOriginalSide(const SkOpAngle* test) { |
Cary Clark | 3a4a321 | 2018-06-06 15:22:08 -0400 | [diff] [blame] | 263 | SkASSERT(!fPart.isCurve()); |
| 264 | SkASSERT(!test->fPart.isCurve()); |
| 265 | SkDPoint origin = fOriginalCurvePart[0]; |
| 266 | SkDVector line = fOriginalCurvePart[1] - origin; |
| 267 | double dots[2]; |
| 268 | double crosses[2]; |
| 269 | const SkDCurve& testCurve = test->fOriginalCurvePart; |
| 270 | for (int index = 0; index < 2; ++index) { |
| 271 | SkDVector testLine = testCurve[index] - origin; |
| 272 | double xy1 = line.fX * testLine.fY; |
| 273 | double xy2 = line.fY * testLine.fX; |
| 274 | dots[index] = line.fX * testLine.fX + line.fY * testLine.fY; |
| 275 | crosses[index] = AlmostBequalUlps(xy1, xy2) ? 0 : xy1 - xy2; |
| 276 | } |
| 277 | if (crosses[0] * crosses[1] < 0) { |
| 278 | return -1; |
| 279 | } |
| 280 | if (crosses[0]) { |
| 281 | return crosses[0] < 0; |
| 282 | } |
| 283 | if (crosses[1]) { |
| 284 | return crosses[1] < 0; |
| 285 | } |
| 286 | if ((!dots[0] && dots[1] < 0) || (dots[0] < 0 && !dots[1])) { |
| 287 | return 2; // 180 degrees apart |
| 288 | } |
| 289 | fUnorderable = true; |
| 290 | return -1; |
| 291 | } |
| 292 | |
Cary Clark | ff11428 | 2016-12-14 11:56:16 -0500 | [diff] [blame] | 293 | // To sort the angles, all curves are translated to have the same starting point. |
| 294 | // If the curve's control point in its original position is on one side of a compared line, |
| 295 | // and translated is on the opposite side, reverse the previously computed order. |
| 296 | void SkOpAngle::alignmentSameSide(const SkOpAngle* test, int* order) const { |
| 297 | if (*order < 0) { |
| 298 | return; |
| 299 | } |
| 300 | if (fPart.isCurve()) { |
| 301 | // This should support all curve types, but only bug that requires this has lines |
| 302 | // Turning on for curves causes existing tests to fail |
| 303 | return; |
| 304 | } |
| 305 | if (test->fPart.isCurve()) { |
| 306 | return; |
| 307 | } |
| 308 | const SkDPoint& xOrigin = test->fPart.fCurve.fLine[0]; |
| 309 | const SkDPoint& oOrigin = test->fOriginalCurvePart.fLine[0]; |
| 310 | if (xOrigin == oOrigin) { |
| 311 | return; |
| 312 | } |
| 313 | int iMax = SkPathOpsVerbToPoints(this->segment()->verb()); |
| 314 | SkDVector xLine = test->fPart.fCurve.fLine[1] - xOrigin; |
| 315 | SkDVector oLine = test->fOriginalCurvePart.fLine[1] - oOrigin; |
| 316 | for (int index = 1; index <= iMax; ++index) { |
| 317 | const SkDPoint& testPt = fPart.fCurve[index]; |
| 318 | double xCross = oLine.crossCheck(testPt - xOrigin); |
| 319 | double oCross = xLine.crossCheck(testPt - oOrigin); |
| 320 | if (oCross * xCross < 0) { |
| 321 | *order ^= 1; |
| 322 | break; |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 327 | bool SkOpAngle::checkCrossesZero() const { |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 328 | int start = std::min(fSectorStart, fSectorEnd); |
| 329 | int end = std::max(fSectorStart, fSectorEnd); |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 330 | bool crossesZero = end - start > 16; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 331 | return crossesZero; |
| 332 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 333 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 334 | bool SkOpAngle::checkParallel(SkOpAngle* rh) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 335 | SkDVector scratch[2]; |
| 336 | const SkDVector* sweep, * tweep; |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 337 | if (this->fPart.isOrdered()) { |
| 338 | sweep = this->fPart.fSweep; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 339 | } else { |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 340 | scratch[0] = this->fPart.fCurve[1] - this->fPart.fCurve[0]; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 341 | sweep = &scratch[0]; |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 342 | } |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 343 | if (rh->fPart.isOrdered()) { |
| 344 | tweep = rh->fPart.fSweep; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 345 | } else { |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 346 | scratch[1] = rh->fPart.fCurve[1] - rh->fPart.fCurve[0]; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 347 | tweep = &scratch[1]; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 348 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 349 | double s0xt0 = sweep->crossCheck(*tweep); |
| 350 | if (tangentsDiverge(rh, s0xt0)) { |
| 351 | return s0xt0 < 0; |
skia.committer@gmail.com | 8f6ef40 | 2013-06-05 07:01:06 +0000 | [diff] [blame] | 352 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 353 | // compute the perpendicular to the endpoints and see where it intersects the opposite curve |
| 354 | // if the intersections within the t range, do a cross check on those |
| 355 | bool inside; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 356 | if (!fEnd->contains(rh->fEnd)) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 357 | if (this->endToSide(rh, &inside)) { |
| 358 | return inside; |
| 359 | } |
| 360 | if (rh->endToSide(this, &inside)) { |
| 361 | return !inside; |
| 362 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 363 | } |
| 364 | if (this->midToSide(rh, &inside)) { |
| 365 | return inside; |
| 366 | } |
| 367 | if (rh->midToSide(this, &inside)) { |
| 368 | return !inside; |
| 369 | } |
| 370 | // compute the cross check from the mid T values (last resort) |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 371 | SkDVector m0 = segment()->dPtAtT(this->midT()) - this->fPart.fCurve[0]; |
| 372 | SkDVector m1 = rh->segment()->dPtAtT(rh->midT()) - rh->fPart.fCurve[0]; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 373 | double m0xm1 = m0.crossCheck(m1); |
| 374 | if (m0xm1 == 0) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 375 | this->fUnorderable = true; |
| 376 | rh->fUnorderable = true; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 377 | return true; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 378 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 379 | return m0xm1 < 0; |
| 380 | } |
| 381 | |
| 382 | // the original angle is too short to get meaningful sector information |
| 383 | // lengthen it until it is long enough to be meaningful or leave it unset if lengthening it |
| 384 | // would cause it to intersect one of the adjacent angles |
| 385 | bool SkOpAngle::computeSector() { |
| 386 | if (fComputedSector) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 387 | return !fUnorderable; |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 388 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 389 | fComputedSector = true; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 390 | bool stepUp = fStart->t() < fEnd->t(); |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 391 | SkOpSpanBase* checkEnd = fEnd; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 392 | if (checkEnd->final() && stepUp) { |
caryclark | ccec0f9 | 2015-03-24 07:28:17 -0700 | [diff] [blame] | 393 | fUnorderable = true; |
| 394 | return false; |
| 395 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 396 | do { |
| 397 | // advance end |
| 398 | const SkOpSegment* other = checkEnd->segment(); |
| 399 | const SkOpSpanBase* oSpan = other->head(); |
| 400 | do { |
| 401 | if (oSpan->segment() != segment()) { |
| 402 | continue; |
| 403 | } |
| 404 | if (oSpan == checkEnd) { |
| 405 | continue; |
| 406 | } |
| 407 | if (!approximately_equal(oSpan->t(), checkEnd->t())) { |
| 408 | continue; |
| 409 | } |
| 410 | goto recomputeSector; |
| 411 | } while (!oSpan->final() && (oSpan = oSpan->upCast()->next())); |
| 412 | checkEnd = stepUp ? !checkEnd->final() |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 413 | ? checkEnd->upCast()->next() : nullptr |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 414 | : checkEnd->prev(); |
| 415 | } while (checkEnd); |
| 416 | recomputeSector: |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 417 | SkOpSpanBase* computedEnd = stepUp ? checkEnd ? checkEnd->prev() : fEnd->segment()->head() |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 418 | : checkEnd ? checkEnd->upCast()->next() : fEnd->segment()->tail(); |
| 419 | if (checkEnd == fEnd || computedEnd == fEnd || computedEnd == fStart) { |
| 420 | fUnorderable = true; |
| 421 | return false; |
| 422 | } |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 423 | if (stepUp != (fStart->t() < computedEnd->t())) { |
| 424 | fUnorderable = true; |
| 425 | return false; |
| 426 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 427 | SkOpSpanBase* saveEnd = fEnd; |
| 428 | fComputedEnd = fEnd = computedEnd; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 429 | setSpans(); |
| 430 | setSector(); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 431 | fEnd = saveEnd; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 432 | return !fUnorderable; |
| 433 | } |
| 434 | |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 435 | int SkOpAngle::convexHullOverlaps(const SkOpAngle* rh) { |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 436 | const SkDVector* sweep = this->fPart.fSweep; |
| 437 | const SkDVector* tweep = rh->fPart.fSweep; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 438 | double s0xs1 = sweep[0].crossCheck(sweep[1]); |
| 439 | double s0xt0 = sweep[0].crossCheck(tweep[0]); |
| 440 | double s1xt0 = sweep[1].crossCheck(tweep[0]); |
| 441 | bool tBetweenS = s0xs1 > 0 ? s0xt0 > 0 && s1xt0 < 0 : s0xt0 < 0 && s1xt0 > 0; |
| 442 | double s0xt1 = sweep[0].crossCheck(tweep[1]); |
| 443 | double s1xt1 = sweep[1].crossCheck(tweep[1]); |
| 444 | tBetweenS |= s0xs1 > 0 ? s0xt1 > 0 && s1xt1 < 0 : s0xt1 < 0 && s1xt1 > 0; |
| 445 | double t0xt1 = tweep[0].crossCheck(tweep[1]); |
| 446 | if (tBetweenS) { |
| 447 | return -1; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 448 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 449 | if ((s0xt0 == 0 && s1xt1 == 0) || (s1xt0 == 0 && s0xt1 == 0)) { // s0 to s1 equals t0 to t1 |
| 450 | return -1; |
| 451 | } |
| 452 | bool sBetweenT = t0xt1 > 0 ? s0xt0 < 0 && s0xt1 > 0 : s0xt0 > 0 && s0xt1 < 0; |
| 453 | sBetweenT |= t0xt1 > 0 ? s1xt0 < 0 && s1xt1 > 0 : s1xt0 > 0 && s1xt1 < 0; |
| 454 | if (sBetweenT) { |
| 455 | return -1; |
| 456 | } |
| 457 | // if all of the sweeps are in the same half plane, then the order of any pair is enough |
| 458 | if (s0xt0 >= 0 && s0xt1 >= 0 && s1xt0 >= 0 && s1xt1 >= 0) { |
| 459 | return 0; |
| 460 | } |
| 461 | if (s0xt0 <= 0 && s0xt1 <= 0 && s1xt0 <= 0 && s1xt1 <= 0) { |
| 462 | return 1; |
| 463 | } |
| 464 | // if the outside sweeps are greater than 180 degress: |
| 465 | // first assume the inital tangents are the ordering |
| 466 | // if the midpoint direction matches the inital order, that is enough |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 467 | SkDVector m0 = this->segment()->dPtAtT(this->midT()) - this->fPart.fCurve[0]; |
| 468 | SkDVector m1 = rh->segment()->dPtAtT(rh->midT()) - rh->fPart.fCurve[0]; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 469 | double m0xm1 = m0.crossCheck(m1); |
| 470 | if (s0xt0 > 0 && m0xm1 > 0) { |
| 471 | return 0; |
| 472 | } |
| 473 | if (s0xt0 < 0 && m0xm1 < 0) { |
| 474 | return 1; |
| 475 | } |
| 476 | if (tangentsDiverge(rh, s0xt0)) { |
| 477 | return s0xt0 < 0; |
| 478 | } |
| 479 | return m0xm1 < 0; |
| 480 | } |
| 481 | |
| 482 | // OPTIMIZATION: longest can all be either lazily computed here or precomputed in setup |
| 483 | double SkOpAngle::distEndRatio(double dist) const { |
| 484 | double longest = 0; |
| 485 | const SkOpSegment& segment = *this->segment(); |
| 486 | int ptCount = SkPathOpsVerbToPoints(segment.verb()); |
| 487 | const SkPoint* pts = segment.pts(); |
| 488 | for (int idx1 = 0; idx1 <= ptCount - 1; ++idx1) { |
| 489 | for (int idx2 = idx1 + 1; idx2 <= ptCount; ++idx2) { |
| 490 | if (idx1 == idx2) { |
| 491 | continue; |
| 492 | } |
| 493 | SkDVector v; |
| 494 | v.set(pts[idx2] - pts[idx1]); |
| 495 | double lenSq = v.lengthSquared(); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 496 | longest = std::max(longest, lenSq); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 497 | } |
| 498 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 499 | return sqrt(longest) / dist; |
| 500 | } |
| 501 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 502 | bool SkOpAngle::endsIntersect(SkOpAngle* rh) { |
| 503 | SkPath::Verb lVerb = this->segment()->verb(); |
| 504 | SkPath::Verb rVerb = rh->segment()->verb(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 505 | int lPts = SkPathOpsVerbToPoints(lVerb); |
| 506 | int rPts = SkPathOpsVerbToPoints(rVerb); |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 507 | SkDLine rays[] = {{{this->fPart.fCurve[0], rh->fPart.fCurve[rPts]}}, |
| 508 | {{this->fPart.fCurve[0], this->fPart.fCurve[lPts]}}}; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 509 | if (this->fEnd->contains(rh->fEnd)) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 510 | return checkParallel(rh); |
| 511 | } |
| 512 | double smallTs[2] = {-1, -1}; |
| 513 | bool limited[2] = {false, false}; |
| 514 | for (int index = 0; index < 2; ++index) { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 515 | SkPath::Verb cVerb = index ? rVerb : lVerb; |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 516 | // if the curve is a line, then the line and the ray intersect only at their crossing |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 517 | if (cVerb == SkPath::kLine_Verb) { |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame] | 518 | continue; |
| 519 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 520 | const SkOpSegment& segment = index ? *rh->segment() : *this->segment(); |
| 521 | SkIntersections i; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 522 | (*CurveIntersectRay[cVerb])(segment.pts(), segment.weight(), rays[index], &i); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 523 | double tStart = index ? rh->fStart->t() : this->fStart->t(); |
| 524 | double tEnd = index ? rh->fComputedEnd->t() : this->fComputedEnd->t(); |
| 525 | bool testAscends = tStart < (index ? rh->fComputedEnd->t() : this->fComputedEnd->t()); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 526 | double t = testAscends ? 0 : 1; |
| 527 | for (int idx2 = 0; idx2 < i.used(); ++idx2) { |
| 528 | double testT = i[0][idx2]; |
| 529 | if (!approximately_between_orderable(tStart, testT, tEnd)) { |
| 530 | continue; |
| 531 | } |
| 532 | if (approximately_equal_orderable(tStart, testT)) { |
| 533 | continue; |
| 534 | } |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 535 | smallTs[index] = t = testAscends ? std::max(t, testT) : std::min(t, testT); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 536 | limited[index] = approximately_equal_orderable(t, tEnd); |
| 537 | } |
| 538 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 539 | bool sRayLonger = false; |
| 540 | SkDVector sCept = {0, 0}; |
| 541 | double sCeptT = -1; |
| 542 | int sIndex = -1; |
| 543 | bool useIntersect = false; |
| 544 | for (int index = 0; index < 2; ++index) { |
| 545 | if (smallTs[index] < 0) { |
| 546 | continue; |
| 547 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 548 | const SkOpSegment& segment = index ? *rh->segment() : *this->segment(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 549 | const SkDPoint& dPt = segment.dPtAtT(smallTs[index]); |
| 550 | SkDVector cept = dPt - rays[index][0]; |
| 551 | // If this point is on the curve, it should have been detected earlier by ordinary |
| 552 | // curve intersection. This may be hard to determine in general, but for lines, |
| 553 | // the point could be close to or equal to its end, but shouldn't be near the start. |
| 554 | if ((index ? lPts : rPts) == 1) { |
| 555 | SkDVector total = rays[index][1] - rays[index][0]; |
| 556 | if (cept.lengthSquared() * 2 < total.lengthSquared()) { |
| 557 | continue; |
| 558 | } |
| 559 | } |
| 560 | SkDVector end = rays[index][1] - rays[index][0]; |
| 561 | if (cept.fX * end.fX < 0 || cept.fY * end.fY < 0) { |
| 562 | continue; |
| 563 | } |
| 564 | double rayDist = cept.length(); |
| 565 | double endDist = end.length(); |
| 566 | bool rayLonger = rayDist > endDist; |
| 567 | if (limited[0] && limited[1] && rayLonger) { |
| 568 | useIntersect = true; |
| 569 | sRayLonger = rayLonger; |
| 570 | sCept = cept; |
| 571 | sCeptT = smallTs[index]; |
| 572 | sIndex = index; |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 573 | break; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 574 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 575 | double delta = fabs(rayDist - endDist); |
| 576 | double minX, minY, maxX, maxY; |
| 577 | minX = minY = SK_ScalarInfinity; |
| 578 | maxX = maxY = -SK_ScalarInfinity; |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 579 | const SkDCurve& curve = index ? rh->fPart.fCurve : this->fPart.fCurve; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 580 | int ptCount = index ? rPts : lPts; |
| 581 | for (int idx2 = 0; idx2 <= ptCount; ++idx2) { |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 582 | minX = std::min(minX, curve[idx2].fX); |
| 583 | minY = std::min(minY, curve[idx2].fY); |
| 584 | maxX = std::max(maxX, curve[idx2].fX); |
| 585 | maxY = std::max(maxY, curve[idx2].fY); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 586 | } |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 587 | double maxWidth = std::max(maxX - minX, maxY - minY); |
Cary Clark | 016d9b0 | 2018-10-16 11:59:34 -0400 | [diff] [blame] | 588 | delta = sk_ieee_double_divide(delta, maxWidth); |
Cary Clark | 9d6049a | 2018-12-21 13:13:10 -0500 | [diff] [blame] | 589 | // FIXME: move these magic numbers |
| 590 | // This fixes skbug.com/8380 |
| 591 | // Larger changes (like changing the constant in the next block) cause other |
| 592 | // tests to fail as documented in the bug. |
| 593 | // This could probably become a more general test: e.g., if translating the |
| 594 | // curve causes the cross product of any control point or end point to change |
| 595 | // sign with regard to the opposite curve's hull, treat the curves as parallel. |
| 596 | |
| 597 | // Moreso, this points to the general fragility of this approach of assigning |
| 598 | // winding by sorting the angles of curves sharing a common point, as mentioned |
| 599 | // in the bug. |
| 600 | if (delta < 4e-3 && delta > 1e-3 && !useIntersect && fPart.isCurve() |
| 601 | && rh->fPart.isCurve() && fOriginalCurvePart[0] != fPart.fCurve.fLine[0]) { |
| 602 | // see if original curve is on one side of hull; translated is on the other |
| 603 | const SkDPoint& origin = rh->fOriginalCurvePart[0]; |
| 604 | int count = SkPathOpsVerbToPoints(rh->segment()->verb()); |
| 605 | const SkDVector line = rh->fOriginalCurvePart[count] - origin; |
| 606 | int originalSide = rh->lineOnOneSide(origin, line, this, true); |
| 607 | if (originalSide >= 0) { |
| 608 | int translatedSide = rh->lineOnOneSide(origin, line, this, false); |
| 609 | if (originalSide != translatedSide) { |
| 610 | continue; |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | if (delta > 1e-3 && (useIntersect ^= true)) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 615 | sRayLonger = rayLonger; |
| 616 | sCept = cept; |
| 617 | sCeptT = smallTs[index]; |
| 618 | sIndex = index; |
| 619 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 620 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 621 | if (useIntersect) { |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 622 | const SkDCurve& curve = sIndex ? rh->fPart.fCurve : this->fPart.fCurve; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 623 | const SkOpSegment& segment = sIndex ? *rh->segment() : *this->segment(); |
| 624 | double tStart = sIndex ? rh->fStart->t() : fStart->t(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 625 | SkDVector mid = segment.dPtAtT(tStart + (sCeptT - tStart) / 2) - curve[0]; |
| 626 | double septDir = mid.crossCheck(sCept); |
| 627 | if (!septDir) { |
| 628 | return checkParallel(rh); |
| 629 | } |
| 630 | return sRayLonger ^ (sIndex == 0) ^ (septDir < 0); |
| 631 | } else { |
| 632 | return checkParallel(rh); |
caryclark@google.com | a5e5592 | 2013-05-07 18:51:31 +0000 | [diff] [blame] | 633 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 634 | } |
| 635 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 636 | bool SkOpAngle::endToSide(const SkOpAngle* rh, bool* inside) const { |
| 637 | const SkOpSegment* segment = this->segment(); |
| 638 | SkPath::Verb verb = segment->verb(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 639 | SkDLine rayEnd; |
| 640 | rayEnd[0].set(this->fEnd->pt()); |
| 641 | rayEnd[1] = rayEnd[0]; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 642 | SkDVector slopeAtEnd = (*CurveDSlopeAtT[verb])(segment->pts(), segment->weight(), |
| 643 | this->fEnd->t()); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 644 | rayEnd[1].fX += slopeAtEnd.fY; |
| 645 | rayEnd[1].fY -= slopeAtEnd.fX; |
| 646 | SkIntersections iEnd; |
| 647 | const SkOpSegment* oppSegment = rh->segment(); |
| 648 | SkPath::Verb oppVerb = oppSegment->verb(); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 649 | (*CurveIntersectRay[oppVerb])(oppSegment->pts(), oppSegment->weight(), rayEnd, &iEnd); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 650 | double endDist; |
| 651 | int closestEnd = iEnd.closestTo(rh->fStart->t(), rh->fEnd->t(), rayEnd[0], &endDist); |
| 652 | if (closestEnd < 0) { |
| 653 | return false; |
| 654 | } |
| 655 | if (!endDist) { |
| 656 | return false; |
| 657 | } |
| 658 | SkDPoint start; |
| 659 | start.set(this->fStart->pt()); |
| 660 | // OPTIMIZATION: multiple times in the code we find the max scalar |
| 661 | double minX, minY, maxX, maxY; |
| 662 | minX = minY = SK_ScalarInfinity; |
| 663 | maxX = maxY = -SK_ScalarInfinity; |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 664 | const SkDCurve& curve = rh->fPart.fCurve; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 665 | int oppPts = SkPathOpsVerbToPoints(oppVerb); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 666 | for (int idx2 = 0; idx2 <= oppPts; ++idx2) { |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 667 | minX = std::min(minX, curve[idx2].fX); |
| 668 | minY = std::min(minY, curve[idx2].fY); |
| 669 | maxX = std::max(maxX, curve[idx2].fX); |
| 670 | maxY = std::max(maxY, curve[idx2].fY); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 671 | } |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 672 | double maxWidth = std::max(maxX - minX, maxY - minY); |
Cary Clark | db018db | 2018-10-24 08:34:24 -0400 | [diff] [blame] | 673 | endDist = sk_ieee_double_divide(endDist, maxWidth); |
| 674 | if (!(endDist >= 5e-12)) { // empirically found |
| 675 | return false; // ! above catches NaN |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 676 | } |
| 677 | const SkDPoint* endPt = &rayEnd[0]; |
| 678 | SkDPoint oppPt = iEnd.pt(closestEnd); |
| 679 | SkDVector vLeft = *endPt - start; |
| 680 | SkDVector vRight = oppPt - start; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 681 | double dir = vLeft.crossNoNormalCheck(vRight); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 682 | if (!dir) { |
| 683 | return false; |
| 684 | } |
| 685 | *inside = dir < 0; |
| 686 | return true; |
| 687 | } |
| 688 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 689 | /* y<0 y==0 y>0 x<0 x==0 x>0 xy<0 xy==0 xy>0 |
| 690 | 0 x x x |
| 691 | 1 x x x |
| 692 | 2 x x x |
| 693 | 3 x x x |
| 694 | 4 x x x |
| 695 | 5 x x x |
| 696 | 6 x x x |
| 697 | 7 x x x |
| 698 | 8 x x x |
| 699 | 9 x x x |
| 700 | 10 x x x |
| 701 | 11 x x x |
| 702 | 12 x x x |
| 703 | 13 x x x |
| 704 | 14 x x x |
| 705 | 15 x x x |
| 706 | */ |
| 707 | int SkOpAngle::findSector(SkPath::Verb verb, double x, double y) const { |
| 708 | double absX = fabs(x); |
| 709 | double absY = fabs(y); |
| 710 | double xy = SkPath::kLine_Verb == verb || !AlmostEqualUlps(absX, absY) ? absX - absY : 0; |
| 711 | // If there are four quadrants and eight octants, and since the Latin for sixteen is sedecim, |
| 712 | // one could coin the term sedecimant for a space divided into 16 sections. |
| 713 | // http://english.stackexchange.com/questions/133688/word-for-something-partitioned-into-16-parts |
| 714 | static const int sedecimant[3][3][3] = { |
| 715 | // y<0 y==0 y>0 |
| 716 | // x<0 x==0 x>0 x<0 x==0 x>0 x<0 x==0 x>0 |
| 717 | {{ 4, 3, 2}, { 7, -1, 15}, {10, 11, 12}}, // abs(x) < abs(y) |
| 718 | {{ 5, -1, 1}, {-1, -1, -1}, { 9, -1, 13}}, // abs(x) == abs(y) |
| 719 | {{ 6, 3, 0}, { 7, -1, 15}, { 8, 11, 14}}, // abs(x) > abs(y) |
| 720 | }; |
| 721 | int sector = sedecimant[(xy >= 0) + (xy > 0)][(y >= 0) + (y > 0)][(x >= 0) + (x > 0)] * 2 + 1; |
caryclark | 65b427c | 2014-09-18 10:32:57 -0700 | [diff] [blame] | 722 | // SkASSERT(SkPath::kLine_Verb == verb || sector >= 0); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 723 | return sector; |
| 724 | } |
| 725 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 726 | SkOpGlobalState* SkOpAngle::globalState() const { |
| 727 | return this->segment()->globalState(); |
| 728 | } |
| 729 | |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 730 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 731 | // OPTIMIZE: if this loops to only one other angle, after first compare fails, insert on other side |
| 732 | // OPTIMIZE: return where insertion succeeded. Then, start next insertion on opposite side |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 733 | bool SkOpAngle::insert(SkOpAngle* angle) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 734 | if (angle->fNext) { |
| 735 | if (loopCount() >= angle->loopCount()) { |
| 736 | if (!merge(angle)) { |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 737 | return true; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 738 | } |
| 739 | } else if (fNext) { |
| 740 | if (!angle->merge(this)) { |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 741 | return true; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 742 | } |
| 743 | } else { |
| 744 | angle->insert(this); |
| 745 | } |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 746 | return true; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 747 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 748 | bool singleton = nullptr == fNext; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 749 | if (singleton) { |
| 750 | fNext = this; |
| 751 | } |
| 752 | SkOpAngle* next = fNext; |
| 753 | if (next->fNext == this) { |
| 754 | if (singleton || angle->after(this)) { |
| 755 | this->fNext = angle; |
| 756 | angle->fNext = next; |
| 757 | } else { |
| 758 | next->fNext = angle; |
| 759 | angle->fNext = this; |
| 760 | } |
| 761 | debugValidateNext(); |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 762 | return true; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 763 | } |
| 764 | SkOpAngle* last = this; |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 765 | bool flipAmbiguity = false; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 766 | do { |
| 767 | SkASSERT(last->fNext == next); |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 768 | if (angle->after(last) ^ (angle->tangentsAmbiguous() & flipAmbiguity)) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 769 | last->fNext = angle; |
| 770 | angle->fNext = next; |
| 771 | debugValidateNext(); |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 772 | return true; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 773 | } |
| 774 | last = next; |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 775 | if (last == this) { |
| 776 | FAIL_IF(flipAmbiguity); |
| 777 | // We're in a loop. If a sort was ambiguous, flip it to end the loop. |
| 778 | flipAmbiguity = true; |
| 779 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 780 | next = next->fNext; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 781 | } while (true); |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 782 | return true; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 783 | } |
| 784 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 785 | SkOpSpanBase* SkOpAngle::lastMarked() const { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 786 | if (fLastMarked) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 787 | if (fLastMarked->chased()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 788 | return nullptr; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 789 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 790 | fLastMarked->setChased(true); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 791 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 792 | return fLastMarked; |
| 793 | } |
| 794 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 795 | bool SkOpAngle::loopContains(const SkOpAngle* angle) const { |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 796 | if (!fNext) { |
| 797 | return false; |
| 798 | } |
| 799 | const SkOpAngle* first = this; |
| 800 | const SkOpAngle* loop = this; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 801 | const SkOpSegment* tSegment = angle->fStart->segment(); |
| 802 | double tStart = angle->fStart->t(); |
| 803 | double tEnd = angle->fEnd->t(); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 804 | do { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 805 | const SkOpSegment* lSegment = loop->fStart->segment(); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 806 | if (lSegment != tSegment) { |
| 807 | continue; |
| 808 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 809 | double lStart = loop->fStart->t(); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 810 | if (lStart != tEnd) { |
| 811 | continue; |
| 812 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 813 | double lEnd = loop->fEnd->t(); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 814 | if (lEnd == tStart) { |
| 815 | return true; |
| 816 | } |
| 817 | } while ((loop = loop->fNext) != first); |
| 818 | return false; |
| 819 | } |
| 820 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 821 | int SkOpAngle::loopCount() const { |
| 822 | int count = 0; |
| 823 | const SkOpAngle* first = this; |
| 824 | const SkOpAngle* next = this; |
| 825 | do { |
| 826 | next = next->fNext; |
| 827 | ++count; |
| 828 | } while (next && next != first); |
| 829 | return count; |
| 830 | } |
| 831 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 832 | bool SkOpAngle::merge(SkOpAngle* angle) { |
| 833 | SkASSERT(fNext); |
| 834 | SkASSERT(angle->fNext); |
| 835 | SkOpAngle* working = angle; |
| 836 | do { |
| 837 | if (this == working) { |
| 838 | return false; |
| 839 | } |
| 840 | working = working->fNext; |
| 841 | } while (working != angle); |
| 842 | do { |
| 843 | SkOpAngle* next = working->fNext; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 844 | working->fNext = nullptr; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 845 | insert(working); |
| 846 | working = next; |
| 847 | } while (working != angle); |
| 848 | // it's likely that a pair of the angles are unorderable |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 849 | debugValidateNext(); |
| 850 | return true; |
| 851 | } |
| 852 | |
| 853 | double SkOpAngle::midT() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 854 | return (fStart->t() + fEnd->t()) / 2; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 855 | } |
| 856 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 857 | bool SkOpAngle::midToSide(const SkOpAngle* rh, bool* inside) const { |
| 858 | const SkOpSegment* segment = this->segment(); |
| 859 | SkPath::Verb verb = segment->verb(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 860 | const SkPoint& startPt = this->fStart->pt(); |
| 861 | const SkPoint& endPt = this->fEnd->pt(); |
| 862 | SkDPoint dStartPt; |
| 863 | dStartPt.set(startPt); |
| 864 | SkDLine rayMid; |
| 865 | rayMid[0].fX = (startPt.fX + endPt.fX) / 2; |
| 866 | rayMid[0].fY = (startPt.fY + endPt.fY) / 2; |
| 867 | rayMid[1].fX = rayMid[0].fX + (endPt.fY - startPt.fY); |
| 868 | rayMid[1].fY = rayMid[0].fY - (endPt.fX - startPt.fX); |
| 869 | SkIntersections iMid; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 870 | (*CurveIntersectRay[verb])(segment->pts(), segment->weight(), rayMid, &iMid); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 871 | int iOutside = iMid.mostOutside(this->fStart->t(), this->fEnd->t(), dStartPt); |
| 872 | if (iOutside < 0) { |
| 873 | return false; |
| 874 | } |
| 875 | const SkOpSegment* oppSegment = rh->segment(); |
| 876 | SkPath::Verb oppVerb = oppSegment->verb(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 877 | SkIntersections oppMid; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 878 | (*CurveIntersectRay[oppVerb])(oppSegment->pts(), oppSegment->weight(), rayMid, &oppMid); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 879 | int oppOutside = oppMid.mostOutside(rh->fStart->t(), rh->fEnd->t(), dStartPt); |
| 880 | if (oppOutside < 0) { |
| 881 | return false; |
| 882 | } |
| 883 | SkDVector iSide = iMid.pt(iOutside) - dStartPt; |
| 884 | SkDVector oppSide = oppMid.pt(oppOutside) - dStartPt; |
| 885 | double dir = iSide.crossCheck(oppSide); |
| 886 | if (!dir) { |
| 887 | return false; |
| 888 | } |
| 889 | *inside = dir < 0; |
| 890 | return true; |
| 891 | } |
| 892 | |
| 893 | bool SkOpAngle::oppositePlanes(const SkOpAngle* rh) const { |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 894 | int startSpan = SkTAbs(rh->fSectorStart - fSectorStart); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 895 | return startSpan >= 8; |
| 896 | } |
| 897 | |
Cary Clark | ea2a632 | 2018-08-27 13:19:09 -0400 | [diff] [blame] | 898 | int SkOpAngle::orderable(SkOpAngle* rh) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 899 | int result; |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 900 | if (!fPart.isCurve()) { |
| 901 | if (!rh->fPart.isCurve()) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 902 | double leftX = fTangentHalf.dx(); |
| 903 | double leftY = fTangentHalf.dy(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 904 | double rightX = rh->fTangentHalf.dx(); |
| 905 | double rightY = rh->fTangentHalf.dy(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 906 | double x_ry = leftX * rightY; |
| 907 | double rx_y = rightX * leftY; |
| 908 | if (x_ry == rx_y) { |
| 909 | if (leftX * rightX < 0 || leftY * rightY < 0) { |
Cary Clark | ea2a632 | 2018-08-27 13:19:09 -0400 | [diff] [blame] | 910 | return 1; // exactly 180 degrees apart |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 911 | } |
| 912 | goto unorderable; |
| 913 | } |
| 914 | SkASSERT(x_ry != rx_y); // indicates an undetected coincidence -- worth finding earlier |
Cary Clark | ea2a632 | 2018-08-27 13:19:09 -0400 | [diff] [blame] | 915 | return x_ry < rx_y ? 1 : 0; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 916 | } |
Cary Clark | 9d6049a | 2018-12-21 13:13:10 -0500 | [diff] [blame] | 917 | if ((result = this->lineOnOneSide(rh, false)) >= 0) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 918 | return result; |
| 919 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 920 | if (fUnorderable || approximately_zero(rh->fSide)) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 921 | goto unorderable; |
| 922 | } |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 923 | } else if (!rh->fPart.isCurve()) { |
Cary Clark | 9d6049a | 2018-12-21 13:13:10 -0500 | [diff] [blame] | 924 | if ((result = rh->lineOnOneSide(this, false)) >= 0) { |
Cary Clark | ea2a632 | 2018-08-27 13:19:09 -0400 | [diff] [blame] | 925 | return result ? 0 : 1; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 926 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 927 | if (rh->fUnorderable || approximately_zero(fSide)) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 928 | goto unorderable; |
| 929 | } |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 930 | } else if ((result = this->convexHullOverlaps(rh)) >= 0) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 931 | return result; |
| 932 | } |
Cary Clark | ea2a632 | 2018-08-27 13:19:09 -0400 | [diff] [blame] | 933 | return this->endsIntersect(rh) ? 1 : 0; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 934 | unorderable: |
| 935 | fUnorderable = true; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 936 | rh->fUnorderable = true; |
Cary Clark | ea2a632 | 2018-08-27 13:19:09 -0400 | [diff] [blame] | 937 | return -1; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | // OPTIMIZE: if this shows up in a profile, add a previous pointer |
| 941 | // as is, this should be rarely called |
| 942 | SkOpAngle* SkOpAngle::previous() const { |
| 943 | SkOpAngle* last = fNext; |
| 944 | do { |
| 945 | SkOpAngle* next = last->fNext; |
| 946 | if (next == this) { |
| 947 | return last; |
| 948 | } |
| 949 | last = next; |
| 950 | } while (true); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 951 | } |
| 952 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 953 | SkOpSegment* SkOpAngle::segment() const { |
| 954 | return fStart->segment(); |
| 955 | } |
| 956 | |
| 957 | void SkOpAngle::set(SkOpSpanBase* start, SkOpSpanBase* end) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 958 | fStart = start; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 959 | fComputedEnd = fEnd = end; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 960 | SkASSERT(start != end); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 961 | fNext = nullptr; |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 962 | fComputeSector = fComputedSector = fCheckCoincidence = fTangentsAmbiguous = false; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 963 | setSpans(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 964 | setSector(); |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 965 | SkDEBUGCODE(fID = start ? start->globalState()->nextAngleID() : -1); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 966 | } |
| 967 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 968 | void SkOpAngle::setSpans() { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 969 | fUnorderable = false; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 970 | fLastMarked = nullptr; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 971 | if (!fStart) { |
| 972 | fUnorderable = true; |
| 973 | return; |
| 974 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 975 | const SkOpSegment* segment = fStart->segment(); |
| 976 | const SkPoint* pts = segment->pts(); |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 977 | SkDEBUGCODE(fPart.fCurve.fVerb = SkPath::kCubic_Verb); // required for SkDCurve debug check |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 978 | SkDEBUGCODE(fPart.fCurve[2].fX = fPart.fCurve[2].fY = fPart.fCurve[3].fX = fPart.fCurve[3].fY |
caryclark | 6c3b9cd | 2016-09-26 05:36:58 -0700 | [diff] [blame] | 979 | = SK_ScalarNaN); // make the non-line part uninitialized |
| 980 | SkDEBUGCODE(fPart.fCurve.fVerb = segment->verb()); // set the curve type for real |
| 981 | segment->subDivide(fStart, fEnd, &fPart.fCurve); // set at least the line part if not more |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 982 | fOriginalCurvePart = fPart.fCurve; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 983 | const SkPath::Verb verb = segment->verb(); |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 984 | fPart.setCurveHullSweep(verb); |
| 985 | if (SkPath::kLine_Verb != verb && !fPart.isCurve()) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 986 | SkDLine lineHalf; |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 987 | fPart.fCurve[1] = fPart.fCurve[SkPathOpsVerbToPoints(verb)]; |
| 988 | fOriginalCurvePart[1] = fPart.fCurve[1]; |
| 989 | lineHalf[0].set(fPart.fCurve[0].asSkPoint()); |
| 990 | lineHalf[1].set(fPart.fCurve[1].asSkPoint()); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 991 | fTangentHalf.lineEndPoints(lineHalf); |
| 992 | fSide = 0; |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 993 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 994 | switch (verb) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 995 | case SkPath::kLine_Verb: { |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 996 | SkASSERT(fStart != fEnd); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 997 | const SkPoint& cP1 = pts[fStart->t() < fEnd->t()]; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 998 | SkDLine lineHalf; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 999 | lineHalf[0].set(fStart->pt()); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1000 | lineHalf[1].set(cP1); |
| 1001 | fTangentHalf.lineEndPoints(lineHalf); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1002 | fSide = 0; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1003 | } return; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1004 | case SkPath::kQuad_Verb: |
| 1005 | case SkPath::kConic_Verb: { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1006 | SkLineParameters tangentPart; |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 1007 | (void) tangentPart.quadEndPoints(fPart.fCurve.fQuad); |
| 1008 | fSide = -tangentPart.pointDistance(fPart.fCurve[2]); // not normalized -- compare sign only |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 1009 | } break; |
| 1010 | case SkPath::kCubic_Verb: { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1011 | SkLineParameters tangentPart; |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 1012 | (void) tangentPart.cubicPart(fPart.fCurve.fCubic); |
| 1013 | fSide = -tangentPart.pointDistance(fPart.fCurve[3]); |
caryclark@google.com | b3f0921 | 2013-04-17 15:49:16 +0000 | [diff] [blame] | 1014 | double testTs[4]; |
| 1015 | // OPTIMIZATION: keep inflections precomputed with cubic segment? |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 1016 | int testCount = SkDCubic::FindInflections(pts, testTs); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1017 | double startT = fStart->t(); |
| 1018 | double endT = fEnd->t(); |
caryclark@google.com | b3f0921 | 2013-04-17 15:49:16 +0000 | [diff] [blame] | 1019 | double limitT = endT; |
| 1020 | int index; |
| 1021 | for (index = 0; index < testCount; ++index) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1022 | if (!::between(startT, testTs[index], limitT)) { |
caryclark@google.com | b3f0921 | 2013-04-17 15:49:16 +0000 | [diff] [blame] | 1023 | testTs[index] = -1; |
| 1024 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1025 | } |
caryclark@google.com | b3f0921 | 2013-04-17 15:49:16 +0000 | [diff] [blame] | 1026 | testTs[testCount++] = startT; |
| 1027 | testTs[testCount++] = endT; |
John Stiles | 70474c1 | 2020-07-13 18:09:07 -0400 | [diff] [blame^] | 1028 | std::sort(testTs, testTs + testCount); |
caryclark@google.com | b3f0921 | 2013-04-17 15:49:16 +0000 | [diff] [blame] | 1029 | double bestSide = 0; |
| 1030 | int testCases = (testCount << 1) - 1; |
| 1031 | index = 0; |
| 1032 | while (testTs[index] < 0) { |
| 1033 | ++index; |
| 1034 | } |
| 1035 | index <<= 1; |
| 1036 | for (; index < testCases; ++index) { |
| 1037 | int testIndex = index >> 1; |
| 1038 | double testT = testTs[testIndex]; |
| 1039 | if (index & 1) { |
| 1040 | testT = (testT + testTs[testIndex + 1]) / 2; |
| 1041 | } |
| 1042 | // OPTIMIZE: could avoid call for t == startT, endT |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1043 | SkDPoint pt = dcubic_xy_at_t(pts, segment->weight(), testT); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1044 | SkLineParameters tangentPart; |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 1045 | tangentPart.cubicEndPoints(fPart.fCurve.fCubic); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1046 | double testSide = tangentPart.pointDistance(pt); |
caryclark@google.com | b3f0921 | 2013-04-17 15:49:16 +0000 | [diff] [blame] | 1047 | if (fabs(bestSide) < fabs(testSide)) { |
| 1048 | bestSide = testSide; |
| 1049 | } |
| 1050 | } |
| 1051 | fSide = -bestSide; // compare sign only |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1052 | } break; |
| 1053 | default: |
| 1054 | SkASSERT(0); |
| 1055 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1056 | } |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 1057 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1058 | void SkOpAngle::setSector() { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 1059 | if (!fStart) { |
| 1060 | fUnorderable = true; |
| 1061 | return; |
| 1062 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1063 | const SkOpSegment* segment = fStart->segment(); |
| 1064 | SkPath::Verb verb = segment->verb(); |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 1065 | fSectorStart = this->findSector(verb, fPart.fSweep[0].fX, fPart.fSweep[0].fY); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1066 | if (fSectorStart < 0) { |
| 1067 | goto deferTilLater; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1068 | } |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 1069 | if (!fPart.isCurve()) { // if it's a line or line-like, note that both sectors are the same |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1070 | SkASSERT(fSectorStart >= 0); |
| 1071 | fSectorEnd = fSectorStart; |
| 1072 | fSectorMask = 1 << fSectorStart; |
| 1073 | return; |
| 1074 | } |
| 1075 | SkASSERT(SkPath::kLine_Verb != verb); |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 1076 | fSectorEnd = this->findSector(verb, fPart.fSweep[1].fX, fPart.fSweep[1].fY); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1077 | if (fSectorEnd < 0) { |
| 1078 | deferTilLater: |
| 1079 | fSectorStart = fSectorEnd = -1; |
| 1080 | fSectorMask = 0; |
| 1081 | fComputeSector = true; // can't determine sector until segment length can be found |
| 1082 | return; |
| 1083 | } |
| 1084 | if (fSectorEnd == fSectorStart |
| 1085 | && (fSectorStart & 3) != 3) { // if the sector has no span, it can't be an exact angle |
| 1086 | fSectorMask = 1 << fSectorStart; |
| 1087 | return; |
| 1088 | } |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 1089 | bool crossesZero = this->checkCrossesZero(); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1090 | int start = std::min(fSectorStart, fSectorEnd); |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 1091 | bool curveBendsCCW = (fSectorStart == start) ^ crossesZero; |
| 1092 | // bump the start and end of the sector span if they are on exact compass points |
| 1093 | if ((fSectorStart & 3) == 3) { |
| 1094 | fSectorStart = (fSectorStart + (curveBendsCCW ? 1 : 31)) & 0x1f; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1095 | } |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 1096 | if ((fSectorEnd & 3) == 3) { |
| 1097 | fSectorEnd = (fSectorEnd + (curveBendsCCW ? 31 : 1)) & 0x1f; |
| 1098 | } |
| 1099 | crossesZero = this->checkCrossesZero(); |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 1100 | start = std::min(fSectorStart, fSectorEnd); |
| 1101 | int end = std::max(fSectorStart, fSectorEnd); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1102 | if (!crossesZero) { |
| 1103 | fSectorMask = (unsigned) -1 >> (31 - end + start) << start; |
| 1104 | } else { |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 1105 | fSectorMask = (unsigned) -1 >> (31 - start) | ((unsigned) -1 << end); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1106 | } |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 1107 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1108 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1109 | SkOpSpan* SkOpAngle::starter() { |
| 1110 | return fStart->starter(fEnd); |
| 1111 | } |
| 1112 | |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 1113 | bool SkOpAngle::tangentsDiverge(const SkOpAngle* rh, double s0xt0) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1114 | if (s0xt0 == 0) { |
| 1115 | return false; |
| 1116 | } |
| 1117 | // if the ctrl tangents are not nearly parallel, use them |
| 1118 | // solve for opposite direction displacement scale factor == m |
| 1119 | // initial dir = v1.cross(v2) == v2.x * v1.y - v2.y * v1.x |
| 1120 | // displacement of q1[1] : dq1 = { -m * v1.y, m * v1.x } + q1[1] |
| 1121 | // straight angle when : v2.x * (dq1.y - q1[0].y) == v2.y * (dq1.x - q1[0].x) |
| 1122 | // v2.x * (m * v1.x + v1.y) == v2.y * (-m * v1.y + v1.x) |
| 1123 | // - m * (v2.x * v1.x + v2.y * v1.y) == v2.x * v1.y - v2.y * v1.x |
| 1124 | // m = (v2.y * v1.x - v2.x * v1.y) / (v2.x * v1.x + v2.y * v1.y) |
| 1125 | // m = v1.cross(v2) / v1.dot(v2) |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 1126 | const SkDVector* sweep = fPart.fSweep; |
| 1127 | const SkDVector* tweep = rh->fPart.fSweep; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1128 | double s0dt0 = sweep[0].dot(tweep[0]); |
| 1129 | if (!s0dt0) { |
| 1130 | return true; |
| 1131 | } |
| 1132 | SkASSERT(s0dt0 != 0); |
| 1133 | double m = s0xt0 / s0dt0; |
| 1134 | double sDist = sweep[0].length() * m; |
| 1135 | double tDist = tweep[0].length() * m; |
| 1136 | bool useS = fabs(sDist) < fabs(tDist); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 1137 | double mFactor = fabs(useS ? this->distEndRatio(sDist) : rh->distEndRatio(tDist)); |
caryclark | b36a3cd | 2016-10-18 07:59:44 -0700 | [diff] [blame] | 1138 | fTangentsAmbiguous = mFactor >= 50 && mFactor < 200; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 1139 | return mFactor < 50; // empirically found limit |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 1140 | } |