Flutter Engine
The Flutter Engine
BruteForceCrossingsTest.cpp
Go to the documentation of this file.
1// Copyright 2023 Google LLC
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
5
8#include "tests/Test.h"
9
10#include <vector>
11
12using namespace bentleyottmann;
13
14DEF_TEST(BO_bruteForceCrossingsBasic, reporter) {
15
16 {
17 Segment s0 = {{-1, 0}, {1, 0}},
18 s1 = {{ 0, 1}, {0, -1}};
19
20 std::vector<Segment> segments;
21 segments.push_back(s0);
22 segments.push_back(s1);
23
24 auto possibleCrossings = brute_force_crossings(segments);
25
26 REPORTER_ASSERT(reporter, possibleCrossings.has_value());
27
28 if (possibleCrossings) {
29 auto crossings = possibleCrossings.value();
30 REPORTER_ASSERT(reporter, crossings.size() == 1);
31 Point p = {0, 0};
32 REPORTER_ASSERT(reporter, crossings[0].crossing == p);
33 REPORTER_ASSERT(reporter, (crossings[0].s0 == s0 && crossings[0].s1 == s1) ||
34 (crossings[0].s0 == s1 && crossings[0].s1 == s0));
35 }
36 }
37 {
38 Point p0 = {-50, -100},
39 p1 = { 50, -100},
40 p2 = { 0, 100};
41 Segment s0 = {p0, p1},
42 s1 = {p1, p2},
43 s2 = {p2, p0};
44
45 std::vector<Segment> segments{s0, s1, s2};
46 auto possibleCrossings = brute_force_crossings(segments);
47
48 REPORTER_ASSERT(reporter, possibleCrossings.has_value());
49 if (possibleCrossings) {
50 auto crossings = possibleCrossings.value();
51 REPORTER_ASSERT(reporter, crossings.size() == 0);
52 }
53 }
54 {
55 Point p0 = {-50, 100},
56 p1 = { 50, 100},
57 p2 = { 0, -100};
58 Segment s0 = {p0, p1},
59 s1 = {p1, p2},
60 s2 = {p2, p0};
61
62 std::vector<Segment> segments{s0, s1, s2};
63 auto possibleCrossings = brute_force_crossings(segments);
64
65 REPORTER_ASSERT(reporter, possibleCrossings.has_value());
66 if (possibleCrossings) {
67 auto crossings = possibleCrossings.value();
68 REPORTER_ASSERT(reporter, crossings.size() == 0);
69 }
70 }
71
72}
DEF_TEST(BO_bruteForceCrossingsBasic, reporter)
reporter
Definition: FontMgrTest.cpp:39
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
std::optional< std::vector< Crossing > > brute_force_crossings(SkSpan< const Segment > segments)