GCC Code Coverage Report


Directory: ./
File: tasks/orehov_n_jarvis_pass/omp/src/ops_omp.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 43 49 87.8%
Functions: 7 10 70.0%
Branches: 25 40 62.5%

Line Branch Exec Source
1 #include "orehov_n_jarvis_pass/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <cmath>
6 #include <cstddef>
7 #include <vector>
8
9 #include "orehov_n_jarvis_pass/common/include/common.hpp"
10
11 namespace orehov_n_jarvis_pass {
12
13 ////
14
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 OrehovNJarvisPassOMP::OrehovNJarvisPassOMP(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 GetInput() = in;
17 12 GetOutput() = std::vector<Point>();
18 12 }
19
20 12 bool OrehovNJarvisPassOMP::ValidationImpl() {
21 12 return !GetInput().empty();
22 }
23
24 12 bool OrehovNJarvisPassOMP::PreProcessingImpl() {
25 12 return true;
26 }
27
28
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 bool OrehovNJarvisPassOMP::RunImpl() {
29 const auto &input = GetInput();
30
31
4/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 4 times.
12 if (input.size() == 1 || input.size() == 2) {
32 8 GetOutput() = input;
33 8 return true;
34 }
35
36
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 Point current = FindFirstElem(input);
37 GetOutput().push_back(current);
38
39 while (true) {
40 20 Point next = FindNext(current, input);
41 if (next == GetOutput()[0]) {
42 break;
43 }
44
45
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 12 times.
16 current = next;
46 GetOutput().push_back(next);
47 16 }
48
49 4 return true;
50 }
51
52 150 void OrehovNJarvisPassOMP::UpdateBestCandidate(Point current, const Point &candidate, Point &best, double orient) {
53
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 85 times.
150 if (orient > 0) {
54 65 best = candidate;
55
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 45 times.
85 } else if (std::abs(orient) < 1e-9) {
56 40 if (DistanceSquared(current, candidate) > DistanceSquared(current, best)) {
57 6 best = candidate;
58 }
59 }
60 150 }
61
62
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12 times.
20 Point OrehovNJarvisPassOMP::FindNext(Point current, const std::vector<Point> &input) {
63 const size_t n = input.size();
64 20 Point initial_candidate = (current == input[0]) ? input[1] : input[0];
65
66 20 int max_threads = omp_get_max_threads();
67 20 std::vector<Point> local_bests(max_threads, initial_candidate);
68 20 const int n_int = static_cast<int>(n);
69
70 20 #pragma omp parallel default(none) shared(input, n_int, current, local_bests)
71 {
72 int tid = omp_get_thread_num();
73 Point thread_local_best = local_bests[tid];
74
75 #pragma omp for nowait
76 for (int i = 0; i < n_int; ++i) {
77 const Point &point = input[i];
78 if (current == point) {
79 continue;
80 }
81
82 double orient = CheckLeft(current, thread_local_best, point);
83 UpdateBestCandidate(current, point, thread_local_best, orient);
84 }
85 local_bests[tid] = thread_local_best;
86 }
87
88 20 Point global_next = local_bests[0];
89
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 20 times.
50 for (int i = 1; i < max_threads; ++i) {
90 30 double orient = CheckLeft(current, global_next, local_bests[i]);
91 30 UpdateBestCandidate(current, local_bests[i], global_next, orient);
92 }
93
94 20 return global_next;
95 }
96
97 double OrehovNJarvisPassOMP::CheckLeft(Point a, Point b, Point c) {
98 30 return ((b.x - a.x) * (c.y - a.y)) - ((b.y - a.y) * (c.x - a.x));
99 }
100
101 Point OrehovNJarvisPassOMP::FindFirstElem(const std::vector<Point> &input) {
102 Point current = input[0];
103
2/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 4 times.
32 for (const auto &f : input) {
104
2/12
✗ 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 taken 28 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 28 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
28 if (f.x < current.x || (f.y < current.y && f.x == current.x)) {
105 current = f;
106 }
107 }
108 return current;
109 }
110
111 double OrehovNJarvisPassOMP::DistanceSquared(Point a, Point b) {
112 40 double dx = a.x - b.x;
113 40 double dy = a.y - b.y;
114
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 34 times.
40 return (dx * dx) + (dy * dy);
115 }
116
117 12 bool OrehovNJarvisPassOMP::PostProcessingImpl() {
118 12 return true;
119 }
120
121 } // namespace orehov_n_jarvis_pass
122