From d9cb8919511fbf12431fa5fa7e87e5969353a4da Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 6 Sep 2022 10:54:56 +0200 Subject: [PATCH] Measuring: Rewritten method SurfaceFeature::operator ==() --- src/libslic3r/Measure.hpp | 23 ++++++++++++++++------- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 4 ++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/Measure.hpp b/src/libslic3r/Measure.hpp index 3b811db0c..5d71983f0 100644 --- a/src/libslic3r/Measure.hpp +++ b/src/libslic3r/Measure.hpp @@ -44,19 +44,28 @@ public: std::tuple get_circle() const { assert(m_type == SurfaceFeatureType::Circle); return std::make_tuple(m_pt1, m_value, m_pt2); } // For planes, return index into vector provided by Measuring::get_plane_triangle_indices, normal and point. - std::tuple get_plane() const { return std::make_tuple(int(m_value), m_pt1, m_pt2); } + std::tuple get_plane() const { assert(m_type == SurfaceFeatureType::Plane); return std::make_tuple(int(m_value), m_pt1, m_pt2); } // For anything, return an extra point that should also be considered a part of this. std::optional get_extra_point() const { assert(m_type != SurfaceFeatureType::Undef); return m_pt3; } bool operator == (const SurfaceFeature& other) const { if (this->m_type != other.m_type) return false; - if (!this->m_pt1.isApprox(other.m_pt1)) return false; - if (!this->m_pt2.isApprox(other.m_pt2)) return false; - if (this->m_pt3.has_value() && !other.m_pt3.has_value()) return false; - if (!this->m_pt3.has_value() && other.m_pt3.has_value()) return false; - if (this->m_pt3.has_value() && other.m_pt3.has_value() && !(*this->m_pt3).isApprox(*other.m_pt3)) return false; - return this->m_value == other.m_value; + switch (this->m_type) + { + case SurfaceFeatureType::Undef: { break; } + case SurfaceFeatureType::Point: { return (this->m_pt1.isApprox(other.m_pt1)); } + case SurfaceFeatureType::Edge: { + return (this->m_pt1.isApprox(other.m_pt1) && this->m_pt2.isApprox(other.m_pt2)) || + (this->m_pt1.isApprox(other.m_pt2) && this->m_pt2.isApprox(other.m_pt1)); + } + case SurfaceFeatureType::Plane: + case SurfaceFeatureType::Circle: { + return (this->m_pt1.isApprox(other.m_pt1) && this->m_pt2.isApprox(other.m_pt2) && std::abs(this->m_value - other.m_value) < EPSILON); + } + } + + return false; } bool operator != (const SurfaceFeature& other) const { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index 21e86532a..942a8c93e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -113,7 +113,7 @@ bool GLGizmoMeasure::on_mouse(const wxMouseEvent &mouse_event) auto set_item_from_feature = [this]() { const SelectedFeatures::Item item = { m_mode, (m_mode == EMode::ExtendedSelection) ? point_on_feature_type_as_string(m_curr_feature->get_type(), m_hover_id) : surface_feature_type_as_string(m_curr_feature->get_type()), - (m_mode == EMode::ExtendedSelection) ? Measure::SurfaceFeature(Measure::SurfaceFeatureType::Point, *m_curr_point_on_feature_position, Vec3d::Zero(), std::nullopt, 0.0) : m_curr_feature }; + (m_mode == EMode::ExtendedSelection) ? Measure::SurfaceFeature(*m_curr_point_on_feature_position) : m_curr_feature }; return item; }; @@ -331,7 +331,7 @@ void GLGizmoMeasure::on_render() default: { assert(false); break; } case Measure::SurfaceFeatureType::Point: { - m_curr_point_on_feature_position = model_matrix * m_curr_feature->get_point(); + m_curr_point_on_feature_position = position_on_feature(POINT_ID, camera); break; } case Measure::SurfaceFeatureType::Edge: