OLD | NEW |
| (Empty) |
1 /* | |
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 */ | |
7 #include "CurveIntersection.h" | |
8 #include "CurveUtilities.h" | |
9 #include "Intersection_Tests.h" | |
10 #include "Intersections.h" | |
11 #include "TestUtilities.h" | |
12 | |
13 struct lineCubic { | |
14 Cubic cubic; | |
15 _Line line; | |
16 } lineCubicTests[] = { | |
17 {{{0, 0}, {0, 1}, {0, 1}, {1, 1}}, {{0, 1}, {1, 0}}} | |
18 }; | |
19 | |
20 size_t lineCubicTests_count = sizeof(lineCubicTests) / sizeof(lineCubicTests[0])
; | |
21 | |
22 const int firstLineCubicIntersectionTest = 0; | |
23 | |
24 void LineCubicIntersection_Test() { | |
25 for (size_t index = firstLineCubicIntersectionTest; index < lineCubicTests_c
ount; ++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_NoQuadraticsAllowe
d, | |
31 kReduceOrder_TreatAsFill); | |
32 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) { | |
40 Intersections i; | |
41 double* range1 = i.fT[0]; | |
42 double* range2 = i.fT[1]; | |
43 int roots = intersect(reduce1, reduce2, i); | |
44 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); | |
51 if (!AlmostEqualUlps(tx1, tx2)) { | |
52 printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", | |
53 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, t
y2); | |
54 } | |
55 if (!AlmostEqualUlps(ty1, ty2)) { | |
56 printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n", | |
57 __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, t
y2); | |
58 } | |
59 } | |
60 } | |
61 } | |
62 } | |
OLD | NEW |