From 1aedc2a041ffa02137995cfb8bc6f2f88735fee2 Mon Sep 17 00:00:00 2001 From: Pascal <engelerp@phys.ethz.ch> Date: Wed, 26 Jul 2023 17:56:01 +0200 Subject: [PATCH] Fixed bug where several attachment modes are possible --- data_generation/cpp/src/linestrip.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/data_generation/cpp/src/linestrip.cpp b/data_generation/cpp/src/linestrip.cpp index 1884a49..93abd36 100644 --- a/data_generation/cpp/src/linestrip.cpp +++ b/data_generation/cpp/src/linestrip.cpp @@ -1,5 +1,8 @@ #include <linestrip.hpp> #include <algorithm> +#ifndef NDEBUG +#include <iostream> +#endif bool isEqual(const double x, const double y, const double tol=1e-8){ return (x - y < tol) && (y - x < tol); @@ -15,6 +18,16 @@ void reverseNodes(std::vector<double>& nodes){ LineStrip::LineStrip(std::vector<double> nodes): _nodes(nodes), _isClosed(false), _isActive(true) {} void LineStrip::attach(LineStrip& other, int mode){ + #ifndef NDEBUG + std::cout << "ATTACH\n"; + std::cout << "Mode: " << mode << std::endl; + std::cout << "This: (" << _nodes[0] << ", " << _nodes[1] << ") ... (" << _nodes[_nodes.size()-2] << ", " << _nodes[_nodes.size()-1] << ")\n"; + std::cout << "Other: "; + for(int i = 0; i < other._nodes.size()/2; i+=2){ + std::cout << "(" << other._nodes[2*i] << ", " << other._nodes[2*i+1] << "), "; + } + std::cout << std::endl << std::endl; + #endif if(mode == 1){ //normal attach _nodes.reserve(_nodes.size() + other._nodes.size()); //reserve _nodes.insert(_nodes.end(), other._nodes.begin()+2, other._nodes.end()); @@ -57,7 +70,12 @@ int LineStrip::canBeAttached(const LineStrip& other) const { bool endToEndAttach = isEqual(other._nodes[other._nodes.size()-2], _nodes[_nodes.size()-2]) && isEqual(other._nodes[other._nodes.size()-1],_nodes[_nodes.size()-1]); bool startToStartAttach = isEqual(other._nodes[0], _nodes[0]) && isEqual(other._nodes[1],_nodes[1]); - return normalAttach + 2*reverseAttach + 3*endToEndAttach + 4*startToStartAttach; + if(normalAttach && reverseAttach){ + return normalAttach; + } + else{ + return normalAttach + 2*reverseAttach + 3*endToEndAttach + 4*startToStartAttach; + } } bool LineStrip::isActive() const { -- GitLab