Skip to content

Commit 17f4221

Browse files
committed
Apply code suggestions
CURA-12361
1 parent b557589 commit 17f4221

File tree

6 files changed

+15
-22
lines changed

6 files changed

+15
-22
lines changed

include/geometry/Point2D.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Point2D
4646
std::optional<Point2D> vNormalized() const
4747
{
4848
const double size = vSize();
49-
if (is_null(size))
49+
if (is_zero(size))
5050
{
5151
return std::nullopt;
5252
}

include/utils/Coord_t.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ template<utils::floating_point FactorType>
3939
}
4040

4141
/*! Returns true if the given value is null or small enough to be considered null */
42-
[[nodiscard]] inline bool fuzzy_is_null(const coord_t value)
42+
[[nodiscard]] inline bool fuzzy_is_zero(const coord_t value)
4343
{
4444
return std::abs(value) <= EPSILON;
4545
}
4646

4747
/*! Returns true if the given values are equal or close enough to be considered equal */
4848
[[nodiscard]] inline bool fuzzy_equal(const coord_t a, const coord_t b)
4949
{
50-
return fuzzy_is_null(b - a);
50+
return fuzzy_is_zero(b - a);
5151
}
5252

5353
/*! Returns true if the given values are not equal and different enough to be considered not equal */

include/utils/math.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ template<utils::floating_point T>
138138

139139
/*! \brief Check if a value is very close to 0 */
140140
template<utils::floating_point T>
141-
[[nodiscard]] bool is_null(T value)
141+
[[nodiscard]] bool is_zero(T value)
142142
{
143143
return std::abs(value) < (std::numeric_limits<T>::epsilon() * 100.0);
144144
}
@@ -150,7 +150,7 @@ template<utils::floating_point T>
150150
template<utils::numeric T>
151151
[[nodiscard]] int8_t sign(T value)
152152
{
153-
return value >= static_cast<T>(0) ? 1 : -1;
153+
return std::signbit(value) ? -1 : 1;
154154
}
155155

156156
} // namespace cura

src/bridge.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ struct TransformedSegment
7070

7171
void updateMinMax()
7272
{
73-
min_y = std::min(start.Y, end.Y);
74-
max_y = std::max(start.Y, end.Y);
73+
std::tie(min_y, max_y) = std::minmax(start.Y, end.Y);
7574
}
7675

7776
/*!
@@ -330,7 +329,7 @@ coord_t evaluateBridgeLine(const coord_t line_y, const TransformedShape& transfo
330329
const double next_intersection_skin_area = skin_outline_intersections.front();
331330
const double next_intersection_supported_area = supported_regions_intersections.front();
332331

333-
if (is_null(next_intersection_skin_area - next_intersection_supported_area))
332+
if (is_zero(next_intersection_skin_area - next_intersection_supported_area))
334333
{
335334
next_intersection_is_skin_area = true;
336335
next_intersection_is_supported_area = true;
@@ -753,7 +752,7 @@ struct ExpansionRange
753752
return data.segment.calculateOverlapping(other, expand_direction);
754753
}
755754

756-
if (other.min_y > (y_max() - EPSILON) || other.max_y < (y_min() - EPSILON))
755+
if (fuzzy_is_greater_or_equal(other.min_y, y_max()) || fuzzy_is_lesser_or_equal(other.max_y, y_min()))
757756
{
758757
// Not on the same horizontal band, or very slightly overlapping , discard
759758
return std::nullopt;
@@ -1080,11 +1079,6 @@ std::tuple<Shape, AngleDegrees> makeBridgeOverInfillPrintable(
10801079
// Perform a morphological closing to remove overlapping lines
10811080
transformed_expanded_infill_below_skin_area = transformed_expanded_infill_below_skin_area.offset(EPSILON).offset(-EPSILON).intersection(infill_contour);
10821081

1083-
SVG svg(fmt::format("/tmp/skin_support.svg"), AABB(transformed_expanded_infill_below_skin_area));
1084-
svg.write(infill_below_skin_area, { .surface = { SVG::Color::BLUE } });
1085-
svg.write(infill_lines_below, { .line = { SVG::Color::MAGENTA, 0.4 } });
1086-
svg.write(transformed_expanded_infill_below_skin_area, { .surface = { SVG::Color::RED, 0.3 } });
1087-
10881082
return { transformed_expanded_infill_below_skin_area, bridge_angle };
10891083
}
10901084

src/utils/linearAlg2D.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ std::optional<coord_t> LinearAlg2D::lineHorizontalLineIntersection(const Point2L
349349

350350
std::optional<coord_t> LinearAlg2D::segmentHorizontalLineIntersection(const Point2LL& p1, const Point2LL& p2, const coord_t line_y)
351351
{
352-
const coord_t min_y = std::min(p1.Y, p2.Y);
353-
const coord_t max_y = std::max(p1.Y, p2.Y);
352+
const auto [min_y, max_y] = std::minmax(p1.Y, p2.Y);
354353

355354
if (min_y > line_y || max_y < line_y)
356355
{

tests/utils/CoordTTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ namespace cura
1111
{
1212
// NOLINTBEGIN(*-magic-numbers)
1313

14-
TEST(CoordTTest, TestFuzzyNull)
14+
TEST(CoordTTest, TestFuzzyZero)
1515
{
16-
EXPECT_EQ(fuzzy_is_null(0), true);
17-
EXPECT_EQ(fuzzy_is_null(2), true);
18-
EXPECT_EQ(fuzzy_is_null(-2), true);
19-
EXPECT_EQ(fuzzy_is_null(10), false);
20-
EXPECT_EQ(fuzzy_is_null(-10), false);
16+
EXPECT_EQ(fuzzy_is_zero(0), true);
17+
EXPECT_EQ(fuzzy_is_zero(2), true);
18+
EXPECT_EQ(fuzzy_is_zero(-2), true);
19+
EXPECT_EQ(fuzzy_is_zero(10), false);
20+
EXPECT_EQ(fuzzy_is_zero(-10), false);
2121
}
2222

2323
TEST(CoordTTest, TestFuzzyEqual)

0 commit comments

Comments
 (0)