2012-08-27 14:11:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2012-06-01 17:44:28 +00:00
|
|
|
#include "CurveIntersection.h"
|
2012-07-02 20:27:02 +00:00
|
|
|
#include "CurveUtilities.h"
|
2012-04-26 21:01:06 +00:00
|
|
|
#include "Extrema.h"
|
|
|
|
|
|
|
|
double leftMostT(const Quadratic& quad, double startT, double endT) {
|
|
|
|
double leftT;
|
|
|
|
if (findExtrema(quad[0].x, quad[1].x, quad[2].x, &leftT)
|
|
|
|
&& startT <= leftT && leftT <= endT) {
|
|
|
|
return leftT;
|
|
|
|
}
|
|
|
|
_Point startPt;
|
|
|
|
xy_at_t(quad, startT, startPt.x, startPt.y);
|
|
|
|
_Point endPt;
|
|
|
|
xy_at_t(quad, endT, endPt.x, endPt.y);
|
|
|
|
return startPt.x <= endPt.x ? startT : endT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _Rect::setBounds(const Quadratic& quad) {
|
|
|
|
set(quad[0]);
|
|
|
|
add(quad[2]);
|
|
|
|
double tValues[2];
|
|
|
|
int roots = 0;
|
2013-02-14 15:29:11 +00:00
|
|
|
if (!between(quad[0].x, quad[1].x, quad[2].x)) {
|
2012-04-26 21:01:06 +00:00
|
|
|
roots = findExtrema(quad[0].x, quad[1].x, quad[2].x, tValues);
|
|
|
|
}
|
2013-02-14 15:29:11 +00:00
|
|
|
if (!between(quad[0].y, quad[1].y, quad[2].y)) {
|
|
|
|
roots += findExtrema(quad[0].y, quad[1].y, quad[2].y, &tValues[roots]);
|
2012-04-26 21:01:06 +00:00
|
|
|
}
|
|
|
|
for (int x = 0; x < roots; ++x) {
|
|
|
|
_Point result;
|
|
|
|
xy_at_t(quad, tValues[x], result.x, result.y);
|
|
|
|
add(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _Rect::setRawBounds(const Quadratic& quad) {
|
|
|
|
set(quad[0]);
|
|
|
|
for (int x = 1; x < 3; ++x) {
|
|
|
|
add(quad[x]);
|
|
|
|
}
|
|
|
|
}
|