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-02-03 22:07:47 +00:00
|
|
|
#include "CurveIntersection.h"
|
2012-07-02 20:27:02 +00:00
|
|
|
#include "CurveUtilities.h"
|
2012-01-10 21:46:10 +00:00
|
|
|
#include "CubicIntersection_TestData.h"
|
2012-01-25 18:57:23 +00:00
|
|
|
#include "Intersection_Tests.h"
|
2012-01-10 21:46:10 +00:00
|
|
|
#include "Intersections.h"
|
|
|
|
#include "TestUtilities.h"
|
|
|
|
|
|
|
|
const int firstCubicIntersectionTest = 9;
|
|
|
|
|
|
|
|
void CubicIntersection_Test() {
|
|
|
|
for (size_t index = firstCubicIntersectionTest; index < tests_count; ++index) {
|
|
|
|
const Cubic& cubic1 = tests[index][0];
|
|
|
|
const Cubic& cubic2 = tests[index][1];
|
|
|
|
Cubic reduce1, reduce2;
|
|
|
|
int order1 = reduceOrder(cubic1, reduce1, kReduceOrder_NoQuadraticsAllowed);
|
|
|
|
int order2 = reduceOrder(cubic2, reduce2, kReduceOrder_NoQuadraticsAllowed);
|
|
|
|
if (order1 < 4) {
|
2012-01-25 18:57:23 +00:00
|
|
|
printf("%s [%d] cubic1 order=%d\n", __FUNCTION__, (int) index, order1);
|
|
|
|
continue;
|
2012-01-10 21:46:10 +00:00
|
|
|
}
|
|
|
|
if (order2 < 4) {
|
2012-01-25 18:57:23 +00:00
|
|
|
printf("%s [%d] cubic2 order=%d\n", __FUNCTION__, (int) index, order2);
|
|
|
|
continue;
|
2012-01-10 21:46:10 +00:00
|
|
|
}
|
2012-01-25 18:57:23 +00:00
|
|
|
if (implicit_matches(reduce1, reduce2)) {
|
|
|
|
printf("%s [%d] coincident\n", __FUNCTION__, (int) index);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Intersections tIntersections;
|
2012-02-03 22:07:47 +00:00
|
|
|
intersect(reduce1, reduce2, tIntersections);
|
2012-01-25 18:57:23 +00:00
|
|
|
if (!tIntersections.intersected()) {
|
|
|
|
printf("%s [%d] no intersection\n", __FUNCTION__, (int) index);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (int pt = 0; pt < tIntersections.used(); ++pt) {
|
|
|
|
double tt1 = tIntersections.fT[0][pt];
|
|
|
|
double tx1, ty1;
|
|
|
|
xy_at_t(cubic1, tt1, tx1, ty1);
|
|
|
|
double tt2 = tIntersections.fT[1][pt];
|
|
|
|
double tx2, ty2;
|
|
|
|
xy_at_t(cubic2, tt2, tx2, ty2);
|
|
|
|
if (!approximately_equal(tx1, tx2)) {
|
|
|
|
printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
|
|
|
|
__FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
|
|
|
|
}
|
|
|
|
if (!approximately_equal(ty1, ty2)) {
|
|
|
|
printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
|
|
|
|
__FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
|
2012-01-10 21:46:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|