blob: adf01122ac4de4bef4f8e674044ec155d53fe679 [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;
caryclark@google.com47d73da2013-02-17 01:41:25 +000030 int order1 = reduceOrder(cubic, reduce1, kReduceOrder_NoQuadraticsAllowed,
31 kReduceOrder_TreatAsFill);
caryclark@google.com27accef2012-01-25 18:57:23 +000032 int order2 = reduceOrder(line, reduce2);
33 if (order1 < 4) {
34 printf("[%d] cubic order=%d\n", (int) index, order1);
35 }
36 if (order2 < 2) {
37 printf("[%d] line order=%d\n", (int) index, order2);
38 }
39 if (order1 == 4 && order2 == 2) {
caryclark@google.com73ca6242013-01-17 21:02:47 +000040 Intersections i;
41 double* range1 = i.fT[0];
42 double* range2 = i.fT[1];
43 int roots = intersect(reduce1, reduce2, i);
caryclark@google.comc6825902012-02-03 22:07:47 +000044 for (int pt = 0; pt < roots; ++pt) {
45 double tt1 = range1[pt];
46 double tx1, ty1;
47 xy_at_t(cubic, tt1, tx1, ty1);
48 double tt2 = range2[pt];
49 double tx2, ty2;
50 xy_at_t(line, tt2, tx2, ty2);
caryclark@google.com6d0032a2013-01-04 19:41:13 +000051 if (!AlmostEqualUlps(tx1, tx2)) {
caryclark@google.comc6825902012-02-03 22:07:47 +000052 printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
53 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
54 }
caryclark@google.com6d0032a2013-01-04 19:41:13 +000055 if (!AlmostEqualUlps(ty1, ty2)) {
caryclark@google.comc6825902012-02-03 22:07:47 +000056 printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n",
57 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2);
caryclark@google.com27accef2012-01-25 18:57:23 +000058 }
59 }
60 }
61 }
62}