Skip to content
Snippets Groups Projects
Commit 1aedc2a0 authored by Pascal Engeler's avatar Pascal Engeler
Browse files

Fixed bug where several attachment modes are possible

parent ed3160bf
No related branches found
No related tags found
No related merge requests found
#include <linestrip.hpp> #include <linestrip.hpp>
#include <algorithm> #include <algorithm>
#ifndef NDEBUG
#include <iostream>
#endif
bool isEqual(const double x, const double y, const double tol=1e-8){ bool isEqual(const double x, const double y, const double tol=1e-8){
return (x - y < tol) && (y - x < tol); return (x - y < tol) && (y - x < tol);
...@@ -15,6 +18,16 @@ void reverseNodes(std::vector<double>& nodes){ ...@@ -15,6 +18,16 @@ void reverseNodes(std::vector<double>& nodes){
LineStrip::LineStrip(std::vector<double> nodes): _nodes(nodes), _isClosed(false), _isActive(true) {} LineStrip::LineStrip(std::vector<double> nodes): _nodes(nodes), _isClosed(false), _isActive(true) {}
void LineStrip::attach(LineStrip& other, int mode){ 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 if(mode == 1){ //normal attach
_nodes.reserve(_nodes.size() + other._nodes.size()); //reserve _nodes.reserve(_nodes.size() + other._nodes.size()); //reserve
_nodes.insert(_nodes.end(), other._nodes.begin()+2, other._nodes.end()); _nodes.insert(_nodes.end(), other._nodes.begin()+2, other._nodes.end());
...@@ -57,7 +70,12 @@ int LineStrip::canBeAttached(const LineStrip& other) const { ...@@ -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 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]); 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 { bool LineStrip::isActive() const {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment