diff --git a/include/geometry/ClosedPolyline.h b/include/geometry/ClosedPolyline.h index 45b204dcd0..8f4bc3e753 100644 --- a/include/geometry/ClosedPolyline.h +++ b/include/geometry/ClosedPolyline.h @@ -32,6 +32,8 @@ class ClosedPolyline : public Polyline bool explicitely_closed_{ false }; public: + ClosedPolyline() = default; + /*! * \brief Builds an empty closed polyline * \param explicitely_closed Indicates whether the line will be explicitely closed @@ -39,9 +41,8 @@ class ClosedPolyline : public Polyline * constructor in various places, but be careful that the interpretation of the points * added later will depend on this. */ - ClosedPolyline(bool explicitely_closed = false) - : Polyline() - , explicitely_closed_(explicitely_closed) + explicit ClosedPolyline(const bool explicitely_closed) + : explicitely_closed_{ explicitely_closed } { } @@ -56,8 +57,8 @@ class ClosedPolyline : public Polyline * \param explicitely_closed Specify whether the given points form an explicitely closed line */ ClosedPolyline(const std::initializer_list& initializer, bool explicitely_closed) - : Polyline(initializer) - , explicitely_closed_(explicitely_closed) + : Polyline{ initializer } + , explicitely_closed_{ explicitely_closed } { } @@ -66,8 +67,8 @@ class ClosedPolyline : public Polyline * \param explicitely_closed Specify whether the given points form an explicitely closed line */ explicit ClosedPolyline(const ClipperLib::Path& points, bool explicitely_closed) - : Polyline(points) - , explicitely_closed_(explicitely_closed) + : Polyline{ points } + , explicitely_closed_{ explicitely_closed } { } @@ -76,36 +77,30 @@ class ClosedPolyline : public Polyline * \param explicitely_closed Specify whether the given points form an explicitely closed line */ explicit ClosedPolyline(ClipperLib::Path&& points, bool explicitely_closed) - : Polyline(points) - , explicitely_closed_(explicitely_closed) + : Polyline{ std::move(points) } + , explicitely_closed_{ explicitely_closed } { } + ~ClosedPolyline() override = default; + /*! @see Polyline::hasClosingSegment() */ - virtual bool hasClosingSegment() const + [[nodiscard]] bool hasClosingSegment() const override { return ! explicitely_closed_; } /*! @see Polyline::addClosingSegment() */ - virtual size_t segmentsCount() const override; + [[nodiscard]] size_t segmentsCount() const override; /*! @see Polyline::isValid() */ - virtual bool isValid() const override; + [[nodiscard]] bool isValid() const override; - ClosedPolyline& operator=(const ClosedPolyline& other) - { - Polyline::operator=(other); - return *this; - } + ClosedPolyline& operator=(const ClosedPolyline& other) = default; - ClosedPolyline& operator=(ClosedPolyline&& other) - { - Polyline::operator=(other); - return *this; - } + ClosedPolyline& operator=(ClosedPolyline&& other) = default; - bool isExplicitelyClosed() const + [[nodiscard]] bool isExplicitelyClosed() const { return explicitely_closed_; } @@ -126,9 +121,9 @@ class ClosedPolyline : public Polyline * * http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Functions/PointInPolygon.htm */ - bool inside(const Point2LL& p, bool border_result = false) const; + [[nodiscard]] bool inside(const Point2LL& p, bool border_result = false) const; - bool inside(const ClipperLib::Path& polygon) const; + [[nodiscard]] bool inside(const ClipperLib::Path& polygon) const; /*! * \brief Converts the closed polyline to an open polyline which happens to have its end and start points at the same @@ -137,7 +132,7 @@ class ClosedPolyline : public Polyline * between open and closed polylines * \return An open polyline instance, with the end point at the same position of the start point */ - OpenPolyline toPseudoOpenPolyline() const; + [[nodiscard]] OpenPolyline toPseudoOpenPolyline() const; }; } // namespace cura diff --git a/include/geometry/LinesSet.h b/include/geometry/LinesSet.h index 10d327e2bc..3de08203a9 100644 --- a/include/geometry/LinesSet.h +++ b/include/geometry/LinesSet.h @@ -53,13 +53,13 @@ class LinesSet LinesSet(LinesSet&& other) = default; /*! \brief Constructor with an existing set of lines */ - LinesSet(const std::vector& lines) + explicit LinesSet(const std::vector& lines) : lines_(lines) { } /*! \brief Constructor that takes ownership of the data from the given set of lines */ - LinesSet(std::vector&& lines) + explicit LinesSet(std::vector&& lines) : lines_(std::move(lines)) { } @@ -70,7 +70,7 @@ class LinesSet * objects, because closed ones require an additional argument */ template - requires std::is_same_v LinesSet(ClipperLib::Paths&& paths) + requires std::is_same_v explicit LinesSet(ClipperLib::Paths&& paths) { reserve(paths.size()); for (ClipperLib::Path& path : paths) @@ -196,17 +196,9 @@ class LinesSet return lines_.erase(first, last); } - LinesSet& operator=(const LinesSet& other) - { - lines_ = other.lines_; - return *this; - } + LinesSet& operator=(const LinesSet& other) = default; - LinesSet& operator=(LinesSet&& other) noexcept - { - lines_ = std::move(other.lines_); - return *this; - } + LinesSet& operator=(LinesSet&& other) noexcept = default; LineType& operator[](size_t index) { @@ -225,7 +217,7 @@ class LinesSet } /*! \brief Return the amount of points in all lines */ - size_t pointCount() const; + [[nodiscard]] size_t pointCount() const; /*! * Remove a line from the list and move the last line to its place @@ -237,15 +229,15 @@ class LinesSet void addSegment(const Point2LL& from, const Point2LL& to); /*! \brief Get the total length of all the lines */ - coord_t length() const; + [[nodiscard]] coord_t length() const; void splitIntoSegments(OpenLinesSet& result) const; - OpenLinesSet splitIntoSegments() const; + [[nodiscard]] OpenLinesSet splitIntoSegments() const; /*! \brief Removes overlapping consecutive line segments which don't delimit a positive area */ void removeDegenerateVerts(); - Shape offset(coord_t distance, ClipperLib::JoinType join_type = ClipperLib::jtMiter, double miter_limit = 1.2) const; + [[nodiscard]] Shape offset(coord_t distance, ClipperLib::JoinType join_type = ClipperLib::jtMiter, double miter_limit = 1.2) const; /*! * Utility method for creating the tube (or 'donut') of a shape. @@ -257,7 +249,7 @@ class LinesSet * shape. Comparable to normal offset. * \return The resulting polygons. */ - Shape createTubeShape(const coord_t inner_offset, const coord_t outer_offset) const; + [[nodiscard]] Shape createTubeShape(const coord_t inner_offset, const coord_t outer_offset) const; void translate(const Point2LL& delta); @@ -265,13 +257,13 @@ class LinesSet * \brief Utility method to add all the lines to a ClipperLib::Clipper object * \note This method needs to be public but you shouldn't need to use it from outside */ - void addPaths(ClipperLib::Clipper& clipper, ClipperLib::PolyType PolyTyp) const; + void addPaths(ClipperLib::Clipper& clipper, ClipperLib::PolyType poly_typ) const; /*! * \brief Utility method to add all the lines to a ClipperLib::ClipperOffset object * \note This method needs to be public but you shouldn't need to use it from outside */ - void addPaths(ClipperLib::ClipperOffset& clipper, ClipperLib::JoinType jointType, ClipperLib::EndType endType) const; + void addPaths(ClipperLib::ClipperOffset& clipper, ClipperLib::JoinType joint_type, ClipperLib::EndType end_type) const; /*! * \brief Display operator, useful for debugging/testing diff --git a/include/geometry/MixedLinesSet.h b/include/geometry/MixedLinesSet.h index 2017e87be8..f692f47661 100644 --- a/include/geometry/MixedLinesSet.h +++ b/include/geometry/MixedLinesSet.h @@ -36,7 +36,7 @@ class MixedLinesSet : public std::vector * \return A shape containing the offsetted polylines. This may contain many unjoined polygons, * but no overlapping ones. */ - Shape offset(coord_t distance, ClipperLib::JoinType join_type = ClipperLib::jtMiter, double miter_limit = 1.2) const; + [[nodiscard]] Shape offset(coord_t distance, ClipperLib::JoinType join_type = ClipperLib::jtMiter, double miter_limit = 1.2) const; /*! @brief Adds a copy of the given polyline to the set */ void push_back(const OpenPolyline& line); @@ -72,7 +72,7 @@ class MixedLinesSet : public std::vector void push_back(ClosedLinesSet&& lines_set); /*! \brief Computes the total lenght of all the polylines in the set */ - coord_t length() const; + [[nodiscard]] coord_t length() const; }; } // namespace cura diff --git a/include/geometry/OpenPolyline.h b/include/geometry/OpenPolyline.h index 84c0cccdd0..f9a3d1b62e 100644 --- a/include/geometry/OpenPolyline.h +++ b/include/geometry/OpenPolyline.h @@ -41,7 +41,7 @@ class OpenPolyline : public Polyline * \warning A copy of the points list is made, so this constructor is somehow "slow" */ OpenPolyline(const std::initializer_list& initializer) - : Polyline(initializer) + : Polyline{ initializer } { } @@ -49,8 +49,8 @@ class OpenPolyline : public Polyline * \brief Constructor with an existing list of points * \warning A copy of the points list is made, so this constructor is somehow "slow" */ - OpenPolyline(const ClipperLib::Path& points) - : Polyline(points) + explicit OpenPolyline(const ClipperLib::Path& points) + : Polyline{ points } { } @@ -59,40 +59,34 @@ class OpenPolyline : public Polyline * \warning This constructor is fast because it does not allocate data, but it will clear * the source object */ - OpenPolyline(ClipperLib::Path&& points) - : Polyline(std::move(points)) + explicit OpenPolyline(ClipperLib::Path&& points) + : Polyline{ std::move(points) } { } + ~OpenPolyline() override = default; + /*! @see Polyline::hasClosingSegment() */ - virtual bool hasClosingSegment() const override + [[nodiscard]] bool hasClosingSegment() const override { return false; // Definitely not } /*! @see Polyline::segmentsCount() */ - virtual size_t segmentsCount() const override + [[nodiscard]] size_t segmentsCount() const override { return size() > 1 ? size() - 1 : 0; } /*! @see Polyline::isValid() */ - virtual bool isValid() const override + [[nodiscard]] bool isValid() const override { return size() >= 2; } - OpenPolyline& operator=(OpenPolyline&& other) - { - Polyline::operator=(std::move(other)); - return *this; - } + OpenPolyline& operator=(OpenPolyline&& other) noexcept = default; - OpenPolyline& operator=(const OpenPolyline& other) - { - Polyline::operator=(other); - return *this; - } + OpenPolyline& operator=(const OpenPolyline& other) = default; }; } // namespace cura diff --git a/include/geometry/PartsView.h b/include/geometry/PartsView.h index f43c8c1d21..e8b6b59d31 100644 --- a/include/geometry/PartsView.h +++ b/include/geometry/PartsView.h @@ -21,11 +21,21 @@ class PartsView : public std::vector> public: Shape& polygons_; - PartsView(Shape& polygons) - : polygons_(polygons) + PartsView() = delete; + + explicit PartsView(Shape& polygons) + : polygons_{ polygons } { } + PartsView(PartsView&& parts_view) = default; + PartsView(const PartsView& parts_view) = default; + + ~PartsView() = default; + + PartsView& operator=(PartsView&& parts_view) = delete; + PartsView& operator=(const PartsView& parts_view) = delete; + /*! * Get the index of the SingleShape of which the polygon with index \p poly_idx is part. * @@ -50,7 +60,7 @@ class PartsView : public std::vector> * \param part_idx The index of the part * \return The SingleShape with index \p poly_idx */ - SingleShape assemblePart(size_t part_idx) const; + [[nodiscard]] SingleShape assemblePart(size_t part_idx) const; }; } // namespace cura diff --git a/include/geometry/Point2LL.h b/include/geometry/Point2LL.h index 8217d7e797..50781d49b6 100644 --- a/include/geometry/Point2LL.h +++ b/include/geometry/Point2LL.h @@ -42,36 +42,44 @@ INLINE Point2LL operator-(const Point2LL& p0) { return { -p0.X, -p0.Y }; } + INLINE Point2LL operator+(const Point2LL& p0, const Point2LL& p1) { return { p0.X + p1.X, p0.Y + p1.Y }; } + INLINE Point2LL operator-(const Point2LL& p0, const Point2LL& p1) { return { p0.X - p1.X, p0.Y - p1.Y }; } + INLINE Point2LL operator*(const Point2LL& p0, const coord_t i) { return { p0.X * i, p0.Y * i }; } + template::value, T>::type> // Use only for numeric types. INLINE Point2LL operator*(const Point2LL& p0, const T i) { return { std::llrint(static_cast(p0.X) * i), std::llrint(static_cast(p0.Y) * i) }; } + template::value, T>::type> // Use only for numeric types. INLINE Point2LL operator*(const T i, const Point2LL& p0) { return p0 * i; } + INLINE Point2LL operator/(const Point2LL& p0, const coord_t i) { return { p0.X / i, p0.Y / i }; } + INLINE Point2LL operator/(const Point2LL& p0, const Point2LL& p1) { return { p0.X / p1.X, p0.Y / p1.Y }; } + INLINE Point2LL operator%(const Point2LL& p0, const coord_t i) { return { p0.X % i, p0.Y % i }; @@ -83,6 +91,7 @@ INLINE Point2LL& operator+=(Point2LL& p0, const Point2LL& p1) p0.Y += p1.Y; return p0; } + INLINE Point2LL& operator-=(Point2LL& p0, const Point2LL& p1) { p0.X -= p1.X; @@ -111,6 +120,7 @@ INLINE coord_t vSize2(const Point2LL& p0) { return p0.X * p0.X + p0.Y * p0.Y; } + INLINE double vSize2f(const Point2LL& p0) { return static_cast(p0.X) * static_cast(p0.X) + static_cast(p0.Y) * static_cast(p0.Y); @@ -146,14 +156,14 @@ INLINE double vSizeMM(const Point2LL& p0) return sqrt(fx * fx + fy * fy); } -INLINE Point2LL normal(const Point2LL& p0, coord_t len) +INLINE Point2LL normal(const Point2LL& p0, coord_t length) { - coord_t _len{ vSize(p0) }; - if (_len < 1) + coord_t len{ vSize(p0) }; + if (len < 1) { - return { len, 0 }; + return { length, 0 }; } - return p0 * len / _len; + return p0 * length / len; } INLINE Point2LL turn90CCW(const Point2LL& p0) diff --git a/include/geometry/Point3LL.h b/include/geometry/Point3LL.h index 9dfb91c544..fd220b05ef 100644 --- a/include/geometry/Point3LL.h +++ b/include/geometry/Point3LL.h @@ -11,6 +11,7 @@ #include // for operations on any arithmetic number type #include "utils/Coord_t.h" +#include "utils/types/generic.h" namespace cura @@ -19,10 +20,12 @@ namespace cura class Point3LL { public: - coord_t x_, y_, z_; - Point3LL() - { - } + coord_t x_{}; + coord_t y_{}; + coord_t z_{}; + + Point3LL() = default; + Point3LL(const coord_t x, const coord_t y, const coord_t z) : x_(x) , y_(y) @@ -30,41 +33,53 @@ class Point3LL { } + Point3LL(Point3LL&& point) = default; + Point3LL(const Point3LL& point) = default; + Point3LL& operator=(const Point3LL& point) = default; + Point3LL& operator=(Point3LL&& point) = default; + + virtual ~Point3LL() = default; + Point3LL operator+(const Point3LL& p) const; Point3LL operator-() const; Point3LL operator-(const Point3LL& p) const; Point3LL operator*(const Point3LL& p) const; //!< Element-wise multiplication. For dot product, use .dot()! Point3LL operator/(const Point3LL& p) const; - template::value, num_t>::type> - Point3LL operator*(const num_t i) const + + template + Point3LL operator*(const T& i) const { - return Point3LL(std::llround(static_cast(x_) * i), std::llround(static_cast(y_) * i), std::llround(static_cast(z_) * i)); + return { std::llround(static_cast(x_) * i), std::llround(static_cast(y_) * i), std::llround(static_cast(z_) * i) }; } - template::value, num_t>::type> - Point3LL operator/(const num_t i) const + + template + Point3LL operator/(const T& i) const { - return Point3LL(x_ / i, y_ / i, z_ / i); + return { x_ / i, y_ / i, z_ / i }; } - template::value, num_t>::type> - Point3LL operator%(const num_t i) const + + template + Point3LL operator%(const T& i) const { - return Point3LL(x_ % i, y_ % i, z_ % i); + return { x_ % i, y_ % i, z_ % i }; } Point3LL& operator+=(const Point3LL& p); Point3LL& operator-=(const Point3LL& p); Point3LL& operator*=(const Point3LL& p); Point3LL& operator/=(const Point3LL& p); - template::value, num_t>::type> - Point3LL& operator*=(const num_t i) + + template + Point3LL& operator*=(const T i) { x_ *= i; y_ *= i; z_ *= i; return *this; } - template::value, num_t>::type> - Point3LL& operator/=(const num_t i) + + template + Point3LL& operator/=(const T i) { x_ /= i; y_ /= i; @@ -72,9 +87,7 @@ class Point3LL return *this; } - bool operator==(const Point3LL& p) const; - bool operator!=(const Point3LL& p) const; - + auto operator<=>(const Point3LL&) const = default; template friend std::basic_ostream& operator<<(std::basic_ostream& os, const Point3LL& p) @@ -82,38 +95,47 @@ class Point3LL return os << "(" << p.x_ << ", " << p.y_ << ", " << p.z_ << ")"; } - - coord_t max() const + [[nodiscard]] coord_t max() const { if (x_ > y_ && x_ > z_) + { return x_; + } if (y_ > z_) + { return y_; + } return z_; } - bool testLength(coord_t len) const + [[nodiscard]] bool testLength(coord_t len) const { if (x_ > len || x_ < -len) + { return false; + } if (y_ > len || y_ < -len) + { return false; + } if (z_ > len || z_ < -len) + { return false; + } return vSize2() <= len * len; } - coord_t vSize2() const + [[nodiscard]] coord_t vSize2() const { return x_ * x_ + y_ * y_ + z_ * z_; } - coord_t vSize() const + [[nodiscard]] coord_t vSize() const { return std::llrint(sqrt(static_cast(vSize2()))); } - double vSizeMM() const + [[nodiscard]] double vSizeMM() const { double fx = INT2MM(x_); double fy = INT2MM(y_); @@ -121,7 +143,7 @@ class Point3LL return sqrt(fx * fx + fy * fy + fz * fz); } - coord_t dot(const Point3LL& p) const + [[nodiscard]] coord_t dot(const Point3LL& p) const { return x_ * p.x_ + y_ * p.y_ + z_ * p.z_; } @@ -152,8 +174,8 @@ class Point3LL */ static Point3LL no_point3(std::numeric_limits::min(), std::numeric_limits::min(), std::numeric_limits::min()); -template::value, num_t>::type> -inline Point3LL operator*(const num_t i, const Point3LL& rhs) +template +inline Point3LL operator*(const T i, const Point3LL& rhs) { return rhs * i; } @@ -166,7 +188,7 @@ namespace std template<> struct hash { - size_t operator()(const cura::Point3LL& pp) const + size_t operator()(const cura::Point3LL& pp) const noexcept { static int prime = 31; int result = 89; diff --git a/include/geometry/PointsSet.h b/include/geometry/PointsSet.h index f530613ba1..f61329929d 100644 --- a/include/geometry/PointsSet.h +++ b/include/geometry/PointsSet.h @@ -27,9 +27,12 @@ class PointsSet public: // Required for some std calls as a container - typedef Point2LL value_type; + using value_type = Point2LL; + using iterator = typename std::vector::iterator; + using const_iterator = typename std::vector::const_iterator; + using reverse_iterator = typename std::vector::reverse_iterator; + using const_reverse_iterator = typename std::vector::const_reverse_iterator; -public: /*! \brief Builds an empty set */ PointsSet() = default; @@ -42,13 +45,15 @@ class PointsSet /*! \brief Constructor with a points initializer list, provided for convenience" */ PointsSet(const std::initializer_list& initializer); + virtual ~PointsSet() = default; + /*! \brief Constructor with an existing list of points */ - PointsSet(const ClipperLib::Path& points); + explicit PointsSet(const ClipperLib::Path& points); /*! \brief Constructor that takes ownership of the given list of points */ - PointsSet(ClipperLib::Path&& points); + explicit PointsSet(ClipperLib::Path&& points); - const ClipperLib::Path& getPoints() const + [[nodiscard]] const ClipperLib::Path& getPoints() const { return points_; } @@ -63,7 +68,7 @@ class PointsSet points_ = points; } - size_t size() const + [[nodiscard]] size_t size() const { return points_.size(); } @@ -73,10 +78,9 @@ class PointsSet points_.push_back(point); } - template - void emplace_back(Args&&... args) + void emplace_back(auto&&... args) { - points_.emplace_back(args...); + points_.emplace_back(std::forward(args)...); } void pop_back() @@ -84,53 +88,52 @@ class PointsSet points_.pop_back(); } - template - void insert(Args&&... args) + void insert(auto&&... args) { - points_.insert(args...); + points_.insert(std::forward(args)...); } - std::vector::const_iterator begin() const + [[nodiscard]] const_iterator begin() const { return points_.begin(); } - std::vector::iterator begin() + iterator begin() { return points_.begin(); } - std::vector::const_iterator end() const + [[nodiscard]] const_iterator end() const { return points_.end(); } - std::vector::iterator end() + iterator end() { return points_.end(); } - std::vector::const_reverse_iterator rbegin() const + [[nodiscard]] const_reverse_iterator rbegin() const { return points_.rbegin(); } - std::vector::reverse_iterator rbegin() + reverse_iterator rbegin() { return points_.rbegin(); } - std::vector::const_reverse_iterator rend() const + [[nodiscard]] const_reverse_iterator rend() const { return points_.rend(); } - std::vector::reverse_iterator rend() + reverse_iterator rend() { return points_.rend(); } - const Point2LL& front() const + [[nodiscard]] const Point2LL& front() const { return points_.front(); } @@ -140,7 +143,7 @@ class PointsSet return points_.front(); } - const Point2LL& back() const + [[nodiscard]] const Point2LL& back() const { return points_.back(); } @@ -150,27 +153,27 @@ class PointsSet return points_.back(); } - const Point2LL& at(size_t pos) const + [[nodiscard]] const Point2LL& at(const size_t pos) const { return points_.at(pos); } - Point2LL& at(size_t pos) + Point2LL& at(const size_t pos) { return points_.at(pos); } - bool empty() const + [[nodiscard]] bool empty() const { return points_.empty(); } - void resize(size_t size) + void resize(const size_t size) { points_.resize(size); } - void reserve(size_t size) + void reserve(const size_t size) { points_.reserve(size); } diff --git a/include/geometry/Polygon.h b/include/geometry/Polygon.h index fa2af370e9..ddb6025794 100644 --- a/include/geometry/Polygon.h +++ b/include/geometry/Polygon.h @@ -21,6 +21,8 @@ class AngleDegrees; class Polygon : public ClosedPolyline { public: + Polygon() = default; + /*! * \brief Builds an empty polygon * \param explicitely_closed Indicates whether the contour line will be explicitely closed @@ -28,8 +30,8 @@ class Polygon : public ClosedPolyline * constructor in various places, but be careful that the interpretation of the points * added later will depend on this. */ - Polygon(bool explicitely_closed = false) - : ClosedPolyline(explicitely_closed) + explicit Polygon(const bool explicitely_closed) + : ClosedPolyline{ explicitely_closed } { } @@ -43,8 +45,8 @@ class Polygon : public ClosedPolyline * \brief Constructor with a points initializer list, provided for convenience * \param explicitely_closed Specify whether the given points form an explicitely closed line */ - Polygon(const std::initializer_list& initializer, bool explicitely_closed) - : ClosedPolyline(initializer, explicitely_closed) + Polygon(const std::initializer_list& initializer, const bool explicitely_closed) + : ClosedPolyline{ initializer, explicitely_closed } { } @@ -52,8 +54,8 @@ class Polygon : public ClosedPolyline * \brief Constructor with an existing list of points * \param explicitely_closed Specify whether the given points form an explicitely closed line */ - explicit Polygon(const ClipperLib::Path& points, bool explicitely_closed) - : ClosedPolyline(points, explicitely_closed) + explicit Polygon(const ClipperLib::Path& points, const bool explicitely_closed) + : ClosedPolyline{ points, explicitely_closed } { } @@ -61,22 +63,16 @@ class Polygon : public ClosedPolyline * \brief Constructor that takes ownership of the given list of points * \param explicitely_closed Specify whether the given points form an explicitely closed line */ - explicit Polygon(ClipperLib::Path&& points, bool explicitely_closed) - : ClosedPolyline(points, explicitely_closed) + explicit Polygon(ClipperLib::Path&& points, const bool explicitely_closed) + : ClosedPolyline{ std::move(points), explicitely_closed } { } - Polygon& operator=(const Polygon& other) - { - Polyline::operator=(other); - return *this; - } + ~Polygon() override = default; - Polygon& operator=(Polygon&& other) - { - Polyline::operator=(std::move(other)); - return *this; - } + Polygon& operator=(const Polygon& other) = default; + + Polygon& operator=(Polygon&& other) = default; /*! * \brief Compute the morphological intersection between this polygon and another. diff --git a/src/geometry/ClosedPolyline.cpp b/src/geometry/ClosedPolyline.cpp index 0f7ab7e142..c4890c48f1 100644 --- a/src/geometry/ClosedPolyline.cpp +++ b/src/geometry/ClosedPolyline.cpp @@ -3,6 +3,8 @@ #include "geometry/ClosedPolyline.h" +#include + #include "geometry/OpenPolyline.h" namespace cura @@ -14,10 +16,7 @@ size_t ClosedPolyline::segmentsCount() const { return size() >= 3 ? size() - 1 : 0; } - else - { - return size() >= 2 ? size() : 0; - } + return size() >= 2 ? size() : 0; } bool ClosedPolyline::isValid() const @@ -37,14 +36,12 @@ bool ClosedPolyline::inside(const Point2LL& p, bool border_result) const bool ClosedPolyline::inside(const ClipperLib::Path& polygon) const { - for (const auto& point : *this) - { - if (! ClipperLib::PointInPolygon(point, polygon)) + return ranges::all_of( + *this, + [&polygon](const auto& point) { - return false; - } - } - return true; + return ClipperLib::PointInPolygon(point, polygon); + }); } OpenPolyline ClosedPolyline::toPseudoOpenPolyline() const diff --git a/src/geometry/MixedLinesSet.cpp b/src/geometry/MixedLinesSet.cpp index d4923c3778..c080becf41 100644 --- a/src/geometry/MixedLinesSet.cpp +++ b/src/geometry/MixedLinesSet.cpp @@ -30,55 +30,47 @@ Shape MixedLinesSet::offset(coord_t distance, ClipperLib::JoinType join_type, do return result; } - else - { - Shape polygons; - ClipperLib::ClipperOffset clipper(miter_limit, 10.0); + Shape polygons; + ClipperLib::ClipperOffset clipper(miter_limit, 10.0); - for (const PolylinePtr& line : (*this)) + for (const PolylinePtr& line : (*this)) + { + if (const std::shared_ptr polygon = dynamic_pointer_cast(line)) { - if (const std::shared_ptr polygon = dynamic_pointer_cast(line)) - { - // Union all polygons first and add them later - polygons.push_back(*polygon); - } - else + // Union all polygons first and add them later + polygons.push_back(*polygon); + } + else + { + static auto end_type_fn = [&line, &join_type]() { - ClipperLib::EndType end_type; - if (line->hasClosingSegment()) { - end_type = ClipperLib::etClosedLine; - } - else if (join_type == ClipperLib::jtMiter) - { - end_type = ClipperLib::etOpenSquare; - } - else - { - end_type = ClipperLib::etOpenRound; + return ClipperLib::etClosedLine; } + return join_type == ClipperLib::jtMiter ? ClipperLib::etOpenSquare : ClipperLib::etOpenRound; + }; - clipper.AddPath(line->getPoints(), join_type, end_type); - } + const ClipperLib::EndType end_type{ end_type_fn() }; + clipper.AddPath(line->getPoints(), join_type, end_type); } + } - if (! polygons.empty()) - { - polygons = polygons.unionPolygons(); + if (! polygons.empty()) + { + polygons = polygons.unionPolygons(); - for (const Polygon& polygon : polygons) - { - clipper.AddPath(polygon.getPoints(), join_type, ClipperLib::etClosedPolygon); - } + for (const Polygon& polygon : polygons) + { + clipper.AddPath(polygon.getPoints(), join_type, ClipperLib::etClosedPolygon); } + } - clipper.MiterLimit = miter_limit; + clipper.MiterLimit = miter_limit; - ClipperLib::Paths result; - clipper.Execute(result, static_cast(distance)); - return Shape(std::move(result)); - } + ClipperLib::Paths result; + clipper.Execute(result, static_cast(distance)); + return Shape{ std::move(result) }; } void MixedLinesSet::push_back(const OpenPolyline& line) @@ -98,7 +90,7 @@ void MixedLinesSet::push_back(ClosedPolyline&& line) void MixedLinesSet::push_back(const Polygon& line) { - std::vector::push_back(std::make_shared(std::move(line))); + std::vector::push_back(std::make_shared(line)); } void MixedLinesSet::push_back(const std::shared_ptr& line) @@ -157,7 +149,7 @@ coord_t MixedLinesSet::length() const return std::accumulate( begin(), end(), - coord_t(0), + 0LL, [](coord_t value, const PolylinePtr& line) { return value + line->length(); diff --git a/src/infill/GyroidInfill.cpp b/src/infill/GyroidInfill.cpp index 59f85fbdf5..c085840a21 100644 --- a/src/infill/GyroidInfill.cpp +++ b/src/infill/GyroidInfill.cpp @@ -344,7 +344,7 @@ void GyroidInfill::generateTotalGyroidInfill(OpenLinesSet& result_lines, bool zi if (chain_index != connector_start_chain_index && connected_to[(point_index + 1) % 2][chain_index] != connector_start_chain_index) { - result.push_back(connector_points); + result.push_back(OpenPolyline{ connector_points }); drawing = false; connector_points.clear(); // remember the connection @@ -393,9 +393,9 @@ void GyroidInfill::generateTotalGyroidInfill(OpenLinesSet& result_lines, bool zi { // output the connector line segments from the last chain to the first point in the outline connector_points.push_back(outline_poly[0]); - result.push_back(connector_points); + result.push_back(OpenPolyline{ connector_points }); // output the connector line segments from the first point in the outline to the first chain - result.push_back(path_to_first_chain); + result.push_back(OpenPolyline{ path_to_first_chain }); } if (chain_ends_remaining < 1) diff --git a/src/utils/Point3LL.cpp b/src/utils/Point3LL.cpp index d12b31414f..bb8e7c6930 100644 --- a/src/utils/Point3LL.cpp +++ b/src/utils/Point3LL.cpp @@ -63,14 +63,4 @@ Point3LL& Point3LL::operator/=(const Point3LL& p) return *this; } -bool Point3LL::operator==(const Point3LL& p) const -{ - return x_ == p.x_ && y_ == p.y_ && z_ == p.z_; -} - -bool Point3LL::operator!=(const Point3LL& p) const -{ - return x_ != p.x_ || y_ != p.y_ || z_ != p.z_; -} - } // namespace cura