caryclark@google.com | 9e49fb6 | 2012-08-27 14:11:33 +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 | */ |
caryclark@google.com | a3f05fa | 2012-06-01 17:44:28 +0000 | [diff] [blame] | 7 | #include "CurveIntersection.h" |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 8 | #include "CurveUtilities.h" |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 9 | #include "Extrema.h" |
| 10 | |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 11 | double leftMostT(const Quadratic& quad, double startT, double endT) { |
| 12 | double leftT; |
| 13 | if (findExtrema(quad[0].x, quad[1].x, quad[2].x, &leftT) |
| 14 | && startT <= leftT && leftT <= endT) { |
| 15 | return leftT; |
| 16 | } |
| 17 | _Point startPt; |
| 18 | xy_at_t(quad, startT, startPt.x, startPt.y); |
| 19 | _Point endPt; |
| 20 | xy_at_t(quad, endT, endPt.x, endPt.y); |
| 21 | return startPt.x <= endPt.x ? startT : endT; |
| 22 | } |
| 23 | |
| 24 | void _Rect::setBounds(const Quadratic& quad) { |
| 25 | set(quad[0]); |
| 26 | add(quad[2]); |
| 27 | double tValues[2]; |
| 28 | int roots = 0; |
caryclark@google.com | 45a8fc6 | 2013-02-14 15:29:11 +0000 | [diff] [blame^] | 29 | if (!between(quad[0].x, quad[1].x, quad[2].x)) { |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 30 | roots = findExtrema(quad[0].x, quad[1].x, quad[2].x, tValues); |
| 31 | } |
caryclark@google.com | 45a8fc6 | 2013-02-14 15:29:11 +0000 | [diff] [blame^] | 32 | if (!between(quad[0].y, quad[1].y, quad[2].y)) { |
| 33 | roots += findExtrema(quad[0].y, quad[1].y, quad[2].y, &tValues[roots]); |
caryclark@google.com | fa0588f | 2012-04-26 21:01:06 +0000 | [diff] [blame] | 34 | } |
| 35 | for (int x = 0; x < roots; ++x) { |
| 36 | _Point result; |
| 37 | xy_at_t(quad, tValues[x], result.x, result.y); |
| 38 | add(result); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | void _Rect::setRawBounds(const Quadratic& quad) { |
| 43 | set(quad[0]); |
| 44 | for (int x = 1; x < 3; ++x) { |
| 45 | add(quad[x]); |
| 46 | } |
| 47 | } |