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 "SkPathOpsLine.h" | 7 #include "SkPathOpsLine.h" |
8 | 8 |
9 SkDLine SkDLine::subDivide(double t1, double t2) const { | 9 SkDLine SkDLine::subDivide(double t1, double t2) const { |
10 SkDVector delta = tangent(); | 10 SkDVector delta = tangent(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 double realPtX = (1 - t) * left + t * right; | 145 double realPtX = (1 - t) * left + t * right; |
146 SkDVector distU = {xy.fY - y, xy.fX - realPtX}; | 146 SkDVector distU = {xy.fY - y, xy.fX - realPtX}; |
147 double distSq = distU.fX * distU.fX + distU.fY * distU.fY; | 147 double distSq = distU.fX * distU.fX + distU.fY * distU.fY; |
148 double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq i
nstead ? | 148 double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq i
nstead ? |
149 double tiniest = SkTMin(SkTMin(y, left), right); | 149 double tiniest = SkTMin(SkTMin(y, left), right); |
150 double largest = SkTMax(SkTMax(y, left), right); | 150 double largest = SkTMax(SkTMax(y, left), right); |
151 largest = SkTMax(largest, -tiniest); | 151 largest = SkTMax(largest, -tiniest); |
152 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS
tolerance? | 152 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS
tolerance? |
153 return -1; | 153 return -1; |
154 } | 154 } |
155 t = SkPinT(t); | |
156 SkASSERT(between(0, t, 1)); | |
157 return t; | 155 return t; |
158 } | 156 } |
159 | 157 |
160 double SkDLine::ExactPointV(const SkDPoint& xy, double top, double bottom, doubl
e x) { | 158 double SkDLine::ExactPointV(const SkDPoint& xy, double top, double bottom, doubl
e x) { |
161 if (xy.fX == x) { | 159 if (xy.fX == x) { |
162 if (xy.fY == top) { | 160 if (xy.fY == top) { |
163 return 0; | 161 return 0; |
164 } | 162 } |
165 if (xy.fY == bottom) { | 163 if (xy.fY == bottom) { |
166 return 1; | 164 return 1; |
(...skipping 15 matching lines...) Expand all Loading... |
182 double realPtY = (1 - t) * top + t * bottom; | 180 double realPtY = (1 - t) * top + t * bottom; |
183 SkDVector distU = {xy.fX - x, xy.fY - realPtY}; | 181 SkDVector distU = {xy.fX - x, xy.fY - realPtY}; |
184 double distSq = distU.fX * distU.fX + distU.fY * distU.fY; | 182 double distSq = distU.fX * distU.fX + distU.fY * distU.fY; |
185 double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq i
nstead ? | 183 double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq i
nstead ? |
186 double tiniest = SkTMin(SkTMin(x, top), bottom); | 184 double tiniest = SkTMin(SkTMin(x, top), bottom); |
187 double largest = SkTMax(SkTMax(x, top), bottom); | 185 double largest = SkTMax(SkTMax(x, top), bottom); |
188 largest = SkTMax(largest, -tiniest); | 186 largest = SkTMax(largest, -tiniest); |
189 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS
tolerance? | 187 if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS
tolerance? |
190 return -1; | 188 return -1; |
191 } | 189 } |
192 t = SkPinT(t); | |
193 SkASSERT(between(0, t, 1)); | |
194 return t; | 190 return t; |
195 } | 191 } |
196 | 192 |
197 #ifdef SK_DEBUG | 193 #ifdef SK_DEBUG |
198 void SkDLine::dump() { | 194 void SkDLine::dump() { |
199 SkDebugf("{{"); | 195 SkDebugf("{{"); |
200 fPts[0].dump(); | 196 fPts[0].dump(); |
201 SkDebugf(", "); | 197 SkDebugf(", "); |
202 fPts[1].dump(); | 198 fPts[1].dump(); |
203 SkDebugf("}}\n"); | 199 SkDebugf("}}\n"); |
204 } | 200 } |
205 #endif | 201 #endif |
OLD | NEW |