Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/CuraEngine.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelle Spijker <j.spijker@ultimaker.com>2022-11-04 23:49:24 +0300
committerJelle Spijker <spijker.jelle@gmail.com>2022-11-04 23:49:24 +0300
commit23d868b3676947a86080b83f77489fc1b199badf (patch)
tree7b2a329454d41c543d2982dabc7096547dc07d58
parent89451982396c8f2bd9326284b8ffb443c37c7816 (diff)
Initial setup of Polygon rewrite
Just me playing around, might make it in, might not.
-rw-r--r--CMakeLists.txt10
-rw-r--r--conandata.yml2
-rw-r--r--include/polygon/Point.h31
-rw-r--r--include/polygon/Polygon.h6
-rw-r--r--include/polygon/Unit.h18
-rw-r--r--include/utils/concepts/Polygon.h30
-rw-r--r--src/polygon/Point.cpp28
-rw-r--r--tests/CMakeLists.txt10
-rw-r--r--tests/polygon/PointTest.cpp40
9 files changed, 173 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f87dcbc80..4cbb3c0e2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -137,6 +137,8 @@ set(engine_SRCS # Except main.cpp.
src/utils/ThreadPool.cpp
src/utils/ToolpathVisualizer.cpp
src/utils/VoronoiUtils.cpp
+
+ src/polygon/Point.cpp
)
add_library(_CuraEngine STATIC ${engine_SRCS} ${engine_PB_SRCS})
@@ -180,12 +182,14 @@ if (ENABLE_ARCUS)
endif ()
find_package(clipper REQUIRED)
-find_package(RapidJSON REQUIRED)
+find_package(rapidjson REQUIRED)
find_package(stb REQUIRED)
find_package(Boost REQUIRED)
find_package(spdlog REQUIRED)
find_package(fmt REQUIRED)
find_package(range-v3 REQUIRED)
+find_package(mp-units REQUIRED)
+find_package(gsl-lite REQUIRED)
if (ENABLE_TESTING)
find_package(GTest REQUIRED)
@@ -194,13 +198,15 @@ endif ()
target_link_libraries(_CuraEngine
PUBLIC
spdlog::spdlog
+ mp-units::mp-units
PRIVATE
range-v3::range-v3
fmt::fmt
clipper::clipper
- rapidjson
+ rapidjson::rapidjson
stb::stb
boost::boost
+ gsl::gsl-lite
$<$<BOOL:${ENABLE_TESTING}>:GTest::gtest>)
if (NOT WIN32)
diff --git a/conandata.yml b/conandata.yml
index 0387dde2e..a3bf356c3 100644
--- a/conandata.yml
+++ b/conandata.yml
@@ -7,6 +7,8 @@
- "spdlog/1.10.0"
- "fmt/9.0.0"
- "range-v3/0.12.0"
+ - "mp-units/0.7.0"
+ - "gsl-lite/0.38.0"
requirements_arcus:
- "protobuf/3.21.4"
- "arcus/(latest)@ultimaker/testing"
diff --git a/include/polygon/Point.h b/include/polygon/Point.h
new file mode 100644
index 000000000..6e9c8b2f0
--- /dev/null
+++ b/include/polygon/Point.h
@@ -0,0 +1,31 @@
+
+
+#ifndef CURAENGINE_POINT_H
+#define CURAENGINE_POINT_H
+
+#include <array>
+
+#include "polygon/Unit.h"
+#include "utils/concepts/Polygon.h"
+
+namespace cura::poly
+{
+
+template<class Tp, std::size_t Nm = 2>
+class Point : public std::array<Tp, Nm>
+{
+public:
+ constexpr Point<Tp, Nm> operator+(const Vector auto& other) const;
+ constexpr Point<Tp, Nm> operator+(const Scalar auto& magnitude) const;
+};
+
+template<Scalar Tp, std::size_t Nm = 2>
+using Position = Point<units::isq::si::length<unit::base_length, Tp>, Nm>;
+
+// CTAD
+template<Scalar T, Scalar... U>
+Point(T, U...) -> Point<T, 1 + sizeof...(U)>;
+
+} // namespace cura::poly
+
+#endif // CURAENGINE_POINT_H
diff --git a/include/polygon/Polygon.h b/include/polygon/Polygon.h
new file mode 100644
index 000000000..df4fbf4f2
--- /dev/null
+++ b/include/polygon/Polygon.h
@@ -0,0 +1,6 @@
+
+
+#ifndef CURAENGINE_POLYGON_H
+#define CURAENGINE_POLYGON_H
+
+#endif // CURAENGINE_POLYGON_H
diff --git a/include/polygon/Unit.h b/include/polygon/Unit.h
new file mode 100644
index 000000000..3d2ba12b2
--- /dev/null
+++ b/include/polygon/Unit.h
@@ -0,0 +1,18 @@
+
+
+#ifndef CURAENGINE_UNIT_H
+#define CURAENGINE_UNIT_H
+
+#include <units/isq/si/length.h>
+#include <units/isq/si/time.h>
+
+namespace u = units::isq::si::references;
+
+namespace cura::unit
+{
+using base_length = units::isq::si::micrometre; // The base length unit, use a different prefix for more or less precision
+
+}
+
+
+#endif // CURAENGINE_UNIT_H
diff --git a/include/utils/concepts/Polygon.h b/include/utils/concepts/Polygon.h
new file mode 100644
index 000000000..0109a5d01
--- /dev/null
+++ b/include/utils/concepts/Polygon.h
@@ -0,0 +1,30 @@
+
+
+#ifndef CURAENGINE_POLYGON_H
+#define CURAENGINE_POLYGON_H
+
+#include <concepts>
+#include <cstdint>
+#include <ranges>
+#include <type_traits>
+
+
+namespace cura::poly
+{
+
+template<class T>
+concept Scalar = std::is_integral_v<T> || std::is_integral_v<typename T::rep>;
+
+template<class T>
+concept Vector = std::ranges::range<T> && Scalar<typename T::value_type>;
+
+template<class T, class U>
+concept is_same_rank = requires(T lhs, U rhs)
+{
+ { lhs.size() == rhs.size() };
+};
+
+
+} // namespace cura::poly
+
+#endif // CURAENGINE_POLYGON_H
diff --git a/src/polygon/Point.cpp b/src/polygon/Point.cpp
new file mode 100644
index 000000000..145c2499e
--- /dev/null
+++ b/src/polygon/Point.cpp
@@ -0,0 +1,28 @@
+
+#include <gsl/gsl-lite.hpp>
+#include <range/v3/to_container.hpp>
+#include <range/v3/view/transform.hpp>
+#include <range/v3/view/zip_with.hpp>
+
+#include "polygon/Point.h"
+
+
+namespace cura::poly
+{
+
+template<class Tp, std::size_t Nm>
+constexpr Point<Tp, Nm> Point<Tp, Nm>::operator+(const Vector auto& other) const
+{
+ gsl_Expects(! this->empty() && ! other.empty());
+ return ranges::views::zip_with([](const auto& lhs, const auto& rhs) { return lhs + rhs; }, this, other) | ranges::to<Point<Tp, Nm>>;
+}
+
+template<class Tp, std::size_t Nm>
+constexpr Point<Tp, Nm> Point<Tp, Nm>::operator+(const Scalar auto& magnitude) const
+{
+ gsl_Expects(! this->empty());
+ return ranges::views::transform([magnitude](const auto& lhs) { return lhs + magnitude; }) | ranges::to<Point<Tp, Nm>>;
+}
+
+
+} // namespace cura::poly
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 357ee011a..dd962924f 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -39,6 +39,10 @@ set(TESTS_SRC_UTILS
UnionFindTest
)
+set(TESTS_SRC_POLYGON
+ PointTest
+ )
+
set(TESTS_HELPERS_SRC ReadTestPolygons.cpp)
set(TESTS_SRC_ARCUS)
@@ -63,6 +67,12 @@ foreach (test ${TESTS_SRC_BASE})
target_link_libraries(${test} PRIVATE _CuraEngine test_helpers GTest::gtest GTest::gmock clipper::clipper)
endforeach ()
+foreach (test ${TESTS_SRC_POLYGON})
+ add_executable(${test} main.cpp polygon/${test}.cpp)
+ add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
+ target_link_libraries(${test} PRIVATE _CuraEngine test_helpers GTest::gtest GTest::gmock clipper::clipper)
+endforeach ()
+
foreach (test ${TESTS_SRC_ARCUS})
add_executable(${test} main.cpp arcus/${test}.cpp)
add_test(NAME ${test} COMMAND "${test}" WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
diff --git a/tests/polygon/PointTest.cpp b/tests/polygon/PointTest.cpp
new file mode 100644
index 000000000..9885560bd
--- /dev/null
+++ b/tests/polygon/PointTest.cpp
@@ -0,0 +1,40 @@
+#include <gtest/gtest.h>
+
+
+#include <units/isq/si/length.h>
+
+#include <fmt/format.h>
+
+#include <polygon/Point.h>
+
+
+using namespace cura;
+
+TEST(PointTest, ctad)
+{
+ auto point_2d = poly::Point{ 1LL, 2 };
+ EXPECT_TRUE(point_2d.max_size() == 2);
+ EXPECT_TRUE(sizeof(decltype(point_2d)::value_type) >= sizeof(std::int64_t));
+
+ auto point_3d = poly::Point{ 1, 2, 3 };
+ EXPECT_TRUE(point_3d.max_size() == 3);
+ EXPECT_TRUE(sizeof(decltype(point_2d)::value_type) >= sizeof(int));
+}
+
+TEST(PointTest, units)
+{
+ auto point_1 = poly::Position<std::int64_t, 2>{ 2000 * u::mm, 5 * u::km };
+ auto point_2 = poly::Position<std::int64_t, 2>{ 2 * u::m, 40 * u::um };
+
+ EXPECT_TRUE(point_1.at(0) == point_2.at(0));
+ EXPECT_TRUE(point_1.at(1) > point_2.at(1));
+}
+
+TEST(PointTest, addition)
+{
+ auto point_1 = poly::Position<std::int64_t, 2>{ 2000 * u::mm, 5 * u::km };
+ auto point_2 = poly::Position<std::int64_t, 2>{ 2 * u::m, 40 * u::um };
+
+ auto point_3 = point_1 + point_2;
+ EXPECT_EQ(point_3.at(0), 4 * u::m);
+}