Skip to content

Commit

Permalink
Include numbers
Browse files Browse the repository at this point in the history
Contributes to CURA-9830
  • Loading branch information
jellespijker committed May 2, 2024
1 parent 5a2c243 commit 0ce98e6
Show file tree
Hide file tree
Showing 30 changed files with 175 additions and 155 deletions.
11 changes: 5 additions & 6 deletions include/BeadingStrategy/BeadingStrategy.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Copyright (c) 2022 Ultimaker B.V.
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher

#ifndef BEADING_STRATEGY_H
#define BEADING_STRATEGY_H

#include <memory>
#include <numbers>

#include "../settings/types/Angle.h"
#include "../settings/types/Ratio.h" //For the wall transition threshold.
#include "geometry/Point2LL.h"
#include "settings/types/Angle.h"
#include "settings/types/Ratio.h" //For the wall transition threshold.

namespace cura
{
Expand Down Expand Up @@ -45,9 +46,7 @@ class BeadingStrategy

BeadingStrategy(const BeadingStrategy& other);

virtual ~BeadingStrategy()
{
}
virtual ~BeadingStrategy() = default;

/*!
* Retrieve the bead widths with which to cover a given thickness.
Expand Down
6 changes: 4 additions & 2 deletions include/BeadingStrategy/BeadingStrategyFactory.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) 2022 Ultimaker B.V.
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef BEADING_STRATEGY_FACTORY_H
#define BEADING_STRATEGY_FACTORY_H

#include "../settings/types/Ratio.h"
#include <numbers>

#include "BeadingStrategy.h"
#include "settings/types/Ratio.h"

namespace cura
{
Expand Down
11 changes: 4 additions & 7 deletions include/PathOrderOptimizer.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) 2023 UltiMaker
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher

#ifndef PATHORDEROPTIMIZER_H
#define PATHORDEROPTIMIZER_H

#include <numbers>
#include <unordered_set>

#include <range/v3/algorithm/partition_copy.hpp>
Expand All @@ -15,7 +16,6 @@
#include <range/v3/view/reverse.hpp>
#include <spdlog/spdlog.h>

#include "InsetOrderOptimizer.h" // for makeOrderIncludeTransitive
#include "pathPlanning/CombPath.h" //To calculate the combing distance if we want to use combing.
#include "pathPlanning/LinePolygonsCrossings.h" //To prevent calculating combing distances if we don't cross the combing borders.
#include "path_ordering.h"
Expand Down Expand Up @@ -402,7 +402,7 @@ class PathOrderOptimizer
}

auto local_current_position = current_position;
while (candidates.size() != 0)
while (!candidates.empty())
{
Path best_candidate = findClosestPathVertices(local_current_position, candidates);

Expand Down Expand Up @@ -633,10 +633,7 @@ class PathOrderOptimizer
{
return path.converted_->size() - 1; // Back end is closer.
}
else
{
return 0; // Front end is closer.
}
return 0; // Front end is closer.
}

// Rest of the function only deals with (closed) polygons. We need to be able to find the seam location of those polygons.
Expand Down
2 changes: 2 additions & 0 deletions include/TreeSupportSettings.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef TREESUPPORTSETTINGS_H
Expand All @@ -13,6 +14,7 @@
#include "settings/types/Ratio.h"
#include "utils/Coord_t.h"
#include "utils/Simplify.h"
#include "utils/math.h"


namespace cura
Expand Down
46 changes: 24 additions & 22 deletions include/geometry/Point2LL.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 Ultimaker B.V.
// Copyright (c) 2024 UltiMaker
// CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef UTILS_INT_POINT_H
Expand All @@ -10,11 +10,9 @@ Integer points are used to avoid floating point rounding errors, and because Cli
*/
#define INLINE static inline

//#include <functional> // for hash function object
//#include <iostream> // auto-serialization / auto-toString()
#include <limits>
#include <numbers>
#include <polyclipping/clipper.hpp>
//#include <stdint.h>

#include "geometry/Point3LL.h"

Expand Down Expand Up @@ -42,24 +40,24 @@ static Point2LL no_point(std::numeric_limits<ClipperLib::cInt>::min(), std::nume
/* Extra operators to make it easier to do math with the 64bit Point objects */
INLINE Point2LL operator-(const Point2LL& p0)
{
return Point2LL(-p0.X, -p0.Y);
return { -p0.X, -p0.Y };
}
INLINE Point2LL operator+(const Point2LL& p0, const Point2LL& p1)
{
return Point2LL(p0.X + p1.X, p0.Y + p1.Y);
return { p0.X + p1.X, p0.Y + p1.Y };
}
INLINE Point2LL operator-(const Point2LL& p0, const Point2LL& p1)
{
return Point2LL(p0.X - p1.X, p0.Y - p1.Y);
return { p0.X - p1.X, p0.Y - p1.Y };
}
INLINE Point2LL operator*(const Point2LL& p0, const coord_t i)
{
return Point2LL(p0.X * i, p0.Y * i);
return { p0.X * i, p0.Y * i };
}
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> // Use only for numeric types.
INLINE Point2LL operator*(const Point2LL& p0, const T i)
{
return Point2LL(std::llrint(static_cast<T>(p0.X) * i), std::llrint(static_cast<T>(p0.Y) * i));
return { std::llrint(static_cast<T>(p0.X) * i), std::llrint(static_cast<T>(p0.Y) * i) };
}
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> // Use only for numeric types.
INLINE Point2LL operator*(const T i, const Point2LL& p0)
Expand All @@ -68,15 +66,15 @@ INLINE Point2LL operator*(const T i, const Point2LL& p0)
}
INLINE Point2LL operator/(const Point2LL& p0, const coord_t i)
{
return Point2LL(p0.X / i, p0.Y / i);
return { p0.X / i, p0.Y / i };
}
INLINE Point2LL operator/(const Point2LL& p0, const Point2LL& p1)
{
return Point2LL(p0.X / p1.X, p0.Y / p1.Y);
return { p0.X / p1.X, p0.Y / p1.Y };
}
INLINE Point2LL operator%(const Point2LL& p0, const coord_t i)
{
return Point2LL(p0.X % i, p0.Y % i);
return { p0.X % i, p0.Y % i };
}

INLINE Point2LL& operator+=(Point2LL& p0, const Point2LL& p1)
Expand Down Expand Up @@ -150,24 +148,26 @@ INLINE double vSizeMM(const Point2LL& p0)

INLINE Point2LL normal(const Point2LL& p0, coord_t len)
{
coord_t _len = vSize(p0);
coord_t _len { vSize(p0) };
if (_len < 1)
return Point2LL(len, 0);
{
return { len, 0 };
}
return p0 * len / _len;
}

INLINE Point2LL turn90CCW(const Point2LL& p0)
{
return Point2LL(-p0.Y, p0.X);
return { -p0.Y, p0.X };
}

INLINE Point2LL rotate(const Point2LL& p0, double angle)
{
const double cos_component = std::cos(angle);
const double sin_component = std::sin(angle);
const double x = static_cast<double>(p0.X);
const double y = static_cast<double>(p0.Y);
return Point2LL(std::llrint(cos_component * x - sin_component * y), std::llrint(sin_component * x + cos_component * y));
const auto x = static_cast<double>(p0.X);
const auto y = static_cast<double>(p0.Y);
return { std::llrint(cos_component * x - sin_component * y), std::llrint(sin_component * x + cos_component * y) };
}

INLINE coord_t dot(const Point2LL& p0, const Point2LL& p1)
Expand All @@ -184,7 +184,9 @@ INLINE double angle(const Point2LL& p)
{
double angle = std::atan2(p.X, p.Y) / std::numbers::pi * 180.0;
if (angle < 0.0)
{
angle += 360.0;
}
return angle;
}

Expand All @@ -196,7 +198,7 @@ INLINE const Point2LL& make_point(const Point2LL& p)

inline Point3LL operator+(const Point3LL& p3, const Point2LL& p2)
{
return Point3LL(p3.x_ + p2.X, p3.y_ + p2.Y, p3.z_);
return { p3.x_ + p2.X, p3.y_ + p2.Y, p3.z_ };
}
inline Point3LL& operator+=(Point3LL& p3, const Point2LL& p2)
{
Expand All @@ -207,13 +209,13 @@ inline Point3LL& operator+=(Point3LL& p3, const Point2LL& p2)

inline Point2LL operator+(const Point2LL& p2, const Point3LL& p3)
{
return Point2LL(p3.x_ + p2.X, p3.y_ + p2.Y);
return { p3.x_ + p2.X, p3.y_ + p2.Y };
}


inline Point3LL operator-(const Point3LL& p3, const Point2LL& p2)
{
return Point3LL(p3.x_ - p2.X, p3.y_ - p2.Y, p3.z_);
return { p3.x_ - p2.X, p3.y_ - p2.Y, p3.z_ };
}
inline Point3LL& operator-=(Point3LL& p3, const Point2LL& p2)
{
Expand All @@ -224,7 +226,7 @@ inline Point3LL& operator-=(Point3LL& p3, const Point2LL& p2)

inline Point2LL operator-(const Point2LL& p2, const Point3LL& p3)
{
return Point2LL(p2.X - p3.x_, p2.Y - p3.y_);
return { p2.X - p3.x_, p2.Y - p3.y_ };
}

} // namespace cura
Expand Down
27 changes: 15 additions & 12 deletions include/geometry/PointMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#ifndef GEOMETRY_POINT_MATRIX_H
#define GEOMETRY_POINT_MATRIX_H

#include <array>
#include <numbers>

#include "geometry/Point2LL.h"


Expand All @@ -13,7 +16,7 @@ namespace cura
class PointMatrix
{
public:
double matrix[4];
std::array<double, 4> matrix{};

PointMatrix()
{
Expand All @@ -23,7 +26,7 @@ class PointMatrix
matrix[3] = 1;
}

PointMatrix(double rotation)
explicit PointMatrix(double rotation)
{
rotation = rotation / 180 * std::numbers::pi;
matrix[0] = cos(rotation);
Expand All @@ -32,7 +35,7 @@ class PointMatrix
matrix[3] = matrix[0];
}

PointMatrix(const Point2LL& p)
explicit PointMatrix(const Point2LL& p)
{
matrix[0] = static_cast<double>(p.X);
matrix[1] = static_cast<double>(p.Y);
Expand All @@ -51,24 +54,24 @@ class PointMatrix
return ret;
}

Point2LL apply(const Point2LL& p) const
[[nodiscard]] Point2LL apply(const Point2LL& p) const
{
const double x = static_cast<double>(p.X);
const double y = static_cast<double>(p.Y);
return Point2LL(std::llrint(x * matrix[0] + y * matrix[1]), std::llrint(x * matrix[2] + y * matrix[3]));
const auto x = static_cast<double>(p.X);
const auto y = static_cast<double>(p.Y);
return { std::llrint(x * matrix[0] + y * matrix[1]), std::llrint(x * matrix[2] + y * matrix[3]) };
}

/*!
* \warning only works on a rotation matrix! Output is incorrect for other types of matrix
*/
Point2LL unapply(const Point2LL& p) const
[[nodiscard]] Point2LL unapply(const Point2LL& p) const
{
const double x = static_cast<double>(p.X);
const double y = static_cast<double>(p.Y);
return Point2LL(std::llrint(x * matrix[0] + y * matrix[2]), std::llrint(x * matrix[1] + y * matrix[3]));
const auto x = static_cast<double>(p.X);
const auto y = static_cast<double>(p.Y);
return { std::llrint(x * matrix[0] + y * matrix[2]), std::llrint(x * matrix[1] + y * matrix[3]) };
}

PointMatrix inverse() const
[[nodiscard]] PointMatrix inverse() const
{
PointMatrix ret;
double det = matrix[0] * matrix[3] - matrix[1] * matrix[2];
Expand Down
Loading

0 comments on commit 0ce98e6

Please sign in to comment.