blob: 983c4e3002682301f8b446f51635d036c612ef59 [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.comc6825902012-02-03 22:07:47 +00007#include "CurveIntersection.h"
caryclark@google.com8dcf1142012-07-02 20:27:02 +00008#include "CurveUtilities.h"
caryclark@google.com639df892012-01-10 21:46:10 +00009#include "CubicIntersection_TestData.h"
caryclark@google.com27accef2012-01-25 18:57:23 +000010#include "Intersection_Tests.h"
caryclark@google.com639df892012-01-10 21:46:10 +000011#include "Intersections.h"
12#include "TestUtilities.h"
13
14const int firstCubicIntersectionTest = 9;
15
16void CubicIntersection_Test() {
17 for (size_t index = firstCubicIntersectionTest; index < tests_count; ++index) {
18 const Cubic& cubic1 = tests[index][0];
19 const Cubic& cubic2 = tests[index][1];
20 Cubic reduce1, reduce2;
21 int order1 = reduceOrder(cubic1, reduce1, kReduceOrder_NoQuadraticsAllowed);
22 int order2 = reduceOrder(cubic2, reduce2, kReduceOrder_NoQuadraticsAllowed);
23 if (order1 < 4) {
caryclark@google.com27accef2012-01-25 18:57:23 +000024 printf("%s [%d] cubic1 order=%d\n", __FUNCTION__, (int) index, order1);
25 continue;
caryclark@google.com639df892012-01-10 21:46:10 +000026 }
27 if (order2 < 4) {
caryclark@google.com27accef2012-01-25 18:57:23 +000028 printf("%s [%d] cubic2 order=%d\n", __FUNCTION__, (int) index, order2);
29 continue;
caryclark@google.com639df892012-01-10 21:46:10 +000030 }
caryclark@google.com27accef2012-01-25 18:57:23 +000031 if (implicit_matches(reduce1, reduce2)) {
32 printf("%s [%d] coincident\n", __FUNCTION__, (int) index);
33 continue;
34 }
35 Intersections tIntersections;
caryclark@google.comc6825902012-02-03 22:07:47 +000036 intersect(reduce1, reduce2, tIntersections);
caryclark@google.com27accef2012-01-25 18:57:23 +000037 if (!tIntersections.intersected()) {
38 printf("%s [%d] no intersection\n", __FUNCTION__, (int) index);
39 continue;
40 }
41 for (int pt = 0; pt < tIntersections.used(); ++pt) {
42 double tt1 = tIntersections.fT[0][pt];
43 double tx1, ty1;
44 xy_at_t(cubic1, tt1, tx1, ty1);
45 double tt2 = tIntersections.fT[1][pt];
46 double tx2, ty2;
47 xy_at_t(cubic2, tt2, tx2, ty2);
48 if (!approximately_equal(tx1, tx2)) {
49 printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
50 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
51 }
52 if (!approximately_equal(ty1, ty2)) {
53 printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
54 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
caryclark@google.com639df892012-01-10 21:46:10 +000055 }
56 }
57 }
58}