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 */
7 #include "CurveIntersection.h"
8 #include "CurveUtilities.h"
9 #include "Extrema.h"
10
leftMostT(const Quadratic & quad,double startT,double endT)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
setBounds(const Quadratic & quad)24 void _Rect::setBounds(const Quadratic& quad) {
25 set(quad[0]);
26 add(quad[2]);
27 double tValues[2];
28 int roots = 0;
29 if (!between(quad[0].x, quad[1].x, quad[2].x)) {
30 roots = findExtrema(quad[0].x, quad[1].x, quad[2].x, tValues);
31 }
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]);
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
setRawBounds(const Quadratic & quad)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 }
48