caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame^] | 1 | #include "CurveIntersection.h" |
| 2 | |
| 3 | /* This rejects coincidence with two muls, two adds, and one cmp. |
| 4 | Coincident candidates will take another four muls and two adds, but may still |
| 5 | fail if they don't overlap. (The overlap test isn't performed here.) |
| 6 | */ |
| 7 | bool implicit_matches(const _Line& one, const _Line& two) { |
| 8 | _Point oneD, twoD; |
| 9 | tangent(one, oneD); |
| 10 | tangent(two, twoD); |
| 11 | /* See if the slopes match, i.e. |
| 12 | dx1 / dy1 == dx2 / dy2 |
| 13 | (dy1 * dy2) * dx1 / dy1 == (dy1 * dy2) * dx2 / dy2 |
| 14 | dy2 * dx1 == dy1 * dx2 |
| 15 | */ |
| 16 | if (!approximately_equal(oneD.x * twoD.y, twoD.x * oneD.y)) { |
| 17 | return false; |
| 18 | } |
| 19 | /* See if the axis intercepts match, i.e. |
| 20 | y0 - x0 * dy / dx == y1 - x1 * dy / dx |
| 21 | dx * (y0 - x0 * dy / dx) == dx * (y1 - x1 * dy / dx) |
| 22 | dx * y0 - x0 * dy == dx * y1 - x1 * dy |
| 23 | */ |
| 24 | if (!approximately_equal(oneD.x * one[0].y - oneD.y * one[0].x, |
| 25 | oneD.x * two[0].y - oneD.y * two[0].x)) { |
| 26 | return false; |
| 27 | } |
| 28 | return true; |
| 29 | } |
| 30 | |
| 31 | void tangent(const _Line& line, _Point& result) { |
| 32 | result.x = line[0].x - line[1].x; |
| 33 | result.y = line[0].y - line[1].y; |
| 34 | } |