blob: 2139f3bc6bfbdc5151b4d654fc483f1742bb3c40 [file] [log] [blame]
caryclark@google.comc6825902012-02-03 22:07:47 +00001#include "CurveIntersection.h"
caryclark@google.com27accef2012-01-25 18:57:23 +00002#include "Intersection_Tests.h"
caryclark@google.comc6825902012-02-03 22:07:47 +00003#include "Parameterization_Test.h"
caryclark@google.com639df892012-01-10 21:46:10 +00004#include "TestUtilities.h"
5
6const Quadratic quadratics[] = {
7 {{0, 0}, {1, 0}, {1, 1}},
8};
9
10const size_t quadratics_count = sizeof(quadratics) / sizeof(quadratics[0]);
11
12int firstCubicCoincidenceTest = 0;
13
14void CubicCoincidence_Test() {
15 // split large quadratic
16 // upscale quadratics to cubics
17 // compare original, parts, to see if the are coincident
18 for (size_t index = firstCubicCoincidenceTest; index < quadratics_count; ++index) {
19 const Quadratic& test = quadratics[index];
20 QuadraticPair split;
21 chop_at(test, split, 0.5);
22 Quadratic midThird;
23 sub_divide(test, 1.0/3, 2.0/3, midThird);
24 Cubic whole, first, second, mid;
25 quad_to_cubic(test, whole);
26 quad_to_cubic(split.first(), first);
27 quad_to_cubic(split.second(), second);
28 quad_to_cubic(midThird, mid);
29 if (!implicit_matches(whole, first)) {
30 printf("%s-1 %d\n", __FUNCTION__, (int)index);
31 }
32 if (!implicit_matches(whole, second)) {
33 printf("%s-2 %d\n", __FUNCTION__, (int)index);
34 }
35 if (!implicit_matches(mid, first)) {
36 printf("%s-3 %d\n", __FUNCTION__, (int)index);
37 }
38 if (!implicit_matches(mid, second)) {
39 printf("%s-4 %d\n", __FUNCTION__, (int)index);
40 }
41 if (!implicit_matches(first, second)) {
42 printf("%s-5 %d\n", __FUNCTION__, (int)index);
43 }
44 }
45}
caryclark@google.com27accef2012-01-25 18:57:23 +000046
47// pairs of coincident cubics
48// The on curve points of each cubic should be on both parameterized cubics.
49const Cubic cubics[] = {
50 {
caryclark@google.comc6825902012-02-03 22:07:47 +000051 { 1, -1},
52 { 1.0/3, 1},
53 {-1.0/3, -1},
54 {-1, 1}
caryclark@google.com27accef2012-01-25 18:57:23 +000055 },
56 {
caryclark@google.comc6825902012-02-03 22:07:47 +000057 {-1, 1},
58 {-1.0/3, -1},
59 { 1.0/3, 1},
60 { 1, -1}
caryclark@google.com27accef2012-01-25 18:57:23 +000061 },
62 {
63 {0, 2},
64 {0, 1},
65 {1, 0},
66 {2, 0}
67 }, {
68 {2, 0},
69 {1, 0},
70 {0, 1},
71 {0, 2}
72 },
73 {
74 {315.74799999999999, 312.83999999999997},
75 {312.64400000000001, 318.13400000000001},
76 {305.83600000000001, 319.90899999999999},
77 {300.54199999999997, 316.80399999999997}
78 }, {
79 {317.12200000000001, 309.05000000000001},
80 {316.11200000000002, 315.10199999999998},
81 {310.38499999999999, 319.19},
82 {304.33199999999999, 318.17899999999997}
83 }
84};
85
86const size_t cubics_count = sizeof(cubics) / sizeof(cubics[0]);
87
88int firstCubicParameterizationTest = 0;
89
90void CubicParameterization_Test() {
91 for (size_t index = firstCubicParameterizationTest; index < cubics_count; ++index) {
92 for (size_t inner = 0; inner < 4; inner += 3) {
93 if (!point_on_parameterized_curve(cubics[index], cubics[index][inner])) {
rmistry@google.comd6176b02012-08-23 18:14:13 +000094 printf("%s [%zu,%zu] 1 parameterization failed\n",
caryclark@google.com27accef2012-01-25 18:57:23 +000095 __FUNCTION__, index, inner);
96 }
97 if (!point_on_parameterized_curve(cubics[index], cubics[index ^ 1][inner])) {
98 printf("%s [%zu,%zu] 2 parameterization failed\n",
99 __FUNCTION__, index, inner);
100 }
101 }
caryclark@google.comc6825902012-02-03 22:07:47 +0000102 if (!implicit_matches(cubics[index], cubics[index ^ 1])) {
103 printf("%s %d\n", __FUNCTION__, (int)index);
104 }
caryclark@google.com27accef2012-01-25 18:57:23 +0000105 }
106}