| 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 "SkIntersections.h" | 7 #include "SkIntersections.h" |
| 8 #include "SkPathOpsLine.h" | 8 #include "SkPathOpsLine.h" |
| 9 | 9 |
| 10 void SkIntersections::cleanUpParallelLines(bool parallel) { | 10 void SkIntersections::cleanUpParallelLines(bool parallel) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 181 } |
| 182 if (min > y || max < y) { | 182 if (min > y || max < y) { |
| 183 return 0; | 183 return 0; |
| 184 } | 184 } |
| 185 if (AlmostEqualUlps(min, max) && max - min < fabs(line[0].fX - line[1].fX))
{ | 185 if (AlmostEqualUlps(min, max) && max - min < fabs(line[0].fX - line[1].fX))
{ |
| 186 return 2; | 186 return 2; |
| 187 } | 187 } |
| 188 return 1; | 188 return 1; |
| 189 } | 189 } |
| 190 | 190 |
| 191 static double horizontal_intercept(const SkDLine& line, double y) { | 191 double SkIntersections::HorizontalIntercept(const SkDLine& line, double y) { |
| 192 return SkPinT((y - line[0].fY) / (line[1].fY - line[0].fY)); | 192 return SkPinT((y - line[0].fY) / (line[1].fY - line[0].fY)); |
| 193 } | 193 } |
| 194 | 194 |
| 195 int SkIntersections::horizontal(const SkDLine& line, double left, double right, | 195 int SkIntersections::horizontal(const SkDLine& line, double left, double right, |
| 196 double y, bool flipped) { | 196 double y, bool flipped) { |
| 197 fMax = 3; // clean up parallel at the end will limit the result to 2 at the
most | 197 fMax = 3; // clean up parallel at the end will limit the result to 2 at the
most |
| 198 // see if end points intersect the opposite line | 198 // see if end points intersect the opposite line |
| 199 double t; | 199 double t; |
| 200 const SkDPoint leftPt = { left, y }; | 200 const SkDPoint leftPt = { left, y }; |
| 201 if ((t = line.exactPoint(leftPt)) >= 0) { | 201 if ((t = line.exactPoint(leftPt)) >= 0) { |
| 202 insert(t, (double) flipped, leftPt); | 202 insert(t, (double) flipped, leftPt); |
| 203 } | 203 } |
| 204 if (left != right) { | 204 if (left != right) { |
| 205 const SkDPoint rightPt = { right, y }; | 205 const SkDPoint rightPt = { right, y }; |
| 206 if ((t = line.exactPoint(rightPt)) >= 0) { | 206 if ((t = line.exactPoint(rightPt)) >= 0) { |
| 207 insert(t, (double) !flipped, rightPt); | 207 insert(t, (double) !flipped, rightPt); |
| 208 } | 208 } |
| 209 for (int index = 0; index < 2; ++index) { | 209 for (int index = 0; index < 2; ++index) { |
| 210 if ((t = SkDLine::ExactPointH(line[index], left, right, y)) >= 0) { | 210 if ((t = SkDLine::ExactPointH(line[index], left, right, y)) >= 0) { |
| 211 insert((double) index, flipped ? 1 - t : t, line[index]); | 211 insert((double) index, flipped ? 1 - t : t, line[index]); |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 int result = horizontal_coincident(line, y); | 215 int result = horizontal_coincident(line, y); |
| 216 if (result == 1 && fUsed == 0) { | 216 if (result == 1 && fUsed == 0) { |
| 217 fT[0][0] = horizontal_intercept(line, y); | 217 fT[0][0] = HorizontalIntercept(line, y); |
| 218 double xIntercept = line[0].fX + fT[0][0] * (line[1].fX - line[0].fX); | 218 double xIntercept = line[0].fX + fT[0][0] * (line[1].fX - line[0].fX); |
| 219 if (between(left, xIntercept, right)) { | 219 if (between(left, xIntercept, right)) { |
| 220 fT[1][0] = (xIntercept - left) / (right - left); | 220 fT[1][0] = (xIntercept - left) / (right - left); |
| 221 if (flipped) { | 221 if (flipped) { |
| 222 // OPTIMIZATION: ? instead of swapping, pass original line, use
[1].fX - [0].fX | 222 // OPTIMIZATION: ? instead of swapping, pass original line, use
[1].fX - [0].fX |
| 223 for (int index = 0; index < result; ++index) { | 223 for (int index = 0; index < result; ++index) { |
| 224 fT[1][index] = 1 - fT[1][index]; | 224 fT[1][index] = 1 - fT[1][index]; |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 fPt[0].fX = xIntercept; | 227 fPt[0].fX = xIntercept; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 257 } | 257 } |
| 258 if (!precisely_between(min, x, max)) { | 258 if (!precisely_between(min, x, max)) { |
| 259 return 0; | 259 return 0; |
| 260 } | 260 } |
| 261 if (AlmostEqualUlps(min, max)) { | 261 if (AlmostEqualUlps(min, max)) { |
| 262 return 2; | 262 return 2; |
| 263 } | 263 } |
| 264 return 1; | 264 return 1; |
| 265 } | 265 } |
| 266 | 266 |
| 267 static double vertical_intercept(const SkDLine& line, double x) { | 267 double SkIntersections::VerticalIntercept(const SkDLine& line, double x) { |
| 268 return SkPinT((x - line[0].fX) / (line[1].fX - line[0].fX)); | 268 return SkPinT((x - line[0].fX) / (line[1].fX - line[0].fX)); |
| 269 } | 269 } |
| 270 | 270 |
| 271 int SkIntersections::vertical(const SkDLine& line, double top, double bottom, | 271 int SkIntersections::vertical(const SkDLine& line, double top, double bottom, |
| 272 double x, bool flipped) { | 272 double x, bool flipped) { |
| 273 fMax = 3; // cleanup parallel lines will bring this back line | 273 fMax = 3; // cleanup parallel lines will bring this back line |
| 274 // see if end points intersect the opposite line | 274 // see if end points intersect the opposite line |
| 275 double t; | 275 double t; |
| 276 SkDPoint topPt = { x, top }; | 276 SkDPoint topPt = { x, top }; |
| 277 if ((t = line.exactPoint(topPt)) >= 0) { | 277 if ((t = line.exactPoint(topPt)) >= 0) { |
| 278 insert(t, (double) flipped, topPt); | 278 insert(t, (double) flipped, topPt); |
| 279 } | 279 } |
| 280 if (top != bottom) { | 280 if (top != bottom) { |
| 281 SkDPoint bottomPt = { x, bottom }; | 281 SkDPoint bottomPt = { x, bottom }; |
| 282 if ((t = line.exactPoint(bottomPt)) >= 0) { | 282 if ((t = line.exactPoint(bottomPt)) >= 0) { |
| 283 insert(t, (double) !flipped, bottomPt); | 283 insert(t, (double) !flipped, bottomPt); |
| 284 } | 284 } |
| 285 for (int index = 0; index < 2; ++index) { | 285 for (int index = 0; index < 2; ++index) { |
| 286 if ((t = SkDLine::ExactPointV(line[index], top, bottom, x)) >= 0) { | 286 if ((t = SkDLine::ExactPointV(line[index], top, bottom, x)) >= 0) { |
| 287 insert((double) index, flipped ? 1 - t : t, line[index]); | 287 insert((double) index, flipped ? 1 - t : t, line[index]); |
| 288 } | 288 } |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 int result = vertical_coincident(line, x); | 291 int result = vertical_coincident(line, x); |
| 292 if (result == 1 && fUsed == 0) { | 292 if (result == 1 && fUsed == 0) { |
| 293 fT[0][0] = vertical_intercept(line, x); | 293 fT[0][0] = VerticalIntercept(line, x); |
| 294 double yIntercept = line[0].fY + fT[0][0] * (line[1].fY - line[0].fY); | 294 double yIntercept = line[0].fY + fT[0][0] * (line[1].fY - line[0].fY); |
| 295 if (between(top, yIntercept, bottom)) { | 295 if (between(top, yIntercept, bottom)) { |
| 296 fT[1][0] = (yIntercept - top) / (bottom - top); | 296 fT[1][0] = (yIntercept - top) / (bottom - top); |
| 297 if (flipped) { | 297 if (flipped) { |
| 298 // OPTIMIZATION: instead of swapping, pass original line, use [1
].fY - [0].fY | 298 // OPTIMIZATION: instead of swapping, pass original line, use [1
].fY - [0].fY |
| 299 for (int index = 0; index < result; ++index) { | 299 for (int index = 0; index < result; ++index) { |
| 300 fT[1][index] = 1 - fT[1][index]; | 300 fT[1][index] = 1 - fT[1][index]; |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 fPt[0].fX = x; | 303 fPt[0].fX = x; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 319 insert((double) index, flipped ? 1 - t : t, line[index]); | 319 insert((double) index, flipped ? 1 - t : t, line[index]); |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 cleanUpParallelLines(result == 2); | 324 cleanUpParallelLines(result == 2); |
| 325 SkASSERT(fUsed <= 2); | 325 SkASSERT(fUsed <= 2); |
| 326 return fUsed; | 326 return fUsed; |
| 327 } | 327 } |
| 328 | 328 |
| OLD | NEW |