GCC Code Coverage Report


Directory: ./
File: tasks/kutuzov_i_convex_hull_jarvis/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 35 42 83.3%
Functions: 6 9 66.7%
Branches: 22 32 68.8%

Line Branch Exec Source
1 #include "kutuzov_i_convex_hull_jarvis/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <cstddef>
5 #include <vector>
6
7 #include "kutuzov_i_convex_hull_jarvis/common/include/common.hpp"
8
9 namespace kutuzov_i_convex_hull_jarvis {
10
11
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 KutuzovITestConvexHullSEQ::KutuzovITestConvexHullSEQ(const InType &in) {
12 SetTypeOfTask(GetStaticTypeOfTask());
13
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 GetInput() = in;
14 GetOutput() = {};
15 24 }
16
17 double KutuzovITestConvexHullSEQ::DistanceSquared(double a_x, double a_y, double b_x, double b_y) {
18 120 return ((a_x - b_x) * (a_x - b_x)) + ((a_y - b_y) * (a_y - b_y));
19 }
20
21 double KutuzovITestConvexHullSEQ::CrossProduct(double o_x, double o_y, double a_x, double a_y, double b_x, double b_y) {
22 424 return ((a_x - o_x) * (b_y - o_y)) - ((a_y - o_y) * (b_x - o_x));
23 }
24
25 24 size_t KutuzovITestConvexHullSEQ::FindLeftmostPoint(const InType &input) {
26 size_t leftmost = 0;
27 24 double leftmost_x = std::get<0>(input[leftmost]);
28 24 double leftmost_y = std::get<1>(input[leftmost]);
29
30
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 24 times.
184 for (size_t i = 0; i < input.size(); ++i) {
31 160 double x = std::get<0>(input[i]);
32 160 double y = std::get<1>(input[i]);
33
34
4/6
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 128 times.
✓ Branch 3 taken 32 times.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
160 if ((x < leftmost_x) || ((x == leftmost_x) && (y < leftmost_y))) {
35 leftmost = i;
36 leftmost_x = std::get<0>(input[leftmost]);
37 leftmost_y = std::get<1>(input[leftmost]);
38 }
39 }
40 24 return leftmost;
41 }
42
43 bool KutuzovITestConvexHullSEQ::IsBetterPoint(double cross, double epsilon, double current_x, double current_y,
44 double i_x, double i_y, double next_x, double next_y) {
45 if (cross < -epsilon) {
46 return true;
47 }
48
49
2/4
✓ Branch 0 taken 248 times.
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
368 if (std::abs(cross) < epsilon) {
50 return DistanceSquared(current_x, current_y, i_x, i_y) > DistanceSquared(current_x, current_y, next_x, next_y);
51 }
52
53 return false;
54 }
55
56 24 bool KutuzovITestConvexHullSEQ::ValidationImpl() {
57 24 return true;
58 }
59
60 24 bool KutuzovITestConvexHullSEQ::PreProcessingImpl() {
61 24 return true;
62 }
63
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 bool KutuzovITestConvexHullSEQ::RunImpl() {
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (GetInput().size() < 3) {
66 GetOutput() = GetInput();
67 return true;
68 }
69
70 // Finding left-most point
71 24 size_t leftmost = FindLeftmostPoint(GetInput());
72
73 // Main loop
74 size_t current = leftmost;
75 24 double current_x = std::get<0>(GetInput()[current]);
76 24 double current_y = std::get<1>(GetInput()[current]);
77
78 const double epsilon = 1e-9;
79
80 while (true) {
81 // Adding current point to the hull
82 GetOutput().push_back(GetInput()[current]);
83
84 // Finding the next point of the hull
85 72 size_t next = (current + 1) % GetInput().size();
86 72 double next_x = std::get<0>(GetInput()[next]);
87 72 double next_y = std::get<1>(GetInput()[next]);
88
89
2/2
✓ Branch 0 taken 496 times.
✓ Branch 1 taken 72 times.
568 for (size_t i = 0; i < GetInput().size(); ++i) {
90
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 424 times.
496 if (i == current) {
91 72 continue;
92 }
93
94 424 double i_x = std::get<0>(GetInput()[i]);
95
2/2
✓ Branch 0 taken 368 times.
✓ Branch 1 taken 56 times.
424 double i_y = std::get<1>(GetInput()[i]);
96
97 double cross = CrossProduct(current_x, current_y, next_x, next_y, i_x, i_y);
98
99
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 32 times.
120 if (IsBetterPoint(cross, epsilon, current_x, current_y, i_x, i_y, next_x, next_y)) {
100 next = i;
101 next_x = std::get<0>(GetInput()[next]);
102 next_y = std::get<1>(GetInput()[next]);
103 }
104 }
105
106 current = next;
107 current_x = next_x;
108 current_y = next_y;
109
110 // Loop until we wrap around to the first point
111
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 if (current == leftmost) {
112 break;
113 }
114 }
115 return true;
116 }
117
118 24 bool KutuzovITestConvexHullSEQ::PostProcessingImpl() {
119 24 return true;
120 }
121
122 } // namespace kutuzov_i_convex_hull_jarvis
123