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 "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 = SK_ARRAY_COUNT(pointDegenerates);
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        SK_ARRAY_COUNT(notPointDegenerates);
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        {{{104.11546583642826, 370.21352558595504}, {122.96968232592344, 404.54489231839295},
102          {169.90881005384728, 425.00067000000007}, {221.33045999999999, 425.00067000000001}}},
103        {{{116.32365976159625, 381.71048540582598}, {103.86096590870899, 381.71048540581626},
104          {91.394188003200725, 377.17917781762833}, {82.622283093355179, 368.11683661930334}}}
105    }
106};
107
108const size_t tests_count = SK_ARRAY_COUNT(tests);
109
110const SkDCubic lines[] = {
111    {{{0, 0}, {0, 0}, {0, 0}, {1, 0}}},  // 0: horizontal
112    {{{1, 0}, {0, 0}, {0, 0}, {0, 0}}},
113    {{{1, 0}, {2, 0}, {3, 0}, {4, 0}}},
114    {{{0, 0}, {0, 0}, {0, 0}, {0, 1}}},  // 5: vertical
115    {{{0, 1}, {0, 0}, {0, 0}, {0, 0}}},
116    {{{0, 1}, {0, 2}, {0, 3}, {0, 4}}},
117    {{{0, 0}, {0, 0}, {0, 0}, {1, 1}}},  // 10: 3 coincident
118    {{{1, 1}, {0, 0}, {0, 0}, {0, 0}}},
119    {{{0, 0}, {0, 0}, {1, 1}, {2, 2}}},  // 14: 2 coincident
120    {{{0, 0}, {1, 1}, {0, 0}, {2, 2}}},
121    {{{1, 1}, {0, 0}, {0, 0}, {2, 2}}},  // 17:
122    {{{1, 1}, {0, 0}, {2, 2}, {0, 0}}},
123    {{{1, 1}, {2, 2}, {0, 0}, {0, 0}}},
124    {{{1, 1}, {2, 2}, {3, 3}, {2, 2}}},  // middle-last coincident
125    {{{1, 1}, {2, 2}, {3, 3}, {3, 3}}},  // middle-last coincident
126    {{{1, 1}, {1, 1}, {2, 2}, {2, 2}}},  // 2 pairs coincident
127    {{{1, 1}, {2, 2}, {1, 1}, {2, 2}}},
128    {{{1, 1}, {1, 1}, {3, 3}, {3, 3}}},  // first-middle middle-last coincident
129    {{{1, 1}, {2, 2}, {3, 3}, {4, 4}}},  // no coincident
130    {{{1, 1}, {3, 3}, {2, 2}, {4, 4}}},
131    {{{1, 1}, {2, 2}, {4, 4}, {3, 3}}},
132    {{{1, 1}, {3, 3}, {4, 4}, {2, 2}}},
133    {{{1, 1}, {4, 4}, {2, 2}, {3, 3}}},
134    {{{1, 1}, {4, 4}, {3, 3}, {2, 2}}},
135    {{{2, 2}, {1, 1}, {3, 3}, {4, 4}}},
136    {{{2, 2}, {1, 1}, {4, 4}, {3, 3}}},
137    {{{2, 2}, {3, 3}, {1, 1}, {4, 4}}},
138    {{{2, 2}, {3, 3}, {4, 4}, {1, 1}}},
139    {{{2, 2}, {4, 4}, {1, 1}, {3, 3}}},
140    {{{2, 2}, {4, 4}, {3, 3}, {1, 1}}},
141};
142
143const size_t lines_count = SK_ARRAY_COUNT(lines);
144
145// 'not a line' tries to fool the line detection code
146const SkDCubic notLines[] = {
147    {{{0, 0}, {0, 0}, {0, 1}, {1, 0}}},
148    {{{0, 0}, {0, 1}, {0, 0}, {1, 0}}},
149    {{{0, 0}, {0, 1}, {1, 0}, {0, 0}}},
150    {{{0, 1}, {0, 0}, {0, 0}, {1, 0}}},
151    {{{0, 1}, {0, 0}, {1, 0}, {0, 0}}},
152    {{{0, 1}, {1, 0}, {0, 0}, {0, 0}}},
153};
154
155const size_t notLines_count = SK_ARRAY_COUNT(notLines);
156
157static const double E = FLT_EPSILON * 2;
158static const double F = FLT_EPSILON * 3;
159
160const SkDCubic modEpsilonLines[] = {
161    {{{0, E}, {0, 0}, {0, 0}, {1, 0}}},  // horizontal
162    {{{0, 0}, {0, E}, {1, 0}, {0, 0}}},
163    {{{0, 0}, {1, 0}, {0, E}, {0, 0}}},
164    {{{1, 0}, {0, 0}, {0, 0}, {0, E}}},
165    {{{1, E}, {2, 0}, {3, 0}, {4, 0}}},
166    {{{E, 0}, {0, 0}, {0, 0}, {0, 1}}},  // vertical
167    {{{0, 0}, {E, 0}, {0, 1}, {0, 0}}},
168    {{{0, 0}, {0, 1}, {E, 0}, {0, 0}}},
169    {{{0, 1}, {0, 0}, {0, 0}, {E, 0}}},
170    {{{E, 1}, {0, 2}, {0, 3}, {0, 4}}},
171    {{{E, 0}, {0, 0}, {0, 0}, {1, 1}}},  // 3 coincident
172    {{{0, 0}, {E, 0}, {1, 1}, {0, 0}}},
173    {{{0, 0}, {1, 1}, {E, 0}, {0, 0}}},
174    {{{1, 1}, {0, 0}, {0, 0}, {E, 0}}},
175    {{{0, E}, {0, 0}, {1, 1}, {2, 2}}},  // 2 coincident
176    {{{0, 0}, {1, 1}, {0, E}, {2, 2}}},
177    {{{0, 0}, {1, 1}, {2, 2}, {0, E}}},
178    {{{1, 1}, {0, E}, {0, 0}, {2, 2}}},
179    {{{1, 1}, {0, E}, {2, 2}, {0, 0}}},
180    {{{1, 1}, {2, 2}, {E, 0}, {0, 0}}},
181    {{{1, 1}, {2, 2+E}, {3, 3}, {2, 2}}},  // middle-last coincident
182    {{{1, 1}, {2+E, 2}, {3, 3}, {3, 3}}},  // middle-last coincident
183    {{{1, 1}, {1, 1}, {2, 2}, {2+E, 2}}},  // 2 pairs coincident
184    {{{1, 1}, {2, 2}, {1, 1}, {2+E, 2}}},
185    {{{1, 1}, {2, 2}, {2, 2+E}, {1, 1}}},
186    {{{1, 1}, {1, 1+E}, {3, 3}, {3, 3}}},  // first-middle middle-last coincident
187    {{{1, 1}, {2+E, 2}, {3, 3}, {4, 4}}},  // no coincident
188    {{{1, 1}, {3, 3}, {2, 2}, {4, 4+F}}},  // INVESTIGATE: why the epsilon is bigger
189    {{{1, 1+F}, {2, 2}, {4, 4}, {3, 3}}},  // INVESTIGATE: why the epsilon is bigger
190    {{{1, 1}, {3, 3}, {4, 4+E}, {2, 2}}},
191    {{{1, 1}, {4, 4}, {2, 2}, {3, 3+E}}},
192    {{{1, 1}, {4, 4}, {3, 3}, {2+E, 2}}},
193    {{{2, 2}, {1, 1}, {3+E, 3}, {4, 4}}},
194    {{{2, 2}, {1+E, 1}, {4, 4}, {3, 3}}},
195    {{{2, 2+E}, {3, 3}, {1, 1}, {4, 4}}},
196    {{{2+E, 2}, {3, 3}, {4, 4}, {1, 1}}},
197    {{{2, 2}, {4+E, 4}, {1, 1}, {3, 3}}},
198    {{{2, 2}, {4, 4}, {3, 3}, {1, 1+E}}},
199};
200
201const size_t modEpsilonLines_count = SK_ARRAY_COUNT(modEpsilonLines);
202
203const SkDCubic lessEpsilonLines[] = {
204    {{{0, D}, {0, 0}, {0, 0}, {1, 0}}},  // horizontal
205    {{{1, 0}, {0, 0}, {0, 0}, {0, D}}},
206    {{{1, D}, {2, 0}, {3, 0}, {4, 0}}},
207    {{{D, 0}, {0, 0}, {0, 0}, {0, 1}}},  // vertical
208    {{{0, 1}, {0, 0}, {0, 0}, {D, 0}}},
209    {{{D, 1}, {0, 2}, {0, 3}, {0, 4}}},
210    {{{D, 0}, {0, 0}, {0, 0}, {1, 1}}},  // 3 coincident
211    {{{1, 1}, {0, 0}, {0, 0}, {D, 0}}},
212    {{{0, D}, {0, 0}, {1, 1}, {2, 2}}},  // 2 coincident
213    {{{0, 0}, {1, 1}, {0, D}, {2, 2}}},
214    {{{0, 0}, {1, 1}, {2, 2}, {1, 1+D}}},
215    {{{1, 1}, {0, D}, {0, 0}, {2, 2}}},
216    {{{1, 1}, {0, D}, {2, 2}, {0, 0}}},
217    {{{1, 1}, {2, 2}, {D, 0}, {0, 0}}},
218    {{{1, 1}, {2, 2+D}, {3, 3}, {2, 2}}},  // middle-last coincident
219    {{{1, 1}, {2+D, 2}, {3, 3}, {3, 3}}},  // middle-last coincident
220    {{{1, 1}, {1, 1}, {2, 2}, {2+D, 2}}},  // 2 pairs coincident
221    {{{1, 1}, {2, 2}, {1, 1}, {2+D, 2}}},
222    {{{1, 1}, {1, 1+D}, {3, 3}, {3, 3}}},  // first-middle middle-last coincident
223    {{{1, 1}, {2+D/2, 2}, {3, 3}, {4, 4}}},  // no coincident (FIXME: N as opposed to N/2 failed)
224    {{{1, 1}, {3, 3}, {2, 2}, {4, 4+D}}},
225    {{{1, 1+D}, {2, 2}, {4, 4}, {3, 3}}},
226    {{{1, 1}, {3, 3}, {4, 4+D}, {2, 2}}},
227    {{{1, 1}, {4, 4}, {2, 2}, {3, 3+D}}},
228    {{{1, 1}, {4, 4}, {3, 3}, {2+G, 2}}},  // INVESTIGATE: why the epsilon is smaller
229    {{{2, 2}, {1, 1}, {3+D, 3}, {4, 4}}},
230    {{{2, 2}, {1+D, 1}, {4, 4}, {3, 3}}},
231    {{{2, 2+D}, {3, 3}, {1, 1}, {4, 4}}},
232    {{{2+G, 2}, {3, 3}, {4, 4}, {1, 1}}},  // INVESTIGATE: why the epsilon is smaller
233    {{{2, 2}, {4+D, 4}, {1, 1}, {3, 3}}},
234    {{{2, 2}, {4, 4}, {3, 3}, {1, 1+D}}},
235};
236
237const size_t lessEpsilonLines_count = SK_ARRAY_COUNT(lessEpsilonLines);
238
239const SkDCubic negEpsilonLines[] = {
240    {{{0, N}, {0, 0}, {0, 0}, {1, 0}}},  // horizontal
241    {{{1, 0}, {0, 0}, {0, 0}, {0, N}}},
242    {{{1, N}, {2, 0}, {3, 0}, {4, 0}}},
243    {{{N, 0}, {0, 0}, {0, 0}, {0, 1}}},  // vertical
244    {{{0, 1}, {0, 0}, {0, 0}, {N, 0}}},
245    {{{N, 1}, {0, 2}, {0, 3}, {0, 4}}},
246    {{{N, 0}, {0, 0}, {0, 0}, {1, 1}}},  // 3 coincident
247    {{{1, 1}, {0, 0}, {0, 0}, {N, 0}}},
248    {{{0, N}, {0, 0}, {1, 1}, {2, 2}}},  // 2 coincident
249    {{{0, 0}, {1, 1}, {0, N}, {2, 2}}},
250    {{{0, 0}, {1, 1}, {2, 2}, {1, 1+N}}},
251    {{{1, 1}, {0, N}, {0, 0}, {2, 2}}},
252    {{{1, 1}, {0, N}, {2, 2}, {0, 0}}},
253    {{{1, 1}, {2, 2}, {N, 0}, {0, 0}}},
254    {{{1, 1}, {2, 2+N}, {3, 3}, {2, 2}}},  // middle-last coincident
255    {{{1, 1}, {2+N, 2}, {3, 3}, {3, 3}}},  // middle-last coincident
256    {{{1, 1}, {1, 1}, {2, 2}, {2+N, 2}}},  // 2 pairs coincident
257    {{{1, 1}, {2, 2}, {1, 1}, {2+N, 2}}},
258    {{{1, 1}, {1, 1+N}, {3, 3}, {3, 3}}},  // first-middle middle-last coincident
259    {{{1, 1}, {2+N/2, 2}, {3, 3}, {4, 4}}},  // no coincident (FIXME: N as opposed to N/2 failed)
260    {{{1, 1}, {3, 3}, {2, 2}, {4, 4+N}}},
261    {{{1, 1+N}, {2, 2}, {4, 4}, {3, 3}}},
262    {{{1, 1}, {3, 3}, {4, 4+N}, {2, 2}}},
263    {{{1, 1}, {4, 4}, {2, 2}, {3, 3+N}}},
264    {{{1, 1}, {4, 4}, {3, 3}, {2+M, 2}}},  // INVESTIGATE: why the epsilon is smaller
265    {{{2, 2}, {1, 1}, {3+N, 3}, {4, 4}}},
266    {{{2, 2}, {1+N, 1}, {4, 4}, {3, 3}}},
267    {{{2, 2+N}, {3, 3}, {1, 1}, {4, 4}}},
268    {{{2+M, 2}, {3, 3}, {4, 4}, {1, 1}}},  // INVESTIGATE: why the epsilon is smaller
269    {{{2, 2}, {4+N, 4}, {1, 1}, {3, 3}}},
270    {{{2, 2}, {4, 4}, {3, 3}, {1, 1+N}}},
271};
272
273const size_t negEpsilonLines_count = SK_ARRAY_COUNT(negEpsilonLines);
274