Skip to content

Commit 0848e86

Browse files
committed
src: robotics: bresenham: fixed too much break warning in sonar cloud
1 parent e96744b commit 0848e86

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

src/robotics/bresenham/src/bresenham.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,29 @@ LineGenerator::LineGenerator(const Coordinate& start, const Coordinate& end) {
2727
while (true) {
2828
points_.emplace_back(Coordinate{x, y});
2929
if (start == end) break;
30+
3031
const auto e2 = 2 * error;
32+
bool should_break = false;
33+
3134
if (e2 >= dy) {
32-
if (x == end.x) break;
33-
error += dy;
34-
x += sx;
35+
if (x == end.x) {
36+
should_break = true;
37+
} else {
38+
error += dy;
39+
x += sx;
40+
}
3541
}
36-
if (e2 <= dx) {
37-
if (y == end.y) break;
38-
error += dx;
39-
y += sy;
42+
43+
if (!should_break && e2 <= dx) {
44+
if (y == end.y) {
45+
should_break = true;
46+
} else {
47+
error += dx;
48+
y += sy;
49+
}
4050
}
51+
52+
if (should_break) break;
4153
}
4254
}
4355

0 commit comments

Comments
 (0)