blob: cc993a77977e1a4e94c8d641104b2a5ecf3affce [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.com27accef2012-01-25 18:57:23 +00009#include "Intersection_Tests.h"
10#include "Intersections.h"
caryclark@google.com27accef2012-01-25 18:57:23 +000011#include "TestUtilities.h"
12
13struct lineCubic {
14 Cubic cubic;
15 _Line line;
16} lineCubicTests[] = {
17 {{{0, 0}, {0, 1}, {0, 1}, {1, 1}}, {{0, 1}, {1, 0}}}
18};
19
20size_t lineCubicTests_count = sizeof(lineCubicTests) / sizeof(lineCubicTests[0]);
21
22const int firstLineCubicIntersectionTest = 0;
23
24void LineCubicIntersection_Test() {
25 for (size_t index = firstLineCubicIntersectionTest; index < lineCubicTests_count; ++index) {
26 const Cubic& cubic = lineCubicTests[index].cubic;
27 const _Line& line = lineCubicTests[index].line;
28 Cubic reduce1;
29 _Line reduce2;
30 int order1 = reduceOrder(cubic, reduce1, kReduceOrder_NoQuadraticsAllowed);
31 int order2 = reduceOrder(line, reduce2);
32 if (order1 < 4) {
33 printf("[%d] cubic order=%d\n", (int) index, order1);
34 }
35 if (order2 < 2) {
36 printf("[%d] line order=%d\n", (int) index, order2);
37 }
38 if (order1 == 4 && order2 == 2) {
caryclark@google.comc6825902012-02-03 22:07:47 +000039 double range1[2], range2[2];
40 int roots = intersect(reduce1, reduce2, range1, range2);
41 for (int pt = 0; pt < roots; ++pt) {
42 double tt1 = range1[pt];
43 double tx1, ty1;
44 xy_at_t(cubic, tt1, tx1, ty1);
45 double tt2 = range2[pt];
46 double tx2, ty2;
47 xy_at_t(line, 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.com27accef2012-01-25 18:57:23 +000055 }
56 }
57 }
58 }
59}