MCPcopy Create free account
hub / github.com/AngusJohnson/Clipper2 / TEST

Function TEST

CPP/Tests/TestRandomPaths.cpp:42–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40 return result;
41}
42TEST(Clipper2Tests, TestRandomPaths)
43{
44 std::default_random_engine rng(42);
45#if DEBUG
46 for (int i = 0; i < 10; ++i)
47#else
48 for (int i = 0; i < 750; ++i)
49#endif
50 {
51 const auto max_complexity = std::max(1, i / 10);
52 const auto subject = GenerateRandomPaths(rng, 1, max_complexity);
53 const auto subject_open = GenerateRandomPaths(rng, 0, max_complexity);
54 const auto clip = GenerateRandomPaths(rng, 0, max_complexity);
55 const Clipper2Lib::ClipType ct = static_cast<Clipper2Lib::ClipType>(GenerateRandomInt(rng, 0, 4));
56 const Clipper2Lib::FillRule fr = static_cast<Clipper2Lib::FillRule>(GenerateRandomInt(rng, 0, 3));
57 //SaveInputToFile(subject, subject_open, clip, ct, fr);
58 Clipper2Lib::Paths64 solution, solution_open;
59 Clipper2Lib::Clipper64 c;
60 c.AddSubject(subject);
61 c.AddOpenSubject(subject_open);
62 c.AddClip(clip);
63 c.Execute(ct, fr, solution, solution_open);
64 const int64_t area_paths = static_cast<int64_t>(Area(solution));
65 const int64_t count_paths = solution.size() + solution_open.size();
66 Clipper2Lib::PolyTree64 solution_polytree;
67 Clipper2Lib::Paths64 solution_polytree_open;
68 Clipper2Lib::Clipper64 clipper_polytree;
69 clipper_polytree.AddSubject(subject);
70 clipper_polytree.AddOpenSubject(subject_open);
71 clipper_polytree.AddClip(clip);
72 clipper_polytree.Execute(ct, fr, solution_polytree, solution_polytree_open);
73 const auto solution_polytree_paths = PolyTreeToPaths64(solution_polytree);
74 const int64_t area_polytree = static_cast<int64_t>(Area(solution_polytree_paths));
75 const int64_t count_polytree = solution_polytree_paths.size() + solution_polytree_open.size();
76 EXPECT_EQ(area_paths, area_polytree);
77 // polytree does an additional bounds check on each path
78 // and discards paths with empty bounds, so count_polytree
79 // may on occasions be slightly less than count_paths even
80 // though areas match
81 //EXPECT_LE(count_paths - count_polytree, 2);
82 }
83}

Callers

nothing calls this directly

Calls 8

GenerateRandomIntFunction · 0.85
PolyTreeToPaths64Function · 0.85
GenerateRandomPathsFunction · 0.70
AreaFunction · 0.50
AddSubjectMethod · 0.45
AddOpenSubjectMethod · 0.45
AddClipMethod · 0.45
ExecuteMethod · 0.45

Tested by

no test coverage detected