| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "yurkin_g_graham_scan/stl/include/ops_stl.hpp" | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <ranges> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "yurkin_g_graham_scan/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace yurkin_g_graham_scan { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | YurkinGGrahamScanSTL::YurkinGGrahamScanSTL(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | GetInput() = in; |
| 15 | GetOutput().clear(); | ||
| 16 | 8 | } | |
| 17 | |||
| 18 | 8 | bool YurkinGGrahamScanSTL::ValidationImpl() { | |
| 19 | 8 | return !GetInput().empty(); | |
| 20 | } | ||
| 21 | |||
| 22 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | bool YurkinGGrahamScanSTL::PreProcessingImpl() { |
| 23 | auto &pts = GetInput(); | ||
| 24 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | if (pts.empty()) { |
| 25 | return true; | ||
| 26 | } | ||
| 27 | |||
| 28 | std::ranges::sort(pts, [](const Point &a, const Point &b) { | ||
| 29 |
4/26✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 40 times.
✓ Branch 23 taken 16 times.
✓ Branch 24 taken 104 times.
✓ Branch 25 taken 40 times.
|
200 | if (a.x != b.x) { |
| 30 | 144 | return a.x < b.x; | |
| 31 | } | ||
| 32 | 56 | return a.y < b.y; | |
| 33 | }); | ||
| 34 | |||
| 35 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | std::vector<Point> tmp; |
| 36 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | tmp.reserve(pts.size()); |
| 37 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 8 times.
|
72 | for (const auto &p : pts) { |
| 38 |
6/6✓ Branch 0 taken 56 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 24 times.
✓ Branch 5 taken 8 times.
|
64 | if (tmp.empty() || tmp.back().x != p.x || tmp.back().y != p.y) { |
| 39 | tmp.push_back(p); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | pts.swap(tmp); | ||
| 43 | |||
| 44 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | return !pts.empty(); |
| 45 | } | ||
| 46 | |||
| 47 | namespace { // helper: cross product | ||
| 48 | long double Cross(const Point &o, const Point &a, const Point &b) { | ||
| 49 | 96 | return (static_cast<long double>(a.x - o.x) * static_cast<long double>(b.y - o.y)) - | |
| 50 | 96 | (static_cast<long double>(a.y - o.y) * static_cast<long double>(b.x - o.x)); | |
| 51 | } | ||
| 52 | } // namespace | ||
| 53 | |||
| 54 | 8 | bool YurkinGGrahamScanSTL::RunImpl() { | |
| 55 | 8 | const InType pts_in = GetInput(); | |
| 56 | const std::size_t n = pts_in.size(); | ||
| 57 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (n == 0) { |
| 58 | GetOutput().clear(); | ||
| 59 | ✗ | return true; | |
| 60 | } | ||
| 61 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (n == 1) { |
| 62 | ✗ | GetOutput() = pts_in; | |
| 63 | return true; | ||
| 64 | } | ||
| 65 | |||
| 66 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | InType pts = pts_in; |
| 67 | std::ranges::sort(pts, [](const Point &a, const Point &b) { | ||
| 68 |
4/26✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 40 times.
✓ Branch 23 taken 8 times.
✓ Branch 24 taken 24 times.
✓ Branch 25 taken 24 times.
|
96 | if (a.x != b.x) { |
| 69 | 64 | return a.x < b.x; | |
| 70 | } | ||
| 71 | 32 | return a.y < b.y; | |
| 72 | }); | ||
| 73 | |||
| 74 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | OutType lower; |
| 75 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | lower.reserve(pts.size()); |
| 76 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 8 times.
|
64 | for (const auto &p : pts) { |
| 77 |
4/4✓ Branch 0 taken 48 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 16 times.
|
88 | while (lower.size() >= 2 && Cross(lower[lower.size() - 2], lower[lower.size() - 1], p) <= 0) { |
| 78 | lower.pop_back(); | ||
| 79 | } | ||
| 80 | lower.push_back(p); | ||
| 81 | } | ||
| 82 | |||
| 83 | 8 | OutType upper; | |
| 84 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | upper.reserve(pts.size()); |
| 85 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 8 times.
|
64 | for (const auto &p : std::ranges::reverse_view(pts)) { |
| 86 |
4/4✓ Branch 0 taken 48 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 32 times.
|
88 | while (upper.size() >= 2 && Cross(upper[upper.size() - 2], upper[upper.size() - 1], p) <= 0) { |
| 87 | upper.pop_back(); | ||
| 88 | } | ||
| 89 | upper.push_back(p); | ||
| 90 | } | ||
| 91 | |||
| 92 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | OutType hull; |
| 93 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | hull.reserve(lower.size() + upper.size()); |
| 94 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
|
32 | for (const auto &pt : lower) { |
| 95 | hull.push_back(pt); | ||
| 96 | } | ||
| 97 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
16 | for (std::size_t i = 1; i + 1 < upper.size(); ++i) { |
| 98 | hull.push_back(upper[i]); | ||
| 99 | } | ||
| 100 | |||
| 101 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | GetOutput() = hull; |
| 102 | return true; | ||
| 103 | } | ||
| 104 | |||
| 105 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | bool YurkinGGrahamScanSTL::PostProcessingImpl() { |
| 106 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | if (GetInput().empty()) { |
| 107 | return true; | ||
| 108 | } | ||
| 109 | 8 | return !GetOutput().empty(); | |
| 110 | } | ||
| 111 | |||
| 112 | } // namespace yurkin_g_graham_scan | ||
| 113 |