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