From 3f3de067f88a8eb1a575b41863e48e47c80c6692 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 13 Jul 2018 19:36:01 -0500 Subject: [PATCH] Added epsilon to Slic3r::Geometry; added _equiv for comparing two items that have operator- overloaded. --- src/test/test_data.hpp | 9 +++++++-- xs/src/libslic3r/Geometry.hpp | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/test/test_data.hpp b/src/test/test_data.hpp index de7dbcf64..9edd37629 100644 --- a/src/test/test_data.hpp +++ b/src/test/test_data.hpp @@ -1,6 +1,7 @@ #ifndef SLIC3R_TEST_DATA_HPP #include "Point.hpp" #include "TriangleMesh.hpp" +#include "Geometry.hpp" namespace Slic3r { namespace Test { @@ -24,12 +25,16 @@ enum class TestMesh { two_hollow_squares }; -/// Port of Slic3r::Test::Mesh -/// Basic cubes/boxes should call TriangleMesh::make_cube() directly and rescale it +/// Port of Slic3r::Test::mesh +/// Basic cubes/boxes should call TriangleMesh::make_cube() directly and rescale/translate it TriangleMesh mesh(TestMesh m); TriangleMesh mesh(TestMesh m, Pointf3 translate, Pointf3 scale = Pointf3(1.0, 1.0, 1.0)); +/// Templated function to see if two values are equivalent (+/- epsilon) +template +bool _equiv(T a, U b) { return abs(a - b) < Slic3r::Geometry::epsilon; } + } } // namespace Slic3r::Test #endif // SLIC3R_TEST_DATA_HPP diff --git a/xs/src/libslic3r/Geometry.hpp b/xs/src/libslic3r/Geometry.hpp index 7a4c304f4..a64fdcd5d 100644 --- a/xs/src/libslic3r/Geometry.hpp +++ b/xs/src/libslic3r/Geometry.hpp @@ -25,6 +25,10 @@ double rad2deg(double angle); double rad2deg_dir(double angle); double deg2rad(double angle); +/// Epsilon value +constexpr double epsilon { 1e-4 }; +constexpr coord_t scaled_epsilon { static_cast(epsilon / SCALING_FACTOR) }; + double linint(double value, double oldmin, double oldmax, double newmin, double newmax); bool arrange( // input