22static bool operator==(std::pair<const Point &, const Point &> l, std::tuple<Point, Point> r) {
52 const auto [u, l] =
s;
61 const auto [u, l] =
s;
70 s1 = {{0, 0}, {-1, 1}};
81 s1 = {{-1, 0}, {2, 0}};
87 s1 = {{0, 0}, {1, 1}};
93DEF_TEST(MFC_segment_less_than_upper_to_insert, r) {
94 Segment s0 = {{-10, -10}, {10, 10}},
95 s1 = {{10, -10}, {-10, 10}},
96 to_insert = {{0, 0}, {0, 3}};
99 std::vector<Segment> sweepLine = {s1, s0};
101 auto insertionPoint = std::lower_bound(sweepLine.begin(), sweepLine.end(), to_insert,
112 s1 = {{0, 0}, {-2, 2}};
117 Segment s0 = {{-2, -2}, {2, 2}},
118 s1 = {{2, -2}, {-2, 2}};
127 Segment s0 = {{-2, -100}, {-2, 89}},
128 s1 = {{6, -70}, {-2, 72}};
135 return {
s.lower(),
s.upper()};
147 Segment s0 = {{-1, 0}, {1, 0}},
148 s1 = {{ 0, 1}, {0, -1}};
150 checkIntersection(s0, s1);
153 Segment s0 = {{-1, 0}, {5, 0}},
154 s1 = {{ 0, 1}, {0, -1}};
156 checkIntersection(s0, s1);
160 Segment s0 = {{5, 0}, {-1, 0}},
161 s1 = {{ 0, -1}, {0, 1}};
163 checkIntersection(s0, s1);
167 Segment s0 = {{-5, -5}, {5, 5}},
168 s1 = {{-5, 5}, {5, -5}};
170 checkIntersection(s0, s1);
174 for (int32_t x0 = -10; x0 <= 10; x0++) {
175 for (int32_t x1 = -10; x1 <= 10; x1++) {
176 for (int32_t x2 = -10; x2 <= 10; x2++) {
177 for (int32_t x3 = -10; x3 <= 10; x3++) {
183 bool expected = (x0 <= x2 && x3 <= x1) || (x2 <= x0 && x1 <= x3);
184 if (actual != expected) {
194 Segment s0 = {{0, -100}, {0, -50}},
195 s1 = {{100, -100}, {-100, 100}};
200 Segment s0 = {{0, 100}, {0, 50}},
201 s1 = {{100, -100}, {-100, 100}};
206 Segment s0 = {{0, -101}, {0, -50}},
207 s1 = {{100, -100}, {-100, 100}};
214 const std::vector<Segment>
tests[] = {
215 {{{-58, -100}, {75, 105}}, {{149, -58}, {-156, 49}}, {{-34, -55}, {37, 49}}, {{-58, -100}, {75, 105}}, {{-147, -229}, {143, 220}}},
216 {{{-57, -138}, {56, 178}}, {{14, -146}, {-22, 132}}},
217 {{{-4, -23}, {-11, 11}}, {{6, -2}, {-11, 11}}, {{159, -244}, {-159, 233}}},
218 {{{-7, -22}, {10, 14}}, {{-7, -71}, {-7, 80}}, {{-7, -22}, {-4, 5}}},
219 {{{91, -22}, {-93, 24}}, {{31, -18}, {-25, 7}}, {{-25, 7}, {33, 12}}, {{-26, -24}, {18, 20}}},
220 {{{2, -21}, {-16, 7}}, {{-45, -28}, {51, 35}}, {{39, -48}, {-53, 44}}, {{-16, 7}, {26, 7}}},
221 {{{142, -82}, {-128, 64}}, {{208, -16}, {-217, -3}}, {{91, -22}, {-93, 24}}, {{31, -18}, {-25, 7}}, {{-25, 7}, {33, 12}}},
222 {{{-159, -101}, {167, 91}}, {{-96, -117}, {99, 117}}, {{-16, -21}, {12, 35}}, {{-48, -55}, {33, 63}}, {{-16, -21}, {26, 41}}},
223 {{{-51, -18}, {34, 1}}, {{189, -169}, {-171, 150}}, {{24, -8}, {-5, 7}}, {{24, -8}, {-26, 16}}, {{54, -22}, {-36, 20}}},
224 {{{-29, -3}, {15, -3}}, {{-28, -7}, {15, -3}}},
225 {{{20, -149}, {-32, 130}}, {{-29, -3}, {15, -3}}, {{-28, -7}, {15, -3}}},
226 {{{-32, -8}, {16, -8}}, {{-28, -104}, {23, 88}}, {{-17, -11}, {16, -8}}},
227 {{{-59, -9}, {48, 11}}, {{-59, -9}, {75, -9}}, {{173, -20}, {-178, 13}}},
228 {{{-11, 1}, {12, 1}}, {{-42, -35}, {54, 29}}},
229 {{{14, -11}, {-15, -2}}, {{-9, -2}, {13, -2}}},
230 {{{-38, 7}, {47, 7}}, {{-148, 6}, {166, 7}}},
231 {{{-26, -22}, {9, 21}}, {{-32, -28}, {13, 17}}},
232 {{{23, -2}, {-12, 3}}, {{22, -13}, {-5, 2}}},
233 {{{-2, -100}, {-2, 89}}, {{6, -70}, {-2, 72}}},
234 {{{8, -1}, {-8, 19}}, {{-130, -93}, {137, 85}}},
235 {{{-39, -111}, {25, 119}}, {{-26, -112}, {25, 119}}},
236 {{{-9, -5}, {16, -5}}, {{90, -134}, {-71, 144}}},
237 {{{-1, -1}, {1, 1}}, {{1, -1}, {-1, 1}}},
238 {{{-1, -1}, {-1, 1}}, {{1, -1}, {1, 1}}},
239 {{{-1, -1}, {1, -1}}, {{-1, 1}, {1, 1}}},
240 {{{-2, 1}, {1, 1}}, {{-1, 1}, {2, 1}}},
241 {{{0, -100}, {0, -50}}, {{100, -100}, {-100, 100}}},
242 {{{0, 100}, {0, 50}}, {{100, -100}, {-100, 100}}},
243 {{{0, -101}, {0, -50}}, {{100, -100}, {-100, 100}}},
244 {{{0, 0}, {0, 50}}, {{100, -100}, {-100, 100}}},
245 {{{-10, -10}, {10, 10}}, {{-10, -10}, {11, 11}}, {{10, -10}, {-10, 10}}},
246 {{{10, -10}, {-10, 10}}, {{10, -10}, {-11, 11}}, {{-10, -10}, {10, 10}}},
247 {{{-11, -11}, {10, 10}}, {{-10, -10}, {11, 11}}, {{10, -10}, {-10, 10}}},
250 for (
const auto& segments :
tests) {
251 std::vector<Segment> myersSegments = segments;
252 std::vector<Segment> bruteSegments = segments;
256 std::sort(myersResponse.begin(), myersResponse.end());
257 std::sort(bruteResponse.begin(), bruteResponse.end());
261 if (myersResponse.size() != bruteResponse.size()) {
267 std::unique(myersResponse.begin(), myersResponse.end()) ==
268 myersResponse.end());
270 std::unique(bruteResponse.begin(), bruteResponse.end()) ==
271 bruteResponse.end());
275 bruteResponse.begin(), bruteResponse.end()));
282 fStart = std::chrono::high_resolution_clock::now();
286 std::chrono::high_resolution_clock::time_point
stop =
287 std::chrono::high_resolution_clock::now();
289 fAccumulatedTime += std::chrono::duration_cast<std::chrono::microseconds>(
stop - fStart);
294 int64_t average = fAccumulatedTime.count() / fCount;
295 SkDebugf(
"average time: %" PRId64
" µs\n", average);
300 std::chrono::high_resolution_clock::time_point fStart;
301 std::chrono::microseconds fAccumulatedTime = std::chrono::microseconds::zero();
305DEF_TEST(MFC_myers_brute_force_random_comparison, r) {
310 const int boxSize = 20000;
312 std::vector<Segment> segments;
317 for (
int trials = 0; trials < 100'000; trials++) {
318 for (
int i = 0;
i < n; ++
i) {
319 float x = random.nextRangeF(-boxSize, boxSize),
320 y = random.nextRangeF(-boxSize, boxSize);
323 float distance = random.nextRangeF(10, 300);
330 segments.emplace_back(p0, p1);
333 std::vector<Segment> myersSegments = segments;
334 std::vector<Segment> bruteSegments = segments;
335 myersStopWatch.
start();
337 myersStopWatch.
stop();
338 bruteStopWatch.
start();
340 bruteStopWatch.
stop();
342 std::sort(myersResponse.begin(), myersResponse.end());
343 std::sort(bruteResponse.begin(), bruteResponse.end());
348 if (myersResponse.size() != bruteResponse.size()) {
349 SkDebugf(
"myers size: %zu brute size: %zu\n", myersResponse.size(), bruteResponse.size());
352 const auto [u, l] =
s;
353 SkDebugf(
"{{%d, %d}, {%d, %d}}, ", u.x, u.y, l.x, l.y);
360 std::unique(myersResponse.begin(), myersResponse.end()) ==
361 myersResponse.end());
363 std::unique(bruteResponse.begin(), bruteResponse.end()) ==
364 bruteResponse.end());
368 bruteResponse.begin(), bruteResponse.end()));
372 myersStopWatch.
print();
374 bruteStopWatch.
print();
static bool equal(const SkBitmap &a, const SkBitmap &b)
static bool operator==(std::pair< const Point &, const Point & > l, std::tuple< Point, Point > r)
constexpr bool kRunRandomTest
static Segment swap_ends(const Segment &s)
DEF_TEST(MFC_order_segment_points, r)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define sk_float_round2int(x)
constexpr float SK_FloatPI
static std::vector< SkPDFIndirectReference > sort(const THashSet< SkPDFIndirectReference > &src)
#define REPORTER_ASSERT(r, cond,...)
std::optional< std::vector< Crossing > > brute_force_crossings(SkSpan< const Segment > segments)
bool s0_less_than_s1_at_y(const Segment &s0, const Segment &s1, int32_t y)
bool s0_intersects_s1(const Segment &s0, const Segment &s1)
const myers::Point & get< 1 >(const myers::Segment &s)
const myers::Point & get< 0 >(const myers::Segment &s)
bool slope_s0_less_than_slope_s1(const Segment &s0, const Segment &s1)
std::vector< Crossing > myers_find_crossings(const SkSpan< const Segment > segments)
bool segment_less_than_upper_to_insert(const Segment &segment, const Segment &to_insert)