skia2/experimental/Intersection/QuadraticUtilities.cpp
caryclark@google.com 8dcf114db9 shape ops work in progress
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
2012-07-02 20:27:02 +00:00

53 lines
1.3 KiB
C++

#include "QuadraticUtilities.h"
#include <math.h>
int quadraticRoots(double A, double B, double C, double t[2]) {
B *= 2;
double square = B * B - 4 * A * C;
if (square < 0) {
return 0;
}
double squareRt = sqrt(square);
double Q = (B + (B < 0 ? -squareRt : squareRt)) / -2;
double ratio;
int foundRoots = 0;
if ((Q <= A) ^ (Q < 0)) {
ratio = Q / A;
if (!isnan(ratio)) {
t[foundRoots++] = ratio;
}
}
if ((C <= Q) ^ (C < 0)) {
ratio = C / Q;
if (!isnan(ratio)) {
t[foundRoots++] = ratio;
}
}
return foundRoots;
}
void dxdy_at_t(const Quadratic& quad, double t, double& x, double& y) {
double a = t - 1;
double b = 1 - 2 * t;
double c = t;
if (&x) {
x = a * quad[0].x + b * quad[1].x + c * quad[2].x;
}
if (&y) {
y = a * quad[0].y + b * quad[1].y + c * quad[2].y;
}
}
void xy_at_t(const Quadratic& quad, double t, double& x, double& y) {
double one_t = 1 - t;
double a = one_t * one_t;
double b = 2 * one_t * t;
double c = t * t;
if (&x) {
x = a * quad[0].x + b * quad[1].x + c * quad[2].x;
}
if (&y) {
y = a * quad[0].y + b * quad[1].y + c * quad[2].y;
}
}