blob: 645d7b04b918a27133fb48fce8aaef3b8851665d [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.comb45a1b42012-05-18 20:50:33 +00007#define IN_TEST 1
caryclark@google.com639df892012-01-10 21:46:10 +00008#include "CubicIntersection_TestData.h"
9#include <limits>
10
11const Cubic pointDegenerates[] = {
12 {{0, 0}, {0, 0}, {0, 0}, {0, 0}},
13 {{1, 1}, {1, 1}, {1, 1}, {1, 1}},
14 {{1 + PointEpsilon - std::numeric_limits<double>::epsilon(), 1},
15 {1, 1 + PointEpsilon - std::numeric_limits<double>::epsilon()}, {1, 1}, {1, 1}},
16 {{1 + PointEpsilon/2 - std::numeric_limits<double>::epsilon(), 1},
17 {1 - (PointEpsilon/2 - std::numeric_limits<double>::epsilon()), 1}, {1, 1}, {1, 1}}
18};
19
20const size_t pointDegenerates_count = sizeof(pointDegenerates) / sizeof(pointDegenerates[0]);
rmistry@google.comd6176b02012-08-23 18:14:13 +000021
caryclark@google.com639df892012-01-10 21:46:10 +000022const Cubic notPointDegenerates[] = {
23 {{1 + PointEpsilon + std::numeric_limits<double>::epsilon(), 1}, {1, 1 + PointEpsilon}, {1, 1}, {1, 1}},
24 {{1 + PointEpsilon/2 + std::numeric_limits<double>::epsilon(), 1}, {1 - PointEpsilon/2, 1}, {1, 1}, {1, 1}}
25};
26
27const size_t notPointDegenerates_count = sizeof(notPointDegenerates) / sizeof(notPointDegenerates[0]);
28
29// from http://www.truetex.com/bezint.htm
30const Cubic tests[][2] = {
31 { // intersects in one place (data gives bezier clip fits
32 {{0, 45},
33 {6.0094158284751593, 51.610357411322688},
34 {12.741093228940867, 55.981703949474607},
35 {20.021417396476362, 58.652245509710262}},
36 {{2.2070737699246674, 52.703494107327209},
37 {31.591482272629477, 23.811002295222025},
38 {76.824588616426425, 44.049473790502674},
39 {119.25488947221436, 55.599248272955073}}
40 },
41 { // intersects in three places
42 {{0, 45}, {50, 100}, {150, 0}, {200, 55}},
43 {{0, 55}, {50, 0}, {150, 100}, {200, 45}}
44 },
45 { // intersects in one place, cross over is nearly parallel
46 {{0, 0}, {0, 100}, {200, 0}, {200, 100}},
47 {{0, 100}, {0, 0}, {200, 100}, {200, 0}}
48 },
49 { // intersects in two places
50 {{0, 0}, {0, 100}, {200, 100}, {200, 0}},
51 {{0, 100}, {0, 0}, {200, 0}, {200, 100}}
52 },
53 {
54 {{150, 100}, {150 + 0.1, 150}, {150, 200}, {150, 250}},
55 {{250, 150}, {200, 150 + 0.1}, {150, 150}, {100, 150}}
56 },
57 { // single intersection around 168,185
58 {{200, 100}, {150, 100}, {150, 150}, {200, 150}},
59 {{250, 150}, {250, 100}, {100, 100}, {100, 150}}
60 },
61 {
62 {{1.0, 1.5}, {15.5, 0.5}, {-8.0, 3.5}, {5.0, 1.5}},
63 {{4.0, 0.5}, {5.0, 15.0}, {2.0, -8.5}, {4.0, 4.5}}
64 },
65 {
66 {{664.00168, 0}, {726.11545, 124.22757}, {736.89069, 267.89743}, {694.0017, 400.0002}},
67 {{850.66843, 115.55563}, {728.515, 115.55563}, {725.21347, 275.15309}, {694.0017, 400.0002}}
68 },
69 {
70 {{1, 1}, {12.5, 6.5}, {-4, 6.5}, {7.5, 1}},
71 {{1, 6.5}, {12.5, 1}, {-4, 1}, {.5, 6}}
72 },
73 {
74 {{315.748, 312.84}, {312.644, 318.134}, {305.836, 319.909}, {300.542, 316.804}},
75 {{317.122, 309.05}, {316.112, 315.102}, {310.385, 319.19}, {304.332, 318.179}}
76 },
77 {
rmistry@google.comd6176b02012-08-23 18:14:13 +000078 {{1046.604051, 172.937967}, {1046.604051, 178.9763059}, {1041.76745, 183.9279165}, {1035.703842, 184.0432409}},
caryclark@google.com639df892012-01-10 21:46:10 +000079 {{1046.452235, 174.7640504}, {1045.544872, 180.1973817}, {1040.837966, 184.0469882}, {1035.505925, 184.0469882}}
80 },
81 {
82 {{125.79356, 199.57382}, {51.16556, 128.93575}, {87.494, 16.67848}, {167.29361, 16.67848}},
83 {{167.29361, 55.81876}, {100.36128, 55.81876}, {68.64099, 145.4755}, {125.7942, 199.57309}}
84 }
85};
86
87const size_t tests_count = sizeof(tests) / sizeof(tests[0]);
88
89Cubic hexTests[][2] = {
rmistry@google.comd6176b02012-08-23 18:14:13 +000090 {
caryclark@google.com639df892012-01-10 21:46:10 +000091 {{0}} // placeholder for hex converted below
92 }
93};
94
95const size_t hexTests_count = sizeof(hexTests) / sizeof(hexTests[0]);
96
97static const uint64_t testx[2][8] = {
98 {
99 0xf0d0d1ca63075a40LLU, 0x9408ce996a237740LLU, 0x6d5675460fbe5e40LLU, 0x6ef501e1b7487940LLU,
100 0x9a71d2f8143d6540LLU, 0x6bc18bbe02907a40LLU, 0x5b94d92093aa6b40LLU, 0x6ac18bbe02907a40LLU
101 },
102 {
103 0x92c56ed7b6145d40LLU, 0xede4f1255edb7740LLU, 0x1138c1101af75940LLU, 0x42e4f1255edb7740LLU,
rmistry@google.comd6176b02012-08-23 18:14:13 +0000104 0x408e51603ad95640LLU, 0x1e2e8fe9dd927740LLU, 0x1cb4777cd3a75440LLU, 0x212e1390de017740LLU
caryclark@google.com639df892012-01-10 21:46:10 +0000105 }
106};
107
108void convert_testx() {
109 const uint64_t* inPtr = testx[0];
110 double* outPtr = &hexTests[sizeof(tests) / sizeof(tests[0]) - 1][0][0].x;
111 for (unsigned index = 0; index < sizeof(testx) / sizeof(testx[0][0]); ++index) {
112 uint64_t input = *inPtr++;
113 unsigned char* output = (unsigned char*) outPtr++;
114 for (unsigned byte = 0; byte < sizeof(input); ++byte) {
115 output[byte] = input >> (7 - byte) * 8;
116 }
117 }
118}
119
120const Cubic lines[] = {
121 {{0, 0}, {0, 0}, {0, 0}, {1, 0}}, // 0: horizontal
122 {{0, 0}, {0, 0}, {1, 0}, {0, 0}},
123 {{0, 0}, {1, 0}, {0, 0}, {0, 0}},
124 {{1, 0}, {0, 0}, {0, 0}, {0, 0}},
125 {{1, 0}, {2, 0}, {3, 0}, {4, 0}},
126 {{0, 0}, {0, 0}, {0, 0}, {0, 1}}, // 5: vertical
127 {{0, 0}, {0, 0}, {0, 1}, {0, 0}},
128 {{0, 0}, {0, 1}, {0, 0}, {0, 0}},
129 {{0, 1}, {0, 0}, {0, 0}, {0, 0}},
130 {{0, 1}, {0, 2}, {0, 3}, {0, 4}},
131 {{0, 0}, {0, 0}, {0, 0}, {1, 1}}, // 10: 3 coincident
132 {{0, 0}, {0, 0}, {1, 1}, {0, 0}},
133 {{0, 0}, {1, 1}, {0, 0}, {0, 0}},
134 {{1, 1}, {0, 0}, {0, 0}, {0, 0}},
135 {{0, 0}, {0, 0}, {1, 1}, {2, 2}}, // 14: 2 coincident
136 {{0, 0}, {1, 1}, {0, 0}, {2, 2}},
137 {{0, 0}, {1, 1}, {2, 2}, {0, 0}},
138 {{1, 1}, {0, 0}, {0, 0}, {2, 2}}, // 17:
139 {{1, 1}, {0, 0}, {2, 2}, {0, 0}},
140 {{1, 1}, {2, 2}, {0, 0}, {0, 0}},
141 {{1, 1}, {2, 2}, {3, 3}, {2, 2}}, // middle-last coincident
142 {{1, 1}, {2, 2}, {3, 3}, {3, 3}}, // middle-last coincident
143 {{1, 1}, {1, 1}, {2, 2}, {2, 2}}, // 2 pairs coincident
144 {{1, 1}, {2, 2}, {1, 1}, {2, 2}},
145 {{1, 1}, {2, 2}, {2, 2}, {1, 1}},
146 {{1, 1}, {1, 1}, {3, 3}, {3, 3}}, // first-middle middle-last coincident
147 {{1, 1}, {2, 2}, {3, 3}, {4, 4}}, // no coincident
148 {{1, 1}, {3, 3}, {2, 2}, {4, 4}},
149 {{1, 1}, {2, 2}, {4, 4}, {3, 3}},
150 {{1, 1}, {3, 3}, {4, 4}, {2, 2}},
151 {{1, 1}, {4, 4}, {2, 2}, {3, 3}},
152 {{1, 1}, {4, 4}, {3, 3}, {2, 2}},
153 {{2, 2}, {1, 1}, {3, 3}, {4, 4}},
154 {{2, 2}, {1, 1}, {4, 4}, {3, 3}},
155 {{2, 2}, {3, 3}, {1, 1}, {4, 4}},
156 {{2, 2}, {3, 3}, {4, 4}, {1, 1}},
157 {{2, 2}, {4, 4}, {1, 1}, {3, 3}},
158 {{2, 2}, {4, 4}, {3, 3}, {1, 1}},
159};
160
161const size_t lines_count = sizeof(lines) / sizeof(lines[0]);
162
163// 'not a line' tries to fool the line detection code
164const Cubic notLines[] = {
165 {{0, 0}, {0, 0}, {0, 1}, {1, 0}},
166 {{0, 0}, {0, 1}, {0, 0}, {1, 0}},
167 {{0, 0}, {0, 1}, {1, 0}, {0, 0}},
168 {{0, 1}, {0, 0}, {0, 0}, {1, 0}},
169 {{0, 1}, {0, 0}, {1, 0}, {0, 0}},
170 {{0, 1}, {1, 0}, {0, 0}, {0, 0}},
171};
172
173const size_t notLines_count = sizeof(notLines) / sizeof(notLines[0]);
174
175static const double E = PointEpsilon * 2;
176static const double F = PointEpsilon * 3;
caryclark@google.com639df892012-01-10 21:46:10 +0000177
178const Cubic modEpsilonLines[] = {
179 {{0, E}, {0, 0}, {0, 0}, {1, 0}}, // horizontal
180 {{0, 0}, {0, E}, {1, 0}, {0, 0}},
181 {{0, 0}, {1, 0}, {0, E}, {0, 0}},
182 {{1, 0}, {0, 0}, {0, 0}, {0, E}},
183 {{1, E}, {2, 0}, {3, 0}, {4, 0}},
184 {{E, 0}, {0, 0}, {0, 0}, {0, 1}}, // vertical
185 {{0, 0}, {E, 0}, {0, 1}, {0, 0}},
186 {{0, 0}, {0, 1}, {E, 0}, {0, 0}},
187 {{0, 1}, {0, 0}, {0, 0}, {E, 0}},
188 {{E, 1}, {0, 2}, {0, 3}, {0, 4}},
189 {{E, 0}, {0, 0}, {0, 0}, {1, 1}}, // 3 coincident
190 {{0, 0}, {E, 0}, {1, 1}, {0, 0}},
191 {{0, 0}, {1, 1}, {E, 0}, {0, 0}},
192 {{1, 1}, {0, 0}, {0, 0}, {E, 0}},
193 {{0, E}, {0, 0}, {1, 1}, {2, 2}}, // 2 coincident
194 {{0, 0}, {1, 1}, {0, E}, {2, 2}},
195 {{0, 0}, {1, 1}, {2, 2}, {0, E}},
196 {{1, 1}, {0, E}, {0, 0}, {2, 2}},
197 {{1, 1}, {0, E}, {2, 2}, {0, 0}},
198 {{1, 1}, {2, 2}, {E, 0}, {0, 0}},
199 {{1, 1}, {2, 2+E}, {3, 3}, {2, 2}}, // middle-last coincident
200 {{1, 1}, {2+E, 2}, {3, 3}, {3, 3}}, // middle-last coincident
201 {{1, 1}, {1, 1}, {2, 2}, {2+E, 2}}, // 2 pairs coincident
202 {{1, 1}, {2, 2}, {1, 1}, {2+E, 2}},
203 {{1, 1}, {2, 2}, {2, 2+E}, {1, 1}},
204 {{1, 1}, {1, 1+E}, {3, 3}, {3, 3}}, // first-middle middle-last coincident
205 {{1, 1}, {2+E, 2}, {3, 3}, {4, 4}}, // no coincident
206 {{1, 1}, {3, 3}, {2, 2}, {4, 4+F}}, // INVESTIGATE: why the epsilon is bigger
207 {{1, 1+F}, {2, 2}, {4, 4}, {3, 3}}, // INVESTIGATE: why the epsilon is bigger
208 {{1, 1}, {3, 3}, {4, 4+E}, {2, 2}},
209 {{1, 1}, {4, 4}, {2, 2}, {3, 3+E}},
210 {{1, 1}, {4, 4}, {3, 3}, {2+E, 2}},
211 {{2, 2}, {1, 1}, {3+E, 3}, {4, 4}},
212 {{2, 2}, {1+E, 1}, {4, 4}, {3, 3}},
213 {{2, 2+E}, {3, 3}, {1, 1}, {4, 4}},
214 {{2+E, 2}, {3, 3}, {4, 4}, {1, 1}},
215 {{2, 2}, {4+E, 4}, {1, 1}, {3, 3}},
216 {{2, 2}, {4, 4}, {3, 3}, {1, 1+E}},
217};
218
219const size_t modEpsilonLines_count = sizeof(modEpsilonLines) / sizeof(modEpsilonLines[0]);
220
221static const double D = PointEpsilon / 2;
222static const double G = PointEpsilon / 3;
223
224const Cubic lessEpsilonLines[] = {
225 {{0, D}, {0, 0}, {0, 0}, {1, 0}}, // horizontal
226 {{0, 0}, {0, D}, {1, 0}, {0, 0}},
227 {{0, 0}, {1, 0}, {0, D}, {0, 0}},
228 {{1, 0}, {0, 0}, {0, 0}, {0, D}},
229 {{1, D}, {2, 0}, {3, 0}, {4, 0}},
230 {{D, 0}, {0, 0}, {0, 0}, {0, 1}}, // vertical
231 {{0, 0}, {D, 0}, {0, 1}, {0, 0}},
232 {{0, 0}, {0, 1}, {D, 0}, {0, 0}},
233 {{0, 1}, {0, 0}, {0, 0}, {D, 0}},
234 {{D, 1}, {0, 2}, {0, 3}, {0, 4}},
235 {{D, 0}, {0, 0}, {0, 0}, {1, 1}}, // 3 coincident
236 {{0, 0}, {D, 0}, {1, 1}, {0, 0}},
237 {{0, 0}, {1, 1}, {D, 0}, {0, 0}},
238 {{1, 1}, {0, 0}, {0, 0}, {D, 0}},
239 {{0, D}, {0, 0}, {1, 1}, {2, 2}}, // 2 coincident
240 {{0, 0}, {1, 1}, {0, D}, {2, 2}},
241 {{0, 0}, {1, 1}, {2, 2}, {0, D}},
242 {{1, 1}, {0, D}, {0, 0}, {2, 2}},
243 {{1, 1}, {0, D}, {2, 2}, {0, 0}},
244 {{1, 1}, {2, 2}, {D, 0}, {0, 0}},
245 {{1, 1}, {2, 2+D}, {3, 3}, {2, 2}}, // middle-last coincident
246 {{1, 1}, {2+D, 2}, {3, 3}, {3, 3}}, // middle-last coincident
247 {{1, 1}, {1, 1}, {2, 2}, {2+D, 2}}, // 2 pairs coincident
248 {{1, 1}, {2, 2}, {1, 1}, {2+D, 2}},
249 {{1, 1}, {2, 2}, {2, 2+D}, {1, 1}},
250 {{1, 1}, {1, 1+D}, {3, 3}, {3, 3}}, // first-middle middle-last coincident
251 {{1, 1}, {2+D/2, 2}, {3, 3}, {4, 4}}, // no coincident (FIXME: N as opposed to N/2 failed)
252 {{1, 1}, {3, 3}, {2, 2}, {4, 4+D}},
253 {{1, 1+D}, {2, 2}, {4, 4}, {3, 3}},
254 {{1, 1}, {3, 3}, {4, 4+D}, {2, 2}},
255 {{1, 1}, {4, 4}, {2, 2}, {3, 3+D}},
256 {{1, 1}, {4, 4}, {3, 3}, {2+G, 2}}, // INVESTIGATE: why the epsilon is smaller
257 {{2, 2}, {1, 1}, {3+D, 3}, {4, 4}},
258 {{2, 2}, {1+D, 1}, {4, 4}, {3, 3}},
259 {{2, 2+D}, {3, 3}, {1, 1}, {4, 4}},
260 {{2+G, 2}, {3, 3}, {4, 4}, {1, 1}}, // INVESTIGATE: why the epsilon is smaller
261 {{2, 2}, {4+D, 4}, {1, 1}, {3, 3}},
262 {{2, 2}, {4, 4}, {3, 3}, {1, 1+D}},
263};
264
265const size_t lessEpsilonLines_count = sizeof(lessEpsilonLines) / sizeof(lessEpsilonLines[0]);
266
267static const double N = -PointEpsilon / 2;
268static const double M = -PointEpsilon / 3;
269
270const Cubic negEpsilonLines[] = {
271 {{0, N}, {0, 0}, {0, 0}, {1, 0}}, // horizontal
272 {{0, 0}, {0, N}, {1, 0}, {0, 0}},
273 {{0, 0}, {1, 0}, {0, N}, {0, 0}},
274 {{1, 0}, {0, 0}, {0, 0}, {0, N}},
275 {{1, N}, {2, 0}, {3, 0}, {4, 0}},
276 {{N, 0}, {0, 0}, {0, 0}, {0, 1}}, // vertical
277 {{0, 0}, {N, 0}, {0, 1}, {0, 0}},
278 {{0, 0}, {0, 1}, {N, 0}, {0, 0}},
279 {{0, 1}, {0, 0}, {0, 0}, {N, 0}},
280 {{N, 1}, {0, 2}, {0, 3}, {0, 4}},
281 {{N, 0}, {0, 0}, {0, 0}, {1, 1}}, // 3 coincident
282 {{0, 0}, {N, 0}, {1, 1}, {0, 0}},
283 {{0, 0}, {1, 1}, {N, 0}, {0, 0}},
284 {{1, 1}, {0, 0}, {0, 0}, {N, 0}},
285 {{0, N}, {0, 0}, {1, 1}, {2, 2}}, // 2 coincident
286 {{0, 0}, {1, 1}, {0, N}, {2, 2}},
287 {{0, 0}, {1, 1}, {2, 2}, {0, N}},
288 {{1, 1}, {0, N}, {0, 0}, {2, 2}},
289 {{1, 1}, {0, N}, {2, 2}, {0, 0}},
290 {{1, 1}, {2, 2}, {N, 0}, {0, 0}},
291 {{1, 1}, {2, 2+N}, {3, 3}, {2, 2}}, // middle-last coincident
292 {{1, 1}, {2+N, 2}, {3, 3}, {3, 3}}, // middle-last coincident
293 {{1, 1}, {1, 1}, {2, 2}, {2+N, 2}}, // 2 pairs coincident
294 {{1, 1}, {2, 2}, {1, 1}, {2+N, 2}},
295 {{1, 1}, {2, 2}, {2, 2+N}, {1, 1}},
296 {{1, 1}, {1, 1+N}, {3, 3}, {3, 3}}, // first-middle middle-last coincident
297 {{1, 1}, {2+N/2, 2}, {3, 3}, {4, 4}}, // no coincident (FIXME: N as opposed to N/2 failed)
298 {{1, 1}, {3, 3}, {2, 2}, {4, 4+N}},
299 {{1, 1+N}, {2, 2}, {4, 4}, {3, 3}},
300 {{1, 1}, {3, 3}, {4, 4+N}, {2, 2}},
301 {{1, 1}, {4, 4}, {2, 2}, {3, 3+N}},
302 {{1, 1}, {4, 4}, {3, 3}, {2+M, 2}}, // INVESTIGATE: why the epsilon is smaller
303 {{2, 2}, {1, 1}, {3+N, 3}, {4, 4}},
304 {{2, 2}, {1+N, 1}, {4, 4}, {3, 3}},
305 {{2, 2+N}, {3, 3}, {1, 1}, {4, 4}},
306 {{2+M, 2}, {3, 3}, {4, 4}, {1, 1}}, // INVESTIGATE: why the epsilon is smaller
307 {{2, 2}, {4+N, 4}, {1, 1}, {3, 3}},
308 {{2, 2}, {4, 4}, {3, 3}, {1, 1+N}},
309};
310
311const size_t negEpsilonLines_count = sizeof(negEpsilonLines) / sizeof(negEpsilonLines[0]);