blob: 193743b04ac7f3f40644a8f985cc4f89e9aa9e3c [file] [log] [blame]
caryclark@google.com9e49fb62012-08-27 14:11:33 +00001/*
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.coma3f05fa2012-06-01 17:44:28 +00007#include "CurveIntersection.h"
caryclark@google.com8dcf1142012-07-02 20:27:02 +00008#include "CurveUtilities.h"
caryclark@google.comfa0588f2012-04-26 21:01:06 +00009#include "Extrema.h"
10
caryclark@google.comfa0588f2012-04-26 21:01:06 +000011double 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
24void _Rect::setBounds(const Quadratic& quad) {
25 set(quad[0]);
26 add(quad[2]);
27 double tValues[2];
28 int roots = 0;
caryclark@google.com45a8fc62013-02-14 15:29:11 +000029 if (!between(quad[0].x, quad[1].x, quad[2].x)) {
caryclark@google.comfa0588f2012-04-26 21:01:06 +000030 roots = findExtrema(quad[0].x, quad[1].x, quad[2].x, tValues);
31 }
caryclark@google.com45a8fc62013-02-14 15:29:11 +000032 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.comfa0588f2012-04-26 21:01:06 +000034 }
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
42void _Rect::setRawBounds(const Quadratic& quad) {
43 set(quad[0]);
44 for (int x = 1; x < 3; ++x) {
45 add(quad[x]);
46 }
47}