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