8dcf114db9
M Intersection/DataTypes.cpp M Intersection/QuadraticIntersection_Test.cpp M Intersection/EdgeWalker.cpp M Intersection/LineQuadraticIntersection_Test.cpp M Intersection/LineIntersection_Test.cpp M Intersection/LineIntersection.cpp D Intersection/edge.xcodeproj M Intersection/SimplifyFindTop_Test.cpp M Intersection/DataTypes.h A Intersection/SimplifyRect4x4_Test.cpp M Intersection/CubicIntersection_Test.cpp M Intersection/QuadraticUtilities.h M Intersection/LineCubicIntersection_Test.cpp A Intersection/CurveUtilities.h M Intersection/QuadraticBezierClip.cpp M Intersection/QuadraticBounds.cpp M Intersection/LineUtilities.h M Intersection/Intersection_Tests.cpp M Intersection/Simplify.cpp M Intersection/EdgeWalker_TestUtility.cpp M Intersection/QuadraticUtilities.cpp M Intersection/thingsToDo.txt M Intersection/LineUtilities.cpp M Intersection/CubicUtilities.h M Intersection/SimplifyFindNext_Test.cpp M Intersection/Intersection_Tests.h M Intersection/CubicBezierClip.cpp M Intersection/ActiveEdge_Test.cpp M Intersection/CubicBounds.cpp M Intersection/Simplify.h M Intersection/SimplifyNew_Test.cpp M Intersection/EdgeWalker_Test.h M Intersection/CubicUtilities.cpp M Intersection/op.htm M Intersection/ConvexHull.cpp D Intersection/RectUtilities.cpp M Intersection/SimplifyAddIntersectingTs_Test.cpp git-svn-id: http://skia.googlecode.com/svn/trunk@4429 2bbb7eff-a529-9590-31e7-b0007b416f81
65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
#include "CurveIntersection.h"
|
|
#include "CurveUtilities.h"
|
|
#include "Extrema.h"
|
|
|
|
static int isBoundedByEndPoints(double a, double b, double c, double d)
|
|
{
|
|
return (a <= b && a <= c && b <= d && c <= d)
|
|
|| (a >= b && a >= c && b >= d && c >= d);
|
|
}
|
|
|
|
double leftMostT(const Cubic& cubic, double startT, double endT) {
|
|
double leftTs[2];
|
|
_Point pt[2];
|
|
int results = findExtrema(cubic[0].x, cubic[1].x, cubic[2].x, cubic[3].x,
|
|
leftTs);
|
|
int best = -1;
|
|
for (int index = 0; index < results; ++index) {
|
|
if (startT > leftTs[index] || leftTs[index] > endT) {
|
|
continue;
|
|
}
|
|
if (best < 0) {
|
|
best = index;
|
|
continue;
|
|
}
|
|
xy_at_t(cubic, leftTs[0], pt[0].x, pt[0].y);
|
|
xy_at_t(cubic, leftTs[1], pt[1].x, pt[1].y);
|
|
if (pt[0].x > pt[1].x) {
|
|
best = 1;
|
|
}
|
|
}
|
|
if (best >= 0) {
|
|
return leftTs[best];
|
|
}
|
|
xy_at_t(cubic, startT, pt[0].x, pt[0].y);
|
|
xy_at_t(cubic, endT, pt[1].x, pt[1].y);
|
|
return pt[0].x <= pt[1].x ? startT : endT;
|
|
}
|
|
|
|
void _Rect::setBounds(const Cubic& cubic) {
|
|
set(cubic[0]);
|
|
add(cubic[3]);
|
|
double tValues[4];
|
|
int roots = 0;
|
|
if (!isBoundedByEndPoints(cubic[0].x, cubic[1].x, cubic[2].x, cubic[3].x)) {
|
|
roots = findExtrema(cubic[0].x, cubic[1].x, cubic[2].x,
|
|
cubic[3].x, tValues);
|
|
}
|
|
if (!isBoundedByEndPoints(cubic[0].y, cubic[1].y, cubic[2].y, cubic[3].y)) {
|
|
roots += findExtrema(cubic[0].y, cubic[1].y, cubic[2].y,
|
|
cubic[3].y, &tValues[roots]);
|
|
}
|
|
for (int x = 0; x < roots; ++x) {
|
|
_Point result;
|
|
xy_at_t(cubic, tValues[x], result.x, result.y);
|
|
add(result);
|
|
}
|
|
}
|
|
|
|
void _Rect::setRawBounds(const Cubic& cubic) {
|
|
set(cubic[0]);
|
|
for (int x = 1; x < 4; ++x) {
|
|
add(cubic[x]);
|
|
}
|
|
}
|