From dff3aa428ff050c2cce501f646977ddad921feca Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 04:13:16 +0200 Subject: Move 2Geom work to a intermediate positon -helper- Removed dependency to helper/geom.h Now use a simple vector, not a vector of pairs of size_t and Satellite Getters and setters on Satellite removed Update store parameter to a more friendly string, like powerstroke Todo: Documentation and Fix coding style. (bzr r13645.1.63) --- src/helper/Makefile_insert | 7 + src/helper/geom-pathinfo.cpp | 178 ++++++++++++++++++++++++++ src/helper/geom-pathinfo.h | 81 ++++++++++++ src/helper/geom-pointwise.cpp | 268 +++++++++++++++++++++++++++++++++++++++ src/helper/geom-pointwise.h | 96 ++++++++++++++ src/helper/geom-satellite-enum.h | 51 ++++++++ src/helper/geom-satellite.cpp | 237 ++++++++++++++++++++++++++++++++++ src/helper/geom-satellite.h | 87 +++++++++++++ 8 files changed, 1005 insertions(+) create mode 100644 src/helper/geom-pathinfo.cpp create mode 100644 src/helper/geom-pathinfo.h create mode 100644 src/helper/geom-pointwise.cpp create mode 100644 src/helper/geom-pointwise.h create mode 100644 src/helper/geom-satellite-enum.h create mode 100644 src/helper/geom-satellite.cpp create mode 100644 src/helper/geom-satellite.h (limited to 'src/helper') diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index e59fcfb70..1d051734e 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -12,8 +12,15 @@ ink_common_sources += \ helper/geom-curves.h \ helper/geom-nodetype.cpp \ helper/geom-nodetype.h \ + helper/geom-pathinfo.cpp \ + helper/geom-pathinfo.h \ helper/geom-pathstroke.cpp \ helper/geom-pathstroke.h \ + helper/geom-pointwise.cpp \ + helper/geom-pointwise.h \ + helper/geom-satellite.cpp \ + helper/geom-satellite.h \ + helper/geom-satellite-enum.h \ helper/gnome-utils.cpp \ helper/gnome-utils.h \ helper/mathfns.h \ diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp new file mode 100644 index 000000000..c8ba01bd0 --- /dev/null +++ b/src/helper/geom-pathinfo.cpp @@ -0,0 +1,178 @@ +/* + * pathinfo.cpp + * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, output to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + */ + +#include +#include <2geom/sbasis-to-bezier.h> + +namespace Geom { + +Pathinfo::Pathinfo(Piecewise > pwd2) + : _pwd2(pwd2) +{ + setPathInfo(); +}; + +Pathinfo::~Pathinfo(){}; + +Piecewise > +Pathinfo::getPwd2() const +{ + return _pwd2; +} + +void +Pathinfo::setPwd2(Piecewise > pwd2_in) +{ + _pwd2 = pwd2_in; + setPathInfo(); +} + + +void +Pathinfo::setPathInfo() +{ + _pathInfo.clear(); + std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + size_t counter = 0; + for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { + if (path_it->empty()){ + continue; + } + Geom::Path::const_iterator curve_it1 = path_it->begin(); + Geom::Path::const_iterator curve_endit = path_it->end_default(); + if (path_it->closed()) { + const Curve &closingline = path_it->back_closed(); + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + curve_endit = path_it->end_open(); + } + } + while (curve_it1 != curve_endit) { + ++curve_it1; + counter++; + } + if(path_it->closed()){ + _pathInfo.push_back(std::make_pair(counter-1,true)); + } else { + _pathInfo.push_back(std::make_pair(counter-1,false)); + } + } +} + +size_t +Pathinfo::getSubPathIndex(size_t index) const +{ + for(size_t i = 0; i < _pathInfo.size(); i++){ + if(index <= _pathInfo[i].first){ + return i; + } + } + return 0; +} + +size_t +Pathinfo::getLast(size_t index) const +{ + for(size_t i = 0; i < _pathInfo.size(); i++){ + if(index <= _pathInfo[i].first){ + return _pathInfo[i].first; + } + } + return 0; +} + +size_t +Pathinfo::getFirst(size_t index) const +{ + for(size_t i = 0; i < _pathInfo.size(); i++){ + if(index <= _pathInfo[i].first){ + if(i==0){ + return 0; + } else { + return _pathInfo[i-1].first + 1; + } + } + } + return 0; +} + +boost::optional +Pathinfo::getPrevious(size_t index) const +{ + if(getFirst(index) == index && getIsClosed(index)){ + return getLast(index); + } + if(getFirst(index) == index && !getIsClosed(index)){ + return boost::none; + } + return index - 1; +} + +boost::optional +Pathinfo::getNext(size_t index) const +{ + if(getLast(index) == index && getIsClosed(index)){ + return getFirst(index); + } + if(getLast(index) == index && !getIsClosed(index)){ + return boost::none; + } + return index + 1; +} + +bool +Pathinfo::getIsClosed(size_t index) const +{ + for(size_t i = 0; i < _pathInfo.size(); i++){ + if(index <= _pathInfo[i].first){ + return _pathInfo[i].second; + } + } + return false; +} + +std::vector > +Pathinfo::getPathInfo() const +{ + return _pathInfo; +} + +}; // namespace Geom + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h new file mode 100644 index 000000000..1696fd366 --- /dev/null +++ b/src/helper/geom-pathinfo.h @@ -0,0 +1,81 @@ +/** + * \file + * \brief Pathinfo + *//* + * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors + * + * Pathinfo maintains .... + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, output to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + */ + +#ifndef SEEN_GEOM_PATHINFO_H +#define SEEN_GEOM_PATHINFO_H + +#include <2geom/path.h> +#include + +namespace Geom { + +/** + * %Pathinfo function class. + */ + +class Pathinfo +{ + public: + Pathinfo(Piecewise > pwd2); + virtual ~Pathinfo(); + Piecewise > getPwd2() const; + void setPwd2(Piecewise > pwd2_in); + size_t getSubPathIndex(size_t index) const; + size_t getLast(size_t index) const; + size_t getFirst(size_t index) const; + boost::optional getPrevious(size_t index) const; + boost::optional getNext(size_t index) const; + bool getIsClosed(size_t index) const; + std::vector > getPathInfo() const; + + private: + void setPathInfo(); + Piecewise > _pwd2; + std::vector > _pathInfo; +}; + +} //namespace Geom + + +#endif //SEEN_GEOM_PATHINFO_H +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp new file mode 100644 index 000000000..4926bcc47 --- /dev/null +++ b/src/helper/geom-pointwise.cpp @@ -0,0 +1,268 @@ +/* + * pointwise.cpp + * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, output to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + */ + +#include +#include + +namespace Geom { + +Pointwise::Pointwise(Piecewise > pwd2, std::vector satellites) + : _pwd2(pwd2), _satellites(satellites), _pathInfo(pwd2) +{ +}; + +Pointwise::~Pointwise(){}; + +Piecewise > +Pointwise::getPwd2() const +{ + return _pwd2; +} + +void +Pointwise::setPwd2(Piecewise > pwd2_in) +{ + _pwd2 = pwd2_in; + _pathInfo.setPwd2(_pwd2); +} + +std::vector +Pointwise::getSatellites() const +{ + return _satellites; +} + +void +Pointwise::setSatellites(std::vector sats) +{ + _satellites = sats; +} + +void +Pointwise::recalculate_for_new_pwd2(Piecewise > A) +{ + if( _pwd2.size() > A.size()){ + pwd2_sustract(A); + } else if (_pwd2.size() < A.size()){ + pwd2_append(A); + } +} + +void +Pointwise::pwd2_append(Piecewise > A) +{ + size_t counter = 0; + std::vector sats; + bool reversed = false; + bool reorder = false; + for(size_t i = 0; i < A.size(); i++){ + size_t first = _pathInfo.getFirst(i-counter); + size_t last = _pathInfo.getLast(i-counter); + _pathInfo.setPwd2(A); + size_t subpathAIndex = _pathInfo.getSubPathIndex(i); + _pathInfo.setPwd2(_pwd2); + bool changedSubpath = false; + if(_pwd2.size() <= i-counter){ + changedSubpath = false; + } else { + changedSubpath = subpathAIndex != _pathInfo.getSubPathIndex(i-counter); + } + if(!reorder && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ + subpath_append_reorder(_pathInfo.getSubPathIndex(first)); + reorder = true; + i--; + continue; + } + if(!reversed && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ + reverse(first, last); + reversed = true; + } + if(_pwd2.size() <= i-counter || !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ + counter++; + bool active = true; + bool hidden = false; + bool isTime = _satellites[0].isTime; + bool mirror_knots = _satellites[0].hasMirror; + double amount = 0.0; + double degrees = 0.0; + int steps = 0; + Satellite sat(_satellites[0].satelliteType, isTime, active, mirror_knots, hidden, amount, degrees, steps); + sats.push_back(sat); + } else { + sats.push_back(_satellites[i-counter]); + } + } + setPwd2(A); + setSatellites(sats); +} + +void +Pointwise::pwd2_sustract(Piecewise > A) +{ + size_t counter = 0; + std::vector sats; + Piecewise > pwd2 = _pwd2; + setPwd2(A); + for(size_t i = 0; i < _satellites.size(); i++){ + if(_pathInfo.getLast(i-counter) < i-counter || !are_near(pwd2[i].at0(),A[i-counter].at0(),0.001)){ + counter++; + } else { + sats.push_back(_satellites[i-counter]); + } + } + setSatellites(sats); +} + +void +Pointwise::set_extremes(bool active, bool hidden, double amount, double angle) +{ + std::vector > pathInfo = _pathInfo.getPathInfo(); + for(size_t i = 0; i < pathInfo.size(); i++){ + size_t firstNode = _pathInfo.getFirst(pathInfo[i].first); + size_t lastNode = _pathInfo.getLast(pathInfo[i].first); + if(!_pathInfo.getIsClosed(lastNode)){ + for(size_t j = 0; j < _satellites.size(); j++){ + if(j < firstNode || j > lastNode){ + continue; + } + if(j == firstNode){ + _satellites[j].active = active; + _satellites[j].hidden = hidden; + if(amount >= 0){ + _satellites[j].amount = amount; + } + if(angle >= 0){ + _satellites[j].angle = angle; + } + } + } + } else { + for(size_t j = 0; j < _satellites.size(); j++){ + if(j < firstNode){ + continue; + } + if(j == firstNode && !_satellites[j].active){ + _satellites[j].active = true; + _satellites[j].hidden = _satellites[j+1].hidden; + } + + } + } + } +} + +void +Pointwise::subpath_append_reorder(size_t subpath){ + std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + size_t nSubpath = 0; + size_t counter = 0; + std::vector tmp_path; + Geom::Path rev; + for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { + if (path_it->empty()){ + continue; + } + Geom::Path::const_iterator curve_it1 = path_it->begin(); + Geom::Path::const_iterator curve_endit = path_it->end_default(); + const Curve &closingline = path_it->back_closed(); + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + curve_endit = path_it->end_open(); + } + while (curve_it1 != curve_endit) { + if(nSubpath == subpath){ + _satellites.push_back(_satellites[counter]); + deleteSatellite(counter); + } else { + counter++; + } + ++curve_it1; + } + if(nSubpath == subpath){ + rev = *path_it; + } else { + tmp_path.push_back(*path_it); + } + nSubpath++; + } + tmp_path.push_back(rev); + setPwd2(remove_short_cuts(paths_to_pw(tmp_path),0.01)); +} + +void +Pointwise::reverse(size_t start,size_t end){ + start ++; + for(size_t i = end; i >= start; i--){ + _satellites.push_back(_satellites[i]); + deleteSatellite(i); + } + std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + size_t counter = 0; + size_t nSubpath = 0; + size_t subpath = _pathInfo.getSubPathIndex(start); + std::vector tmp_path; + Geom::Path rev; + for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { + if (path_it->empty()){ + continue; + } + counter ++; + if(nSubpath == subpath){ + tmp_path.push_back(path_it->reverse()); + } else { + tmp_path.push_back(*path_it); + } + nSubpath++; + } + setPwd2(remove_short_cuts(paths_to_pw(tmp_path),0.01)); +} + +void +Pointwise::deleteSatellite(size_t A) +{ + for (std::vector::iterator it = _satellites.begin(); it != _satellites.end();) + { + if((unsigned)(it - _satellites.begin()) == A){ + it = _satellites.erase(it); + } + } +} + +} // namespace Geom +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h new file mode 100644 index 000000000..8b5c275b9 --- /dev/null +++ b/src/helper/geom-pointwise.h @@ -0,0 +1,96 @@ +/** + * \file + * \brief Pointwise + *//* + * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors + * + * Pointwise maintains a set of "Satellite" positions along a curve/pathvector. + * The positions are specified as arc length distances along the curve or by + * time in the curve. Splicing operations automatically update the satellite + * positions to preserve the intent. + * The data is serialised to SVG using a specialiced pointwise LPE parameter to + * handle it in th future can be a inkscape based property to paths + * Anywhere a Piecewise is used, a Pointwise can be substituted, allowing + * existing algorithms to correctly update satellite positions. + + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, output to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + * + */ + +#ifndef SEEN_GEOM_POINTWISE_H +#define SEEN_GEOM_POINTWISE_H + +#include +#include <2geom/sbasis.h> +#include <2geom/sbasis-2d.h> +#include <2geom/piecewise.h> +#include +#include +#include <2geom/sbasis-to-bezier.h> +#include <2geom/path.h> +#include + +namespace Geom { +/** + * %Pointwise function class. + */ + +class Pointwise +{ + public: + Pointwise(Piecewise > pwd2, std::vector satellites); + virtual ~Pointwise(); + std::vector getSatellites() const; + void setSatellites(std::vector sats); + Piecewise > getPwd2() const; + void setPwd2(Piecewise > pwd2_in); + void recalculate_for_new_pwd2(Piecewise > A); + void pwd2_append(Piecewise > A); + void pwd2_sustract(Piecewise > A); + void set_extremes(bool active, bool hidden, double amount = -1, double angle = -1); + void deleteSatellite(size_t A); + void subpath_append_reorder(size_t subpath); + void reverse(size_t start,size_t end); + + private: + Piecewise > _pwd2; + std::vector _satellites; + Pathinfo _pathInfo; +}; + +} // end namespace Geom + +#endif //SEEN_GEOM_POINTWISE_H +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/geom-satellite-enum.h b/src/helper/geom-satellite-enum.h new file mode 100644 index 000000000..bcd8d1bb3 --- /dev/null +++ b/src/helper/geom-satellite-enum.h @@ -0,0 +1,51 @@ +#ifndef LIB2GEOM_SEEN_SATELLITE_ENUM_H +#define LIB2GEOM_SEEN_SATELLITE_ENUM_H + +/* + * + * +* Copyright (C) Jabier Arraiza Cenoz + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "util/enums.h" +/*#include +*/ + +namespace Geom { + +enum SatelliteType { + F=0, //Fillet + IF, //Inverse Fillet + C, //Chamfer + IC, //Inverse Chamfer + KO // Invalid Satellite) +}; + +/* TODO maybe is best do next by bimap + typedef boost::bimap< Geom::SatelliteType,gchar const *> map_type ; + + map_type SatelliteTypeBimap; + + SatelliteTypeBimap.insert( map_type::value_type(FILLET, "FILLET")); + SatelliteTypeBimap.insert( map_type::value_type(INVERSE_FILLET, "INVERSE_FILLET")); + SatelliteTypeBimap.insert( map_type::value_type(CHAMFER, "CHAMFER")) ); + SatelliteTypeBimap.insert( map_type::value_type(INVERSE_CHAMFER, "INVERSE_CHAMFER")); + SatelliteTypeBimap.insert( map_type::value_type(INVALID_SATELLITE, "INVALID_SATELLITE")); +*/ + +} //namespace Geom + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp new file mode 100644 index 000000000..73201445a --- /dev/null +++ b/src/helper/geom-satellite.cpp @@ -0,0 +1,237 @@ +/** + * \file + * \brief Satellite + *//* + * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + */ + +#include +#include <2geom/curve.h> +#include <2geom/nearest-point.h> +#include <2geom/sbasis-geometric.h> +#include <2geom/path-intersection.h> +#include <2geom/sbasis-to-bezier.h> +#include <2geom/ray.h> +#include + + +namespace Geom { + +Satellite::Satellite(){}; + +Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps) + : satelliteType(satelliteType), isTime(isTime), active(active), hasMirror(hasMirror), hidden(hidden), amount(amount), angle(angle), steps(steps){}; + +Satellite::~Satellite() {}; + +double +Satellite::toTime(double A,Geom::D2 d2_in) const +{ + if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ + return 0; + } + double t = 0; + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); + if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) { + if (lenghtPart != 0) { + t = A / lenghtPart; + } + } else if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + std::vector t_roots = roots(arcLengthSb(u) - A); + if (t_roots.size() > 0) { + t = t_roots[0]; + } + } + + return t; +} + +double +Satellite::toSize(double A,Geom::D2 d2_in) const +{ + if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ + return 0; + } + double s = 0; + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); + if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) { + s = (A * lenghtPart); + } else if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + u = Geom::portion(u, 0.0, A); + s = Geom::length(u, 0.001); + } + return s; +} + + +double +Satellite::rad_to_len(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const +{ + double len = 0; + if(d2_in && previousSatellite){ + Piecewise > offset_curve0 = Piecewise >(*d2_in)+rot90(unitVector(derivative(*d2_in)))*(A); + Piecewise > offset_curve1 = Piecewise >(d2_out)+rot90(unitVector(derivative(d2_out)))*(A); + Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; + Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; + Geom::Crossings cs = Geom::crossings(p0, p1); + if(cs.size() > 0){ + Point cp =p0(cs[0].ta); + double p0pt = nearest_point(cp, d2_out); + len = (*previousSatellite).toSize(p0pt,d2_out); + } else { + if(A > 0){ + len = rad_to_len(A * -1, *d2_in, d2_out, previousSatellite); + } + } + } + return len; +} + +double +Satellite::len_to_rad(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const +{ + if(d2_in && previousSatellite){ + double time_in = (*previousSatellite).getOpositeTime(A, *d2_in); + double time_out = (*previousSatellite).toTime(A,d2_out); + Geom::Point startArcPoint = (*d2_in).valueAt(time_in); + Geom::Point endArcPoint = d2_out.valueAt(time_out); + Piecewise > u; + u.push_cut(0); + u.push(*d2_in, 1); + Geom::Curve * C = path_from_piecewise(u, 0.1)[0][0].duplicate(); + Piecewise > u2; + u2.push_cut(0); + u2.push(d2_out, 1); + Geom::Curve * D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); + Curve *knotCurve1 = C->portion(0, time_in); + Curve *knotCurve2 = D->portion(time_out, 1); + Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); + Ray ray1(startArcPoint, (*d2_in).valueAt(1)); + if (cubic1) { + ray1.setPoints((*cubic1)[2], startArcPoint); + } + Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); + Ray ray2(d2_out.valueAt(0), endArcPoint); + if (cubic2) { + ray2.setPoints(endArcPoint, (*cubic2)[1]); + } + bool ccwToggle = cross((*d2_in).valueAt(1) - startArcPoint, endArcPoint - startArcPoint) < 0; + double distanceArc = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint)); + double angleBetween = angle_between(ray1, ray2, ccwToggle); + double divisor = std::sin(angleBetween/2.0); + if(divisor > 0){ + return distanceArc/divisor; + } + } + return 0; +} + +double +Satellite::getOpositeTime(double s, Geom::D2 d2_in) const +{ + if(s == 0){ + return 1; + } + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); + double size = lenghtPart - s; + return toTime(size, d2_in); +} + +double +Satellite::getTime(Geom::D2 d2_in) const +{ + double t = amount; + if(!isTime){ + t = toTime(t, d2_in); + } + if(t > 1){ + t = 1; + } + return t; +} + +double +Satellite::getSize(Geom::D2 d2_in) const +{ + double s = amount; + if(isTime){ + s = toSize(s, d2_in); + } + return s; +} + + +Geom::Point +Satellite::getPosition(Geom::D2 d2_in) const +{ + double t = getTime(d2_in); + return d2_in.valueAt(t); +} + +void +Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) +{ + double A = Geom::nearest_point(p, d2_in); + if(!isTime){ + A = toSize(A, d2_in); + } + amount = A; +} + +void +Satellite::setSatelliteType(gchar const * A) +{ + std::map GcharMapToSatelliteType = boost::assign::map_list_of("F", F)("IF", IF)("C",C)("IC",IC)("KO",KO); + satelliteType = GcharMapToSatelliteType.find(std::string(A))->second; +} + +gchar const * +Satellite::getSatelliteTypeGchar() const +{ + std::map SatelliteTypeToGcharMap = boost::assign::map_list_of(F, "F")(IF, "IF")(C,"C")(IC,"IC")(KO,"KO"); + return SatelliteTypeToGcharMap.at(satelliteType); +} + +} //namespace Geom + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h new file mode 100644 index 000000000..f367bb7f3 --- /dev/null +++ b/src/helper/geom-satellite.h @@ -0,0 +1,87 @@ +/** + * \file + * \brief Satellite + *//* + * Authors: + * 2015 Jabier Arraiza Cenoz + * Copyright 2015 authors + * + * This library is free software; you can redistribute it and/or + * modify it either under the terms of the GNU Lesser General Public + * License version 2.1 as published by the Free Software Foundation + * (the "LGPL") or, at your option, under the terms of the Mozilla + * Public License Version 1.1 (the "MPL"). If you do not alter this + * notice, a recipient may use your version of this file under either + * the MPL or the LGPL. + * + * You should have received a copy of the LGPL along with this library + * in the file COPYING-LGPL-2.1; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * You should have received a copy of the MPL along with this library + * in the file COPYING-MPL-1.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY + * OF ANY KIND, either express or implied. See the LGPL or the MPL for + * the specific language governing rights and limitations. + */ + +#ifndef LIB2GEOM_SEEN_SATELLITE_H +#define LIB2GEOM_SEEN_SATELLITE_H + +#include +#include <2geom/d2.h> +#include +#include + +namespace Geom { + +class Satellite +{ + public: + + Satellite(); + Satellite(SatelliteType satelliteType, bool isTime, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps); + + virtual ~Satellite(); + + void setPosition(Geom::Point p, Geom::D2 d2_in); + Geom::Point getPosition(Geom::D2 d2_in) const; + double getSize(Geom::D2 d2_in) const; + double getTime(Geom::D2 d2_in) const; + double getOpositeTime(double A,Geom::D2 SBasisCurve) const; + double toSize(double A,Geom::D2 d2_in) const; + double toTime(double A,Geom::D2 d2_in) const; + double len_to_rad(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const; + double rad_to_len(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const; + void setSatelliteType(gchar const * A); + gchar const * getSatelliteTypeGchar() const; + + SatelliteType satelliteType; + bool isTime; + bool active; + bool hasMirror; + bool hidden; + double amount; + double angle; + size_t steps; +}; + +} // end namespace Geom + +#endif // LIB2GEOM_SEEN_SATELLITE_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3 From ce42be89c9b32edeba6eda6522199ec749e014f8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 12:08:06 +0200 Subject: More cleanup of code structure. TODO: Documentation TODO: Fit code guidelines of Inkscape (bzr r13645.1.64) --- src/helper/geom-pathinfo.cpp | 6 --- src/helper/geom-pathinfo.h | 1 - src/helper/geom-pointwise.cpp | 117 ++++++++++++++++-------------------------- src/helper/geom-pointwise.h | 17 +++--- 4 files changed, 53 insertions(+), 88 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index c8ba01bd0..4bacad7ea 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -42,12 +42,6 @@ Pathinfo::Pathinfo(Piecewise > pwd2) Pathinfo::~Pathinfo(){}; -Piecewise > -Pathinfo::getPwd2() const -{ - return _pwd2; -} - void Pathinfo::setPwd2(Piecewise > pwd2_in) { diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 1696fd366..9018e44f2 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -49,7 +49,6 @@ class Pathinfo public: Pathinfo(Piecewise > pwd2); virtual ~Pathinfo(); - Piecewise > getPwd2() const; void setPwd2(Piecewise > pwd2_in); size_t getSubPathIndex(size_t index) const; size_t getLast(size_t index) const; diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 4926bcc47..9096dff28 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -30,13 +30,14 @@ */ #include -#include + namespace Geom { Pointwise::Pointwise(Piecewise > pwd2, std::vector satellites) : _pwd2(pwd2), _satellites(satellites), _pathInfo(pwd2) { + setStart(); }; Pointwise::~Pointwise(){}; @@ -64,6 +65,24 @@ void Pointwise::setSatellites(std::vector sats) { _satellites = sats; + setStart(); +} + +void +Pointwise::setStart() +{ + std::vector > pathInfo = _pathInfo.getPathInfo(); + for(size_t i = 0; i < pathInfo.size(); i++){ + size_t firstNode = _pathInfo.getFirst(pathInfo[i].first); + size_t lastNode = _pathInfo.getLast(pathInfo[i].first); + if(!_pathInfo.getIsClosed(lastNode)){ + _satellites[firstNode].hidden = true; + _satellites[firstNode].active = false; + } else { + _satellites[firstNode].active = true; + _satellites[firstNode].hidden = _satellites[firstNode + 1].hidden; + } + } } void @@ -76,6 +95,24 @@ Pointwise::recalculate_for_new_pwd2(Piecewise > A) } } +void +Pointwise::pwd2_sustract(Piecewise > A) +{ + size_t counter = 0; + std::vector sats; + Piecewise > pwd2 = _pwd2; + setPwd2(A); + for(size_t i = 0; i < _satellites.size(); i++){ + if(_pathInfo.getLast(i-counter) < i-counter || !are_near(pwd2[i].at0(),A[i-counter].at0(),0.001)){ + counter++; + } else { + sats.push_back(_satellites[i-counter]); + } + } + setSatellites(sats); +} + + void Pointwise::pwd2_append(Piecewise > A) { @@ -96,13 +133,13 @@ Pointwise::pwd2_append(Piecewise > A) changedSubpath = subpathAIndex != _pathInfo.getSubPathIndex(i-counter); } if(!reorder && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ - subpath_append_reorder(_pathInfo.getSubPathIndex(first)); + subpath_to_top(_pathInfo.getSubPathIndex(first)); reorder = true; i--; continue; } if(!reversed && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ - reverse(first, last); + subpath_reverse(first, last); reversed = true; } if(_pwd2.size() <= i-counter || !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ @@ -125,62 +162,7 @@ Pointwise::pwd2_append(Piecewise > A) } void -Pointwise::pwd2_sustract(Piecewise > A) -{ - size_t counter = 0; - std::vector sats; - Piecewise > pwd2 = _pwd2; - setPwd2(A); - for(size_t i = 0; i < _satellites.size(); i++){ - if(_pathInfo.getLast(i-counter) < i-counter || !are_near(pwd2[i].at0(),A[i-counter].at0(),0.001)){ - counter++; - } else { - sats.push_back(_satellites[i-counter]); - } - } - setSatellites(sats); -} - -void -Pointwise::set_extremes(bool active, bool hidden, double amount, double angle) -{ - std::vector > pathInfo = _pathInfo.getPathInfo(); - for(size_t i = 0; i < pathInfo.size(); i++){ - size_t firstNode = _pathInfo.getFirst(pathInfo[i].first); - size_t lastNode = _pathInfo.getLast(pathInfo[i].first); - if(!_pathInfo.getIsClosed(lastNode)){ - for(size_t j = 0; j < _satellites.size(); j++){ - if(j < firstNode || j > lastNode){ - continue; - } - if(j == firstNode){ - _satellites[j].active = active; - _satellites[j].hidden = hidden; - if(amount >= 0){ - _satellites[j].amount = amount; - } - if(angle >= 0){ - _satellites[j].angle = angle; - } - } - } - } else { - for(size_t j = 0; j < _satellites.size(); j++){ - if(j < firstNode){ - continue; - } - if(j == firstNode && !_satellites[j].active){ - _satellites[j].active = true; - _satellites[j].hidden = _satellites[j+1].hidden; - } - - } - } - } -} - -void -Pointwise::subpath_append_reorder(size_t subpath){ +Pointwise::subpath_to_top(size_t subpath){ std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); size_t nSubpath = 0; size_t counter = 0; @@ -199,7 +181,7 @@ Pointwise::subpath_append_reorder(size_t subpath){ while (curve_it1 != curve_endit) { if(nSubpath == subpath){ _satellites.push_back(_satellites[counter]); - deleteSatellite(counter); + _satellites.erase(_satellites.begin() + counter); } else { counter++; } @@ -217,11 +199,11 @@ Pointwise::subpath_append_reorder(size_t subpath){ } void -Pointwise::reverse(size_t start,size_t end){ +Pointwise::subpath_reverse(size_t start,size_t end){ start ++; for(size_t i = end; i >= start; i--){ _satellites.push_back(_satellites[i]); - deleteSatellite(i); + _satellites.erase(_satellites.begin() + i); } std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); size_t counter = 0; @@ -244,17 +226,6 @@ Pointwise::reverse(size_t start,size_t end){ setPwd2(remove_short_cuts(paths_to_pw(tmp_path),0.01)); } -void -Pointwise::deleteSatellite(size_t A) -{ - for (std::vector::iterator it = _satellites.begin(); it != _satellites.end();) - { - if((unsigned)(it - _satellites.begin()) == A){ - it = _satellites.erase(it); - } - } -} - } // namespace Geom /* Local Variables: diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 8b5c275b9..8297143c9 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -43,12 +43,11 @@ #ifndef SEEN_GEOM_POINTWISE_H #define SEEN_GEOM_POINTWISE_H -#include +#include +#include #include <2geom/sbasis.h> #include <2geom/sbasis-2d.h> #include <2geom/piecewise.h> -#include -#include #include <2geom/sbasis-to-bezier.h> #include <2geom/path.h> #include @@ -63,17 +62,19 @@ class Pointwise public: Pointwise(Piecewise > pwd2, std::vector satellites); virtual ~Pointwise(); + std::vector getSatellites() const; void setSatellites(std::vector sats); Piecewise > getPwd2() const; void setPwd2(Piecewise > pwd2_in); + void setStart(); + void recalculate_for_new_pwd2(Piecewise > A); - void pwd2_append(Piecewise > A); void pwd2_sustract(Piecewise > A); - void set_extremes(bool active, bool hidden, double amount = -1, double angle = -1); - void deleteSatellite(size_t A); - void subpath_append_reorder(size_t subpath); - void reverse(size_t start,size_t end); + void pwd2_append(Piecewise > A); + void subpath_to_top(size_t subpath); + void subpath_reverse(size_t start,size_t end); + private: Piecewise > _pwd2; -- cgit v1.2.3 From aea84844cf40c4c1b1977548421ec50ad164590e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 14:18:34 +0200 Subject: add documentation (bzr r13645.1.65) --- src/helper/geom-pathinfo.cpp | 38 +++++----------- src/helper/geom-pathinfo.h | 32 ++------------ src/helper/geom-pointwise.cpp | 60 +++++++++++++------------- src/helper/geom-pointwise.h | 59 ++++++++----------------- src/helper/geom-satellite-enum.h | 26 +++-------- src/helper/geom-satellite.cpp | 93 ++++++++++++++++++++++++---------------- src/helper/geom-satellite.h | 44 ++++++------------- 7 files changed, 142 insertions(+), 210 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 4bacad7ea..19991e879 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -1,32 +1,11 @@ -/* - * pathinfo.cpp +/** + * \file + * \brief Pathinfo store the data of a pathvector and allow get info about it + *//* * Authors: * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, output to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. * + * This code is in public domain */ #include @@ -34,6 +13,10 @@ namespace Geom { +/** + * @brief Pathinfo store the data of a pathvector and allow get info about it + * + */ Pathinfo::Pathinfo(Piecewise > pwd2) : _pwd2(pwd2) { @@ -49,7 +32,8 @@ Pathinfo::setPwd2(Piecewise > pwd2_in) setPathInfo(); } - +/** Store the base path data + */ void Pathinfo::setPathInfo() { diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 9018e44f2..9a40a4f20 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -1,35 +1,11 @@ /** * \file - * \brief Pathinfo + * \brief Pathinfo store the data of a pathvector and allow get info about it *//* * Authors: * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors - * - * Pathinfo maintains .... - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, output to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. * + * This code is in public domain */ #ifndef SEEN_GEOM_PATHINFO_H @@ -41,9 +17,9 @@ namespace Geom { /** - * %Pathinfo function class. + * @brief Pathinfo store the data of a pathvector and allow get info about it + * */ - class Pathinfo { public: diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 9096dff28..9e65685ae 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -1,32 +1,11 @@ -/* - * pointwise.cpp +/** + * \file + * \brief Pointwise a class to manage a vector of satellites per piecewise curve + *//* * Authors: * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors - * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, output to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. * + * This code is in public domain */ #include @@ -34,6 +13,19 @@ namespace Geom { +/** + * @brief Pointwise a class to manage a vector of satellites per piecewise curve + * + * For the moment is a per curve satellite holder not per node. This is ok for + * much cases but not a real node satellite on open paths + * To implement this we can: + * add extra satellite in open paths, and take notice of current open paths + * or put extra satellites on back for each open subpath + * + * Also maybe the vector of satellites become a vector of + * optional satellites, and remove the active variable in satellites. + * + */ Pointwise::Pointwise(Piecewise > pwd2, std::vector satellites) : _pwd2(pwd2), _satellites(satellites), _pathInfo(pwd2) { @@ -68,6 +60,8 @@ Pointwise::setSatellites(std::vector sats) setStart(); } +/** Update the start satellite on ope/closed paths. + */ void Pointwise::setStart() { @@ -85,6 +79,8 @@ Pointwise::setStart() } } +/** Fired when a path is modified. + */ void Pointwise::recalculate_for_new_pwd2(Piecewise > A) { @@ -95,6 +91,8 @@ Pointwise::recalculate_for_new_pwd2(Piecewise > A) } } +/** Some nodes/subpaths are removed. + */ void Pointwise::pwd2_sustract(Piecewise > A) { @@ -112,7 +110,8 @@ Pointwise::pwd2_sustract(Piecewise > A) setSatellites(sats); } - +/** Append nodes/subpaths to current pointwise + */ void Pointwise::pwd2_append(Piecewise > A) { @@ -123,6 +122,7 @@ Pointwise::pwd2_append(Piecewise > A) for(size_t i = 0; i < A.size(); i++){ size_t first = _pathInfo.getFirst(i-counter); size_t last = _pathInfo.getLast(i-counter); + //Check for subpath closed. If a subpath is closed, is not reversed or moved to back _pathInfo.setPwd2(A); size_t subpathAIndex = _pathInfo.getSubPathIndex(i); _pathInfo.setPwd2(_pwd2); @@ -133,7 +133,8 @@ Pointwise::pwd2_append(Piecewise > A) changedSubpath = subpathAIndex != _pathInfo.getSubPathIndex(i-counter); } if(!reorder && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ - subpath_to_top(_pathInfo.getSubPathIndex(first)); + //Send the modified subpath to back + subpath_to_back(_pathInfo.getSubPathIndex(first)); reorder = true; i--; continue; @@ -161,8 +162,9 @@ Pointwise::pwd2_append(Piecewise > A) setSatellites(sats); } + void -Pointwise::subpath_to_top(size_t subpath){ +Pointwise::subpath_to_back(size_t subpath){ std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); size_t nSubpath = 0; size_t counter = 0; diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 8297143c9..59ed4d1aa 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -1,43 +1,11 @@ /** * \file - * \brief Pointwise + * \brief Pointwise a class to manage a vector of satellites per piecewise curve *//* * Authors: * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors - * - * Pointwise maintains a set of "Satellite" positions along a curve/pathvector. - * The positions are specified as arc length distances along the curve or by - * time in the curve. Splicing operations automatically update the satellite - * positions to preserve the intent. - * The data is serialised to SVG using a specialiced pointwise LPE parameter to - * handle it in th future can be a inkscape based property to paths - * Anywhere a Piecewise is used, a Pointwise can be substituted, allowing - * existing algorithms to correctly update satellite positions. - - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, output to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. * + * This code is in public domain */ #ifndef SEEN_GEOM_POINTWISE_H @@ -53,29 +21,40 @@ #include namespace Geom { + /** - * %Pointwise function class. + * @brief Pointwise a class to manage a vector of satellites per piecewise curve + * + * For the moment is a per curve satellite holder not per node. This is ok for + * much cases but not a real node satellite on open paths + * To implement this we can: + * add extra satellite in open paths, and take notice of current open paths + * or put extra satellites on back for each open subpath + * + * Also maybe the vector of satellites become a vector of + * optional satellites, and remove the active variable in satellites. + * */ - class Pointwise { public: Pointwise(Piecewise > pwd2, std::vector satellites); virtual ~Pointwise(); - std::vector getSatellites() const; - void setSatellites(std::vector sats); Piecewise > getPwd2() const; void setPwd2(Piecewise > pwd2_in); + + std::vector getSatellites() const; + void setSatellites(std::vector sats); + void setStart(); void recalculate_for_new_pwd2(Piecewise > A); void pwd2_sustract(Piecewise > A); void pwd2_append(Piecewise > A); - void subpath_to_top(size_t subpath); + void subpath_to_back(size_t subpath); void subpath_reverse(size_t start,size_t end); - private: Piecewise > _pwd2; std::vector _satellites; diff --git a/src/helper/geom-satellite-enum.h b/src/helper/geom-satellite-enum.h index bcd8d1bb3..4680ce2f6 100644 --- a/src/helper/geom-satellite-enum.h +++ b/src/helper/geom-satellite-enum.h @@ -1,17 +1,17 @@ #ifndef LIB2GEOM_SEEN_SATELLITE_ENUM_H #define LIB2GEOM_SEEN_SATELLITE_ENUM_H -/* - * +/** + * \file + * \brief Satellite types enum + *//* + * Authors: + * 2015 Jabier Arraiza Cenoz * -* Copyright (C) Jabier Arraiza Cenoz - * - * Released under GNU GPL, read the file 'COPYING' for more information + * This code is in public domain */ #include "util/enums.h" -/*#include -*/ namespace Geom { @@ -23,18 +23,6 @@ enum SatelliteType { KO // Invalid Satellite) }; -/* TODO maybe is best do next by bimap - typedef boost::bimap< Geom::SatelliteType,gchar const *> map_type ; - - map_type SatelliteTypeBimap; - - SatelliteTypeBimap.insert( map_type::value_type(FILLET, "FILLET")); - SatelliteTypeBimap.insert( map_type::value_type(INVERSE_FILLET, "INVERSE_FILLET")); - SatelliteTypeBimap.insert( map_type::value_type(CHAMFER, "CHAMFER")) ); - SatelliteTypeBimap.insert( map_type::value_type(INVERSE_CHAMFER, "INVERSE_CHAMFER")); - SatelliteTypeBimap.insert( map_type::value_type(INVALID_SATELLITE, "INVALID_SATELLITE")); -*/ - } //namespace Geom #endif diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 73201445a..6304b4148 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -1,33 +1,11 @@ /** * \file - * \brief Satellite + * \brief Satellite a per ?node/curve holder of data. *//* * Authors: * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. + * This code is in public domain */ #include @@ -42,6 +20,9 @@ namespace Geom { +/** + * @brief Satellite a per ?node/curve holder of data. + */ Satellite::Satellite(){}; Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps) @@ -49,6 +30,9 @@ Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active, bool Satellite::~Satellite() {}; +/** + * Calculate the time in d2_in with a size of A + */ double Satellite::toTime(double A,Geom::D2 d2_in) const { @@ -74,6 +58,9 @@ Satellite::toTime(double A,Geom::D2 d2_in) const return t; } +/** + * Calculate the size in d2_in with a point at A + */ double Satellite::toSize(double A,Geom::D2 d2_in) const { @@ -94,7 +81,9 @@ Satellite::toSize(double A,Geom::D2 d2_in) const return s; } - +/** + * Calculate the lenght of a satellite from a radious A input. + */ double Satellite::rad_to_len(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const { @@ -118,6 +107,9 @@ Satellite::rad_to_len(double A, boost::optional > d2_in, return len; } + /** + * Calculate the radious of a satellite from a lenght A input. + */ double Satellite::len_to_rad(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const { @@ -157,17 +149,9 @@ Satellite::len_to_rad(double A, boost::optional > d2_in, return 0; } -double -Satellite::getOpositeTime(double s, Geom::D2 d2_in) const -{ - if(s == 0){ - return 1; - } - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - double size = lenghtPart - s; - return toTime(size, d2_in); -} - +/** + * Get the time position of the satellite in d2_in + */ double Satellite::getTime(Geom::D2 d2_in) const { @@ -181,6 +165,29 @@ Satellite::getTime(Geom::D2 d2_in) const return t; } +/**. + * Get the time from a lenght A in other curve, a bolean I gived to reverse time + */ +double +Satellite::getTime(double A, bool I, Geom::D2 d2_in) const +{ + if(A == 0 && I){ + return 1; + } + if(A == 0 && !I){ + return 0; + } + if(!I){ + return toTime(A, d2_in); + } + double lenghtPart = Geom::length(d2_in, Geom::EPSILON); + A = lenghtPart - A; + return toTime(A, d2_in); +} + +/** + * Get the lenght of the satellite in d2_in + */ double Satellite::getSize(Geom::D2 d2_in) const { @@ -191,7 +198,9 @@ Satellite::getSize(Geom::D2 d2_in) const return s; } - +/** + * Get the point position of the satellite + */ Geom::Point Satellite::getPosition(Geom::D2 d2_in) const { @@ -199,6 +208,9 @@ Satellite::getPosition(Geom::D2 d2_in) const return d2_in.valueAt(t); } +/** + * Set the position of the satellite from a gived point P + */ void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) { @@ -209,6 +221,9 @@ Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) amount = A; } +/** + * Map a satellite type with gchar + */ void Satellite::setSatelliteType(gchar const * A) { @@ -216,6 +231,10 @@ Satellite::setSatelliteType(gchar const * A) satelliteType = GcharMapToSatelliteType.find(std::string(A))->second; } + +/** + * Map a gchar with satelliteType + */ gchar const * Satellite::getSatelliteTypeGchar() const { diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index f367bb7f3..d4550b922 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -1,33 +1,11 @@ /** * \file - * \brief Satellite + * \brief Satellite a per ?node/curve holder of data. *//* * Authors: * 2015 Jabier Arraiza Cenoz - * Copyright 2015 authors * - * This library is free software; you can redistribute it and/or - * modify it either under the terms of the GNU Lesser General Public - * License version 2.1 as published by the Free Software Foundation - * (the "LGPL") or, at your option, under the terms of the Mozilla - * Public License Version 1.1 (the "MPL"). If you do not alter this - * notice, a recipient may use your version of this file under either - * the MPL or the LGPL. - * - * You should have received a copy of the LGPL along with this library - * in the file COPYING-LGPL-2.1; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * You should have received a copy of the MPL along with this library - * in the file COPYING-MPL-1.1 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY - * OF ANY KIND, either express or implied. See the LGPL or the MPL for - * the specific language governing rights and limitations. + * This code is in public domain */ #ifndef LIB2GEOM_SEEN_SATELLITE_H @@ -40,6 +18,9 @@ namespace Geom { +/** + * @brief Satellite a per ?node/curve holder of data. + */ class Satellite { public: @@ -49,18 +30,21 @@ class Satellite virtual ~Satellite(); - void setPosition(Geom::Point p, Geom::D2 d2_in); - Geom::Point getPosition(Geom::D2 d2_in) const; - double getSize(Geom::D2 d2_in) const; - double getTime(Geom::D2 d2_in) const; - double getOpositeTime(double A,Geom::D2 SBasisCurve) const; double toSize(double A,Geom::D2 d2_in) const; double toTime(double A,Geom::D2 d2_in) const; double len_to_rad(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const; double rad_to_len(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const; + + double getTime(Geom::D2 d2_in) const; + double getTime(double A, bool I, Geom::D2 d2_in) const; + double getSize(Geom::D2 d2_in) const; + + void setPosition(Geom::Point p, Geom::D2 d2_in); + Geom::Point getPosition(Geom::D2 d2_in) const; + void setSatelliteType(gchar const * A); gchar const * getSatelliteTypeGchar() const; - + //TODO: maybe make after variables protected? SatelliteType satelliteType; bool isTime; bool active; -- cgit v1.2.3 From f3965759e52107c1cdcd8b7e248e5538fdaa11b6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 17:54:35 +0200 Subject: Added documentation and fix to coding style. (bzr r13645.1.66) --- src/helper/geom-pathinfo.cpp | 119 ++++++++++++------------- src/helper/geom-pathinfo.h | 52 +++++------ src/helper/geom-pointwise.cpp | 185 ++++++++++++++++++++------------------- src/helper/geom-pointwise.h | 55 ++++++------ src/helper/geom-satellite-enum.h | 22 ++--- src/helper/geom-satellite.cpp | 153 +++++++++++++++++--------------- src/helper/geom-satellite.h | 47 +++++----- 7 files changed, 326 insertions(+), 307 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 19991e879..f12004535 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -1,12 +1,12 @@ /** * \file * \brief Pathinfo store the data of a pathvector and allow get info about it - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #include #include <2geom/sbasis-to-bezier.h> @@ -17,131 +17,120 @@ namespace Geom { * @brief Pathinfo store the data of a pathvector and allow get info about it * */ -Pathinfo::Pathinfo(Piecewise > pwd2) - : _pwd2(pwd2) +Pathinfo::Pathinfo(Piecewise > pwd2) : _pwd2(pwd2) { - setPathInfo(); -}; + _setPathInfo(); +} +; -Pathinfo::~Pathinfo(){}; +Pathinfo::~Pathinfo() {} +; -void -Pathinfo::setPwd2(Piecewise > pwd2_in) +void Pathinfo::setPwd2(Piecewise > pwd2_in) { _pwd2 = pwd2_in; - setPathInfo(); + _setPathInfo(); } /** Store the base path data */ -void -Pathinfo::setPathInfo() +void Pathinfo::_setPathInfo() { - _pathInfo.clear(); - std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + data.clear(); + std::vector path_in = + path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t counter = 0; - for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { - if (path_it->empty()){ + for (PathVector::const_iterator path_it = path_in.begin(); + path_it != path_in.end(); ++path_it) { + if (path_it->empty()) { continue; } Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Curve &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } + const Curve &closingline = path_it->back_closed(); + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + curve_endit = path_it->end_open(); + } } while (curve_it1 != curve_endit) { ++curve_it1; counter++; } - if(path_it->closed()){ - _pathInfo.push_back(std::make_pair(counter-1,true)); + if (path_it->closed()) { + data.push_back(std::make_pair(counter - 1, true)); } else { - _pathInfo.push_back(std::make_pair(counter-1,false)); + data.push_back(std::make_pair(counter - 1, false)); } } } -size_t -Pathinfo::getSubPathIndex(size_t index) const +size_t Pathinfo::subPathIndex(size_t index) const { - for(size_t i = 0; i < _pathInfo.size(); i++){ - if(index <= _pathInfo[i].first){ + for (size_t i = 0; i < data.size(); i++) { + if (index <= data[i].first) { return i; } } return 0; } -size_t -Pathinfo::getLast(size_t index) const +size_t Pathinfo::last(size_t index) const { - for(size_t i = 0; i < _pathInfo.size(); i++){ - if(index <= _pathInfo[i].first){ - return _pathInfo[i].first; + for (size_t i = 0; i < data.size(); i++) { + if (index <= data[i].first) { + return data[i].first; } } return 0; } -size_t -Pathinfo::getFirst(size_t index) const +size_t Pathinfo::first(size_t index) const { - for(size_t i = 0; i < _pathInfo.size(); i++){ - if(index <= _pathInfo[i].first){ - if(i==0){ + for (size_t i = 0; i < data.size(); i++) { + if (index <= data[i].first) { + if (i == 0) { return 0; } else { - return _pathInfo[i-1].first + 1; + return data[i - 1].first + 1; } } } return 0; } -boost::optional -Pathinfo::getPrevious(size_t index) const +boost::optional Pathinfo::previous(size_t index) const { - if(getFirst(index) == index && getIsClosed(index)){ - return getLast(index); + if (first(index) == index && isClosed(index)) { + return last(index); } - if(getFirst(index) == index && !getIsClosed(index)){ + if (first(index) == index && !isClosed(index)) { return boost::none; } return index - 1; } -boost::optional -Pathinfo::getNext(size_t index) const +boost::optional Pathinfo::next(size_t index) const { - if(getLast(index) == index && getIsClosed(index)){ - return getFirst(index); + if (last(index) == index && isClosed(index)) { + return first(index); } - if(getLast(index) == index && !getIsClosed(index)){ + if (last(index) == index && !isClosed(index)) { return boost::none; } return index + 1; } -bool -Pathinfo::getIsClosed(size_t index) const +bool Pathinfo::isClosed(size_t index) const { - for(size_t i = 0; i < _pathInfo.size(); i++){ - if(index <= _pathInfo[i].first){ - return _pathInfo[i].second; + for (size_t i = 0; i < data.size(); i++) { + if (index <= data[i].first) { + return data[i].second; } } return false; } -std::vector > -Pathinfo::getPathInfo() const -{ - return _pathInfo; -} - }; // namespace Geom /* @@ -153,4 +142,6 @@ Pathinfo::getPathInfo() const fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 9a40a4f20..c9d8e2862 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -1,12 +1,12 @@ /** * \file * \brief Pathinfo store the data of a pathvector and allow get info about it - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #ifndef SEEN_GEOM_PATHINFO_H #define SEEN_GEOM_PATHINFO_H @@ -20,29 +20,27 @@ namespace Geom { * @brief Pathinfo store the data of a pathvector and allow get info about it * */ -class Pathinfo -{ - public: - Pathinfo(Piecewise > pwd2); - virtual ~Pathinfo(); - void setPwd2(Piecewise > pwd2_in); - size_t getSubPathIndex(size_t index) const; - size_t getLast(size_t index) const; - size_t getFirst(size_t index) const; - boost::optional getPrevious(size_t index) const; - boost::optional getNext(size_t index) const; - bool getIsClosed(size_t index) const; - std::vector > getPathInfo() const; - - private: - void setPathInfo(); - Piecewise > _pwd2; - std::vector > _pathInfo; +class Pathinfo { +public: + Pathinfo(Piecewise > pwd2); + virtual ~Pathinfo(); + void setPwd2(Piecewise > pwd2_in); + size_t subPathIndex(size_t index) const; + size_t last(size_t index) const; + size_t first(size_t index) const; + boost::optional previous(size_t index) const; + boost::optional next(size_t index) const; + bool isClosed(size_t index) const; + std::vector > pathInfo() const; + std::vector > data; + +private: + void _setPathInfo(); + Piecewise > _pwd2; }; } //namespace Geom - #endif //SEEN_GEOM_PATHINFO_H /* Local Variables: @@ -53,4 +51,6 @@ class Pathinfo fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 9e65685ae..cfe93311c 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -1,23 +1,22 @@ /** * \file * \brief Pointwise a class to manage a vector of satellites per piecewise curve - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #include - namespace Geom { /** * @brief Pointwise a class to manage a vector of satellites per piecewise curve * * For the moment is a per curve satellite holder not per node. This is ok for - * much cases but not a real node satellite on open paths + * much cases but not a real node satellite on open paths * To implement this we can: * add extra satellite in open paths, and take notice of current open paths * or put extra satellites on back for each open subpath @@ -26,35 +25,34 @@ namespace Geom { * optional satellites, and remove the active variable in satellites. * */ -Pointwise::Pointwise(Piecewise > pwd2, std::vector satellites) - : _pwd2(pwd2), _satellites(satellites), _pathInfo(pwd2) +Pointwise::Pointwise(Piecewise > pwd2, + std::vector satellites) + : _pwd2(pwd2), _satellites(satellites), _path_info(pwd2) { setStart(); -}; +} +; -Pointwise::~Pointwise(){}; +Pointwise::~Pointwise() {} +; -Piecewise > -Pointwise::getPwd2() const +Piecewise > Pointwise::getPwd2() const { return _pwd2; } -void -Pointwise::setPwd2(Piecewise > pwd2_in) +void Pointwise::setPwd2(Piecewise > pwd2_in) { _pwd2 = pwd2_in; - _pathInfo.setPwd2(_pwd2); + _path_info.setPwd2(_pwd2); } -std::vector -Pointwise::getSatellites() const +std::vector Pointwise::getSatellites() const { return _satellites; } -void -Pointwise::setSatellites(std::vector sats) +void Pointwise::setSatellites(std::vector sats) { _satellites = sats; setStart(); @@ -62,14 +60,13 @@ Pointwise::setSatellites(std::vector sats) /** Update the start satellite on ope/closed paths. */ -void -Pointwise::setStart() +void Pointwise::setStart() { - std::vector > pathInfo = _pathInfo.getPathInfo(); - for(size_t i = 0; i < pathInfo.size(); i++){ - size_t firstNode = _pathInfo.getFirst(pathInfo[i].first); - size_t lastNode = _pathInfo.getLast(pathInfo[i].first); - if(!_pathInfo.getIsClosed(lastNode)){ + std::vector > path_info = _path_info.data; + for (size_t i = 0; i < path_info.size(); i++) { + size_t firstNode = _path_info.first(path_info[i].first); + size_t lastNode = _path_info.last(path_info[i].first); + if (!_path_info.isClosed(lastNode)) { _satellites[firstNode].hidden = true; _satellites[firstNode].active = false; } else { @@ -81,30 +78,29 @@ Pointwise::setStart() /** Fired when a path is modified. */ -void -Pointwise::recalculate_for_new_pwd2(Piecewise > A) +void Pointwise::recalculateForNewPwd2(Piecewise > A) { - if( _pwd2.size() > A.size()){ - pwd2_sustract(A); - } else if (_pwd2.size() < A.size()){ - pwd2_append(A); + if (_pwd2.size() > A.size()) { + pwd2Sustract(A); + } else if (_pwd2.size() < A.size()) { + pwd2Append(A); } } /** Some nodes/subpaths are removed. */ -void -Pointwise::pwd2_sustract(Piecewise > A) +void Pointwise::pwd2Sustract(Piecewise > A) { size_t counter = 0; std::vector sats; Piecewise > pwd2 = _pwd2; setPwd2(A); - for(size_t i = 0; i < _satellites.size(); i++){ - if(_pathInfo.getLast(i-counter) < i-counter || !are_near(pwd2[i].at0(),A[i-counter].at0(),0.001)){ + for (size_t i = 0; i < _satellites.size(); i++) { + if (_path_info.last(i - counter) < i - counter || + !are_near(pwd2[i].at0(), A[i - counter].at0(), 0.001)) { counter++; } else { - sats.push_back(_satellites[i-counter]); + sats.push_back(_satellites[i - counter]); } } setSatellites(sats); @@ -112,76 +108,83 @@ Pointwise::pwd2_sustract(Piecewise > A) /** Append nodes/subpaths to current pointwise */ -void -Pointwise::pwd2_append(Piecewise > A) +void Pointwise::pwd2Append(Piecewise > A) { size_t counter = 0; std::vector sats; bool reversed = false; bool reorder = false; - for(size_t i = 0; i < A.size(); i++){ - size_t first = _pathInfo.getFirst(i-counter); - size_t last = _pathInfo.getLast(i-counter); - //Check for subpath closed. If a subpath is closed, is not reversed or moved to back - _pathInfo.setPwd2(A); - size_t subpathAIndex = _pathInfo.getSubPathIndex(i); - _pathInfo.setPwd2(_pwd2); - bool changedSubpath = false; - if(_pwd2.size() <= i-counter){ - changedSubpath = false; + for (size_t i = 0; i < A.size(); i++) { + size_t first = _path_info.first(i - counter); + size_t last = _path_info.last(i - counter); + //Check for subpath closed. If a subpath is closed, is not reversed or moved + //to back + _path_info.setPwd2(A); + size_t new_subpath_index = _path_info.subPathIndex(i); + _path_info.setPwd2(_pwd2); + bool subpath_is_changed = false; + if (_pwd2.size() <= i - counter) { + subpath_is_changed = false; } else { - changedSubpath = subpathAIndex != _pathInfo.getSubPathIndex(i-counter); + subpath_is_changed = new_subpath_index != _path_info.subPathIndex(i - counter); } - if(!reorder && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ + if (!reorder && first == i - counter && + !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && + !subpath_is_changed) { //Send the modified subpath to back - subpath_to_back(_pathInfo.getSubPathIndex(first)); + subpathToBack(_path_info.subPathIndex(first)); reorder = true; i--; continue; } - if(!reversed && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ - subpath_reverse(first, last); + if (!reversed && first == i - counter && + !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && + !subpath_is_changed) { + subpathReverse(first, last); reversed = true; } - if(_pwd2.size() <= i-counter || !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ + if (_pwd2.size() <= i - counter || + !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001)) { counter++; bool active = true; bool hidden = false; - bool isTime = _satellites[0].isTime; + bool is_time = _satellites[0].isTime; bool mirror_knots = _satellites[0].hasMirror; double amount = 0.0; double degrees = 0.0; int steps = 0; - Satellite sat(_satellites[0].satelliteType, isTime, active, mirror_knots, hidden, amount, degrees, steps); + Satellite sat(_satellites[0].satelliteType, is_time, active, mirror_knots, + hidden, amount, degrees, steps); sats.push_back(sat); } else { - sats.push_back(_satellites[i-counter]); + sats.push_back(_satellites[i - counter]); } } setPwd2(A); setSatellites(sats); } - -void -Pointwise::subpath_to_back(size_t subpath){ - std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); - size_t nSubpath = 0; +void Pointwise::subpathToBack(size_t subpath) +{ + std::vector path_in = + path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); + size_t subpath_counter = 0; size_t counter = 0; std::vector tmp_path; - Geom::Path rev; - for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { - if (path_it->empty()){ + Geom::Path to_back; + for (PathVector::const_iterator path_it = path_in.begin(); + path_it != path_in.end(); ++path_it) { + if (path_it->empty()) { continue; } Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); - const Curve &closingline = path_it->back_closed(); + const Curve &closingline = path_it->back_closed(); if (are_near(closingline.initialPoint(), closingline.finalPoint())) { curve_endit = path_it->end_open(); } while (curve_it1 != curve_endit) { - if(nSubpath == subpath){ + if (subpath_counter == subpath) { _satellites.push_back(_satellites[counter]); _satellites.erase(_satellites.begin() + counter); } else { @@ -189,43 +192,45 @@ Pointwise::subpath_to_back(size_t subpath){ } ++curve_it1; } - if(nSubpath == subpath){ - rev = *path_it; + if (subpath_counter == subpath) { + to_back = *path_it; } else { tmp_path.push_back(*path_it); } - nSubpath++; + subpath_counter++; } - tmp_path.push_back(rev); - setPwd2(remove_short_cuts(paths_to_pw(tmp_path),0.01)); + tmp_path.push_back(to_back); + setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); } -void -Pointwise::subpath_reverse(size_t start,size_t end){ - start ++; - for(size_t i = end; i >= start; i--){ +void Pointwise::subpathReverse(size_t start, size_t end) +{ + start++; + for (size_t i = end; i >= start; i--) { _satellites.push_back(_satellites[i]); _satellites.erase(_satellites.begin() + i); } - std::vector path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + std::vector path_in = + path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t counter = 0; - size_t nSubpath = 0; - size_t subpath = _pathInfo.getSubPathIndex(start); + size_t subpath_counter = 0; + size_t subpath = _path_info.subPathIndex(start); std::vector tmp_path; Geom::Path rev; - for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { - if (path_it->empty()){ + for (PathVector::const_iterator path_it = path_in.begin(); + path_it != path_in.end(); ++path_it) { + if (path_it->empty()) { continue; } - counter ++; - if(nSubpath == subpath){ + counter++; + if (subpath_counter == subpath) { tmp_path.push_back(path_it->reverse()); } else { tmp_path.push_back(*path_it); } - nSubpath++; + subpath_counter++; } - setPwd2(remove_short_cuts(paths_to_pw(tmp_path),0.01)); + setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); } } // namespace Geom @@ -238,4 +243,6 @@ Pointwise::subpath_reverse(size_t start,size_t end){ fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 59ed4d1aa..3ce1ca75a 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -1,12 +1,12 @@ /** * \file * \brief Pointwise a class to manage a vector of satellites per piecewise curve - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #ifndef SEEN_GEOM_POINTWISE_H #define SEEN_GEOM_POINTWISE_H @@ -26,7 +26,7 @@ namespace Geom { * @brief Pointwise a class to manage a vector of satellites per piecewise curve * * For the moment is a per curve satellite holder not per node. This is ok for - * much cases but not a real node satellite on open paths + * much cases but not a real node satellite on open paths * To implement this we can: * add extra satellite in open paths, and take notice of current open paths * or put extra satellites on back for each open subpath @@ -35,30 +35,29 @@ namespace Geom { * optional satellites, and remove the active variable in satellites. * */ -class Pointwise -{ - public: - Pointwise(Piecewise > pwd2, std::vector satellites); - virtual ~Pointwise(); +class Pointwise { +public: + Pointwise(Piecewise > pwd2, std::vector satellites); + virtual ~Pointwise(); - Piecewise > getPwd2() const; - void setPwd2(Piecewise > pwd2_in); + Piecewise > getPwd2() const; + void setPwd2(Piecewise > pwd2_in); - std::vector getSatellites() const; - void setSatellites(std::vector sats); + std::vector getSatellites() const; + void setSatellites(std::vector sats); - void setStart(); + void setStart(); - void recalculate_for_new_pwd2(Piecewise > A); - void pwd2_sustract(Piecewise > A); - void pwd2_append(Piecewise > A); - void subpath_to_back(size_t subpath); - void subpath_reverse(size_t start,size_t end); + void recalculateForNewPwd2(Piecewise > A); + void pwd2Sustract(Piecewise > A); + void pwd2Append(Piecewise > A); + void subpathToBack(size_t subpath); + void subpathReverse(size_t start, size_t end); - private: - Piecewise > _pwd2; - std::vector _satellites; - Pathinfo _pathInfo; +private: + Piecewise > _pwd2; + std::vector _satellites; + Pathinfo _path_info; }; } // end namespace Geom @@ -73,4 +72,6 @@ class Pointwise fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/helper/geom-satellite-enum.h b/src/helper/geom-satellite-enum.h index 4680ce2f6..d82cdabe0 100644 --- a/src/helper/geom-satellite-enum.h +++ b/src/helper/geom-satellite-enum.h @@ -4,23 +4,23 @@ /** * \file * \brief Satellite types enum - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #include "util/enums.h" namespace Geom { enum SatelliteType { - F=0, //Fillet - IF, //Inverse Fillet - C, //Chamfer - IC, //Inverse Chamfer - KO // Invalid Satellite) + F = 0, //Fillet + IF, //Inverse Fillet + C, //Chamfer + IC, //Inverse Chamfer + KO // Invalid Satellite) }; } //namespace Geom diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 6304b4148..efe6bb37a 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -1,12 +1,12 @@ /** * \file * \brief Satellite a per ?node/curve holder of data. - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #include #include <2geom/curve.h> @@ -17,26 +17,31 @@ #include <2geom/ray.h> #include - namespace Geom { /** * @brief Satellite a per ?node/curve holder of data. */ -Satellite::Satellite(){}; +Satellite::Satellite() {} +; -Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps) - : satelliteType(satelliteType), isTime(isTime), active(active), hasMirror(hasMirror), hidden(hidden), amount(amount), angle(angle), steps(steps){}; +Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active, + bool hasMirror, bool hidden, double amount, double angle, + size_t steps) + : satelliteType(satelliteType), isTime(isTime), active(active), + hasMirror(hasMirror), hidden(hidden), amount(amount), angle(angle), + steps(steps) {} +; -Satellite::~Satellite() {}; +Satellite::~Satellite() {} +; /** * Calculate the time in d2_in with a size of A */ -double -Satellite::toTime(double A,Geom::D2 d2_in) const +double Satellite::toTime(double A, Geom::D2 d2_in) const { - if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { return 0; } double t = 0; @@ -61,10 +66,9 @@ Satellite::toTime(double A,Geom::D2 d2_in) const /** * Calculate the size in d2_in with a point at A */ -double -Satellite::toSize(double A,Geom::D2 d2_in) const +double Satellite::toSize(double A, Geom::D2 d2_in) const { - if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { return 0; } double s = 0; @@ -84,66 +88,78 @@ Satellite::toSize(double A,Geom::D2 d2_in) const /** * Calculate the lenght of a satellite from a radious A input. */ -double -Satellite::rad_to_len(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const +double Satellite::radToLen( + double A, boost::optional > d2_in, + Geom::D2 d2_out, + boost::optional previousSatellite) const { double len = 0; - if(d2_in && previousSatellite){ - Piecewise > offset_curve0 = Piecewise >(*d2_in)+rot90(unitVector(derivative(*d2_in)))*(A); - Piecewise > offset_curve1 = Piecewise >(d2_out)+rot90(unitVector(derivative(d2_out)))*(A); + if (d2_in && previousSatellite) { + Piecewise > offset_curve0 = + Piecewise >(*d2_in) + + rot90(unitVector(derivative(*d2_in))) * (A); + Piecewise > offset_curve1 = + Piecewise >(d2_out) + + rot90(unitVector(derivative(d2_out))) * (A); Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; Geom::Crossings cs = Geom::crossings(p0, p1); - if(cs.size() > 0){ - Point cp =p0(cs[0].ta); + if (cs.size() > 0) { + Point cp = p0(cs[0].ta); double p0pt = nearest_point(cp, d2_out); - len = (*previousSatellite).toSize(p0pt,d2_out); + len = (*previousSatellite).toSize(p0pt, d2_out); } else { - if(A > 0){ - len = rad_to_len(A * -1, *d2_in, d2_out, previousSatellite); + if (A > 0) { + len = radToLen(A * -1, *d2_in, d2_out, previousSatellite); } } } return len; } - /** - * Calculate the radious of a satellite from a lenght A input. - */ -double -Satellite::len_to_rad(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const +/** +* Calculate the radious of a satellite from a lenght A input. +*/ +double Satellite::lenToRad( + double A, boost::optional > d2_in, + Geom::D2 d2_out, + boost::optional previousSatellite) const { - if(d2_in && previousSatellite){ - double time_in = (*previousSatellite).getOpositeTime(A, *d2_in); - double time_out = (*previousSatellite).toTime(A,d2_out); + if (d2_in && previousSatellite) { + double time_in = (*previousSatellite).time(A, true, *d2_in); + double time_out = (*previousSatellite).toTime(A, d2_out); Geom::Point startArcPoint = (*d2_in).valueAt(time_in); Geom::Point endArcPoint = d2_out.valueAt(time_out); Piecewise > u; u.push_cut(0); u.push(*d2_in, 1); - Geom::Curve * C = path_from_piecewise(u, 0.1)[0][0].duplicate(); + Geom::Curve *C = path_from_piecewise(u, 0.1)[0][0].duplicate(); Piecewise > u2; u2.push_cut(0); u2.push(d2_out, 1); - Geom::Curve * D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); + Geom::Curve *D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); Curve *knotCurve1 = C->portion(0, time_in); Curve *knotCurve2 = D->portion(time_out, 1); - Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); + Geom::CubicBezier const *cubic1 = + dynamic_cast(&*knotCurve1); Ray ray1(startArcPoint, (*d2_in).valueAt(1)); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } - Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); + Geom::CubicBezier const *cubic2 = + dynamic_cast(&*knotCurve2); Ray ray2(d2_out.valueAt(0), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); } - bool ccwToggle = cross((*d2_in).valueAt(1) - startArcPoint, endArcPoint - startArcPoint) < 0; - double distanceArc = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint)); + bool ccwToggle = cross((*d2_in).valueAt(1) - startArcPoint, + endArcPoint - startArcPoint) < 0; + double distanceArc = + Geom::distance(startArcPoint, middle_point(startArcPoint, endArcPoint)); double angleBetween = angle_between(ray1, ray2, ccwToggle); - double divisor = std::sin(angleBetween/2.0); - if(divisor > 0){ - return distanceArc/divisor; + double divisor = std::sin(angleBetween / 2.0); + if (divisor > 0) { + return distanceArc / divisor; } } return 0; @@ -152,14 +168,13 @@ Satellite::len_to_rad(double A, boost::optional > d2_in, /** * Get the time position of the satellite in d2_in */ -double -Satellite::getTime(Geom::D2 d2_in) const +double Satellite::time(Geom::D2 d2_in) const { double t = amount; - if(!isTime){ + if (!isTime) { t = toTime(t, d2_in); } - if(t > 1){ + if (t > 1) { t = 1; } return t; @@ -168,16 +183,16 @@ Satellite::getTime(Geom::D2 d2_in) const /**. * Get the time from a lenght A in other curve, a bolean I gived to reverse time */ -double -Satellite::getTime(double A, bool I, Geom::D2 d2_in) const +double Satellite::time(double A, bool I, + Geom::D2 d2_in) const { - if(A == 0 && I){ + if (A == 0 && I) { return 1; } - if(A == 0 && !I){ + if (A == 0 && !I) { return 0; } - if(!I){ + if (!I) { return toTime(A, d2_in); } double lenghtPart = Geom::length(d2_in, Geom::EPSILON); @@ -188,11 +203,10 @@ Satellite::getTime(double A, bool I, Geom::D2 d2_in) const /** * Get the lenght of the satellite in d2_in */ -double -Satellite::getSize(Geom::D2 d2_in) const +double Satellite::size(Geom::D2 d2_in) const { double s = amount; - if(isTime){ + if (isTime) { s = toSize(s, d2_in); } return s; @@ -201,21 +215,19 @@ Satellite::getSize(Geom::D2 d2_in) const /** * Get the point position of the satellite */ -Geom::Point -Satellite::getPosition(Geom::D2 d2_in) const +Geom::Point Satellite::getPosition(Geom::D2 d2_in) const { - double t = getTime(d2_in); + double t = time(d2_in); return d2_in.valueAt(t); } /** * Set the position of the satellite from a gived point P */ -void -Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) +void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) { double A = Geom::nearest_point(p, d2_in); - if(!isTime){ + if (!isTime) { A = toSize(A, d2_in); } amount = A; @@ -224,21 +236,20 @@ Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) /** * Map a satellite type with gchar */ -void -Satellite::setSatelliteType(gchar const * A) +void Satellite::setSatelliteType(gchar const *A) { - std::map GcharMapToSatelliteType = boost::assign::map_list_of("F", F)("IF", IF)("C",C)("IC",IC)("KO",KO); + std::map GcharMapToSatelliteType = + boost::assign::map_list_of("F", F)("IF", IF)("C", C)("IC", IC)("KO", KO); satelliteType = GcharMapToSatelliteType.find(std::string(A))->second; } - /** * Map a gchar with satelliteType */ -gchar const * -Satellite::getSatelliteTypeGchar() const +gchar const *Satellite::getSatelliteTypeGchar() const { - std::map SatelliteTypeToGcharMap = boost::assign::map_list_of(F, "F")(IF, "IF")(C,"C")(IC,"IC")(KO,"KO"); + std::map SatelliteTypeToGcharMap = + boost::assign::map_list_of(F, "F")(IF, "IF")(C, "C")(IC, "IC")(KO, "KO"); return SatelliteTypeToGcharMap.at(satelliteType); } @@ -253,4 +264,6 @@ Satellite::getSatelliteTypeGchar() const fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index d4550b922..df54819fd 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -1,12 +1,12 @@ /** * \file * \brief Satellite a per ?node/curve holder of data. - *//* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz + * + * This code is in public domain + */ #ifndef LIB2GEOM_SEEN_SATELLITE_H #define LIB2GEOM_SEEN_SATELLITE_H @@ -21,29 +21,34 @@ namespace Geom { /** * @brief Satellite a per ?node/curve holder of data. */ -class Satellite -{ - public: +class Satellite { +public: Satellite(); - Satellite(SatelliteType satelliteType, bool isTime, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps); + Satellite(SatelliteType satelliteType, bool isTime, bool active, + bool hasMirror, bool hidden, double amount, double angle, + size_t steps); virtual ~Satellite(); - double toSize(double A,Geom::D2 d2_in) const; - double toTime(double A,Geom::D2 d2_in) const; - double len_to_rad(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const; - double rad_to_len(double A, boost::optional > d2_in, Geom::D2 d2_out, boost::optional previousSatellite) const; + double toSize(double A, Geom::D2 d2_in) const; + double toTime(double A, Geom::D2 d2_in) const; + double lenToRad(double A, boost::optional > d2_in, + Geom::D2 d2_out, + boost::optional previousSatellite) const; + double radToLen(double A, boost::optional > d2_in, + Geom::D2 d2_out, + boost::optional previousSatellite) const; - double getTime(Geom::D2 d2_in) const; - double getTime(double A, bool I, Geom::D2 d2_in) const; - double getSize(Geom::D2 d2_in) const; + double time(Geom::D2 d2_in) const; + double time(double A, bool I, Geom::D2 d2_in) const; + double size(Geom::D2 d2_in) const; void setPosition(Geom::Point p, Geom::D2 d2_in); Geom::Point getPosition(Geom::D2 d2_in) const; - void setSatelliteType(gchar const * A); - gchar const * getSatelliteTypeGchar() const; + void setSatelliteType(gchar const *A); + gchar const *getSatelliteTypeGchar() const; //TODO: maybe make after variables protected? SatelliteType satelliteType; bool isTime; @@ -68,4 +73,6 @@ class Satellite fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : -- cgit v1.2.3 From 323fc5ae45fd8374de4561d0771f6b9d5cd3e87a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 3 Apr 2015 01:46:44 +0200 Subject: Adding suport for duplicate nodes Allow degenrate curves Show helper path whith original path (bzr r13645.1.70) --- src/helper/geom-pointwise.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index cfe93311c..261d2bff4 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -123,28 +123,26 @@ void Pointwise::pwd2Append(Piecewise > A) size_t new_subpath_index = _path_info.subPathIndex(i); _path_info.setPwd2(_pwd2); bool subpath_is_changed = false; + bool not_exist = ; if (_pwd2.size() <= i - counter) { subpath_is_changed = false; } else { subpath_is_changed = new_subpath_index != _path_info.subPathIndex(i - counter); } - if (!reorder && first == i - counter && - !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && - !subpath_is_changed) { + if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && !subpath_is_changed) { //Send the modified subpath to back subpathToBack(_path_info.subPathIndex(first)); reorder = true; i--; continue; } - if (!reversed && first == i - counter && - !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && - !subpath_is_changed) { + if (!reversed && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && !subpath_is_changed) { subpathReverse(first, last); reversed = true; } - if (_pwd2.size() <= i - counter || - !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001)) { + if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) || + /*this condition for duplicate node Shift+d*/(i > 0 && are_near(A[i - 1].at0(), A[i].at0(), 0.001) && + !are_near(_pwd2[i - counter].at0(), _pwd2[i - counter - 1].at0(), 0.001))){ counter++; bool active = true; bool hidden = false; -- cgit v1.2.3 From 04218b26ae0a10bf9e64721fb0dd789f024afca5 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 3 Apr 2015 16:10:46 +0200 Subject: Update pathinfo class to allow piecewise and pathvector as input. Add a method on pointwise to allow update if degenerated curves in new path, not noticed by piecewises (bzr r13645.1.72) --- src/helper/geom-pathinfo.cpp | 42 +++++++++++++++++++++-------- src/helper/geom-pathinfo.h | 12 ++++++--- src/helper/geom-pointwise.cpp | 62 ++++++++++++++++++++++++++++++++++++++----- src/helper/geom-pointwise.h | 3 ++- 4 files changed, 97 insertions(+), 22 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index f12004535..f9d4e5dbb 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -19,25 +19,40 @@ namespace Geom { */ Pathinfo::Pathinfo(Piecewise > pwd2) : _pwd2(pwd2) { - _setPathInfo(); + _setPathInfo(pwd2); +} +; +Pathinfo::Pathinfo(Geom::PathVector path_vector) : _path_vector(path_vector) +{ + _setPathInfo(path_vector); } ; Pathinfo::~Pathinfo() {} ; -void Pathinfo::setPwd2(Piecewise > pwd2_in) +void Pathinfo::setPwd2(Piecewise > pwd2) +{ + _pwd2 = pwd2; + _setPathInfo(pwd2); +} + +void Pathinfo::setPathVector(Geom::PathVector path_vector) { - _pwd2 = pwd2_in; - _setPathInfo(); + _path_vector = path_vector; + _setPathInfo(path_vector); } +void Pathinfo::_setPathInfo(Piecewise > pwd2) +{ + _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); +} /** Store the base path data */ -void Pathinfo::_setPathInfo() +void Pathinfo::_setPathInfo(Geom::PathVector path_vector) { data.clear(); - std::vector path_in = + Geom::PathVector path_in = path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t counter = 0; for (PathVector::const_iterator path_it = path_in.begin(); @@ -65,6 +80,11 @@ void Pathinfo::_setPathInfo() } } +size_t Pathinfo::numberCurves() const +{ + return data.back().first; +} + size_t Pathinfo::subPathIndex(size_t index) const { for (size_t i = 0; i < data.size(); i++) { @@ -101,10 +121,10 @@ size_t Pathinfo::first(size_t index) const boost::optional Pathinfo::previous(size_t index) const { - if (first(index) == index && isClosed(index)) { + if (first(index) == index && closed(index)) { return last(index); } - if (first(index) == index && !isClosed(index)) { + if (first(index) == index && !closed(index)) { return boost::none; } return index - 1; @@ -112,16 +132,16 @@ boost::optional Pathinfo::previous(size_t index) const boost::optional Pathinfo::next(size_t index) const { - if (last(index) == index && isClosed(index)) { + if (last(index) == index && closed(index)) { return first(index); } - if (last(index) == index && !isClosed(index)) { + if (last(index) == index && !closed(index)) { return boost::none; } return index + 1; } -bool Pathinfo::isClosed(size_t index) const +bool Pathinfo::closed(size_t index) const { for (size_t i = 0; i < data.size(); i++) { if (index <= data[i].first) { diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index c9d8e2862..c41d92e7a 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -23,20 +23,24 @@ namespace Geom { class Pathinfo { public: Pathinfo(Piecewise > pwd2); + Pathinfo(Geom::PathVector path_vector); virtual ~Pathinfo(); - void setPwd2(Piecewise > pwd2_in); + void setPwd2(Piecewise > pwd2); + void setPathVector(Geom::PathVector path_vector); + size_t numberCurves() const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; size_t first(size_t index) const; boost::optional previous(size_t index) const; boost::optional next(size_t index) const; - bool isClosed(size_t index) const; - std::vector > pathInfo() const; + bool closed(size_t index) const; std::vector > data; private: - void _setPathInfo(); + void _setPathInfo(Geom::PathVector path_vector); + void _setPathInfo(Piecewise > pwd2); Piecewise > _pwd2; + Geom::PathVector _path_vector; }; } //namespace Geom diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 261d2bff4..714573ad5 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -66,7 +66,7 @@ void Pointwise::setStart() for (size_t i = 0; i < path_info.size(); i++) { size_t firstNode = _path_info.first(path_info[i].first); size_t lastNode = _path_info.last(path_info[i].first); - if (!_path_info.isClosed(lastNode)) { + if (!_path_info.closed(lastNode)) { _satellites[firstNode].hidden = true; _satellites[firstNode].active = false; } else { @@ -78,12 +78,14 @@ void Pointwise::setStart() /** Fired when a path is modified. */ -void Pointwise::recalculateForNewPwd2(Piecewise > A) +void Pointwise::recalculateForNewPwd2(Piecewise > A, Geom::PathVector B) { if (_pwd2.size() > A.size()) { pwd2Sustract(A); } else if (_pwd2.size() < A.size()) { pwd2Append(A); + } else { + insertDegenerateSatellites(A,B); } } @@ -123,7 +125,6 @@ void Pointwise::pwd2Append(Piecewise > A) size_t new_subpath_index = _path_info.subPathIndex(i); _path_info.setPwd2(_pwd2); bool subpath_is_changed = false; - bool not_exist = ; if (_pwd2.size() <= i - counter) { subpath_is_changed = false; } else { @@ -140,9 +141,8 @@ void Pointwise::pwd2Append(Piecewise > A) subpathReverse(first, last); reversed = true; } - if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) || - /*this condition for duplicate node Shift+d*/(i > 0 && are_near(A[i - 1].at0(), A[i].at0(), 0.001) && - !are_near(_pwd2[i - counter].at0(), _pwd2[i - counter - 1].at0(), 0.001))){ + + if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001)){ counter++; bool active = true; bool hidden = false; @@ -231,6 +231,56 @@ void Pointwise::subpathReverse(size_t start, size_t end) setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); } + +/** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. + */ +void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathVector B) +{ + size_t size_A = A.size(); + _path_info.setPathVector(B); + size_t size_B = _path_info.numberCurves(); + size_t satellite_gap = size_B - size_A; + if (satellite_gap == 0){ + return; + } + size_t counter = 0; + size_t counter_added = 0; + for (PathVector::const_iterator path_it = B.begin(); + path_it != B.end(); ++path_it) { + if (path_it->empty()) { + continue; + } + Geom::Path::const_iterator curve_it1 = path_it->begin(); + Geom::Path::const_iterator curve_endit = path_it->end_default(); + if (path_it->closed()) { + const Curve &closingline = path_it->back_closed(); + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + curve_endit = path_it->end_open(); + } + } + while (curve_it1 != curve_endit) { + if ((*curve_it1).isDegenerate() && counter_added < satellite_gap){ + counter_added++; + bool active = true; + bool hidden = false; + bool is_time = _satellites[0].isTime; + bool mirror_knots = _satellites[0].hasMirror; + double amount = 0.0; + double degrees = 0.0; + int steps = 0; + Satellite sat(_satellites[0].satelliteType, is_time, active, mirror_knots, + hidden, amount, degrees, steps); + _satellites.insert(_satellites.begin() + counter ,sat); + } + ++curve_it1; + counter++; + } + } + + _path_info.setPwd2(A); + setPwd2(A); +} + } // namespace Geom /* Local Variables: diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 3ce1ca75a..48ee36255 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -48,11 +48,12 @@ public: void setStart(); - void recalculateForNewPwd2(Piecewise > A); + void recalculateForNewPwd2(Piecewise > A, Geom::PathVector B); void pwd2Sustract(Piecewise > A); void pwd2Append(Piecewise > A); void subpathToBack(size_t subpath); void subpathReverse(size_t start, size_t end); + void insertDegenerateSatellites(Piecewise > A, Geom::PathVector B); private: Piecewise > _pwd2; -- cgit v1.2.3 From 49ec02c315e6e5068b1ad395c01db2b536dd9b9e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 3 Apr 2015 21:20:55 +0200 Subject: Updated Pathinfo to discrimine degenerate curves optionaly. Fixed redundant data in are_near from pointwise Fixed Fillet-Chamfer lpe to allow duplicate nodes (bzr r13645.1.73) --- src/helper/geom-pathinfo.cpp | 14 +++++++++----- src/helper/geom-pathinfo.h | 6 +++--- src/helper/geom-pointwise.cpp | 10 +++++----- 3 files changed, 17 insertions(+), 13 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index f9d4e5dbb..a37c0e475 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -22,9 +22,9 @@ Pathinfo::Pathinfo(Piecewise > pwd2) : _pwd2(pwd2) _setPathInfo(pwd2); } ; -Pathinfo::Pathinfo(Geom::PathVector path_vector) : _path_vector(path_vector) +Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate) : _path_vector(path_vector) { - _setPathInfo(path_vector); + _setPathInfo(path_vector, skip_degenerate); } ; @@ -37,10 +37,10 @@ void Pathinfo::setPwd2(Piecewise > pwd2) _setPathInfo(pwd2); } -void Pathinfo::setPathVector(Geom::PathVector path_vector) +void Pathinfo::setPathVector(Geom::PathVector path_vector, bool skip_degenerate) { _path_vector = path_vector; - _setPathInfo(path_vector); + _setPathInfo(path_vector, skip_degenerate); } void Pathinfo::_setPathInfo(Piecewise > pwd2) @@ -49,7 +49,7 @@ void Pathinfo::_setPathInfo(Piecewise > pwd2) } /** Store the base path data */ -void Pathinfo::_setPathInfo(Geom::PathVector path_vector) +void Pathinfo::_setPathInfo(Geom::PathVector path_vector, bool skip_degenerate) { data.clear(); Geom::PathVector path_in = @@ -69,6 +69,10 @@ void Pathinfo::_setPathInfo(Geom::PathVector path_vector) } } while (curve_it1 != curve_endit) { + if(curve_it1->isDegenerate() && skip_degenerate ){ + ++curve_it1; + continue; + } ++curve_it1; counter++; } diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index c41d92e7a..021fcca2b 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -23,10 +23,10 @@ namespace Geom { class Pathinfo { public: Pathinfo(Piecewise > pwd2); - Pathinfo(Geom::PathVector path_vector); + Pathinfo(Geom::PathVector path_vector, bool skip_degenerate = false); virtual ~Pathinfo(); void setPwd2(Piecewise > pwd2); - void setPathVector(Geom::PathVector path_vector); + void setPathVector(Geom::PathVector path_vector, bool skip_degenerate = false); size_t numberCurves() const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; @@ -37,8 +37,8 @@ public: std::vector > data; private: - void _setPathInfo(Geom::PathVector path_vector); void _setPathInfo(Piecewise > pwd2); + void _setPathInfo(Geom::PathVector path_vector, bool skip_degenerate = false); Piecewise > _pwd2; Geom::PathVector _path_vector; }; diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 714573ad5..f68c9b13f 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -99,7 +99,7 @@ void Pointwise::pwd2Sustract(Piecewise > A) setPwd2(A); for (size_t i = 0; i < _satellites.size(); i++) { if (_path_info.last(i - counter) < i - counter || - !are_near(pwd2[i].at0(), A[i - counter].at0(), 0.001)) { + !are_near(pwd2[i].at0(), A[i - counter].at0())) { counter++; } else { sats.push_back(_satellites[i - counter]); @@ -130,19 +130,19 @@ void Pointwise::pwd2Append(Piecewise > A) } else { subpath_is_changed = new_subpath_index != _path_info.subPathIndex(i - counter); } - if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && !subpath_is_changed) { + if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { //Send the modified subpath to back subpathToBack(_path_info.subPathIndex(first)); reorder = true; i--; continue; } - if (!reversed && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) && !subpath_is_changed) { + if (!reversed && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { subpathReverse(first, last); reversed = true; } - if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001)){ + if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0())){ counter++; bool active = true; bool hidden = false; @@ -270,7 +270,7 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV int steps = 0; Satellite sat(_satellites[0].satelliteType, is_time, active, mirror_knots, hidden, amount, degrees, steps); - _satellites.insert(_satellites.begin() + counter ,sat); + _satellites.insert(_satellites.begin() + counter + 1 ,sat); } ++curve_it1; counter++; -- cgit v1.2.3 From f4864a7048b05cfe032027470c58e5ef2b69bd59 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 17:21:27 +0200 Subject: Fix a bug in pathinfo (bzr r13645.1.74) --- src/helper/geom-pathinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index a37c0e475..99ca3c8aa 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -45,7 +45,7 @@ void Pathinfo::setPathVector(Geom::PathVector path_vector, bool skip_degenerate) void Pathinfo::_setPathInfo(Piecewise > pwd2) { - _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); + _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001), true); } /** Store the base path data */ -- cgit v1.2.3 From c6457829dc2711fca07f5f27ecc597dc4f932929 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 17:59:57 +0200 Subject: fixing bug on closed paths (bzr r13645.1.76) --- src/helper/geom-pathinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 99ca3c8aa..a37c0e475 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -45,7 +45,7 @@ void Pathinfo::setPathVector(Geom::PathVector path_vector, bool skip_degenerate) void Pathinfo::_setPathInfo(Piecewise > pwd2) { - _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001), true); + _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); } /** Store the base path data */ -- cgit v1.2.3 From 22ded87a8ca58e0ff4400b2d4e76787f4ac22bd6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 19:39:38 +0200 Subject: Fixed bug on closed paths, Clenup of pathinfo (bzr r13645.1.77) --- src/helper/geom-pathinfo.cpp | 12 ++++-------- src/helper/geom-pathinfo.h | 2 -- 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index a37c0e475..ac94c0281 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -17,12 +17,12 @@ namespace Geom { * @brief Pathinfo store the data of a pathvector and allow get info about it * */ -Pathinfo::Pathinfo(Piecewise > pwd2) : _pwd2(pwd2) +Pathinfo::Pathinfo(Piecewise > pwd2) { _setPathInfo(pwd2); } ; -Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate) : _path_vector(path_vector) +Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate) { _setPathInfo(path_vector, skip_degenerate); } @@ -33,13 +33,11 @@ Pathinfo::~Pathinfo() {} void Pathinfo::setPwd2(Piecewise > pwd2) { - _pwd2 = pwd2; _setPathInfo(pwd2); } void Pathinfo::setPathVector(Geom::PathVector path_vector, bool skip_degenerate) { - _path_vector = path_vector; _setPathInfo(path_vector, skip_degenerate); } @@ -52,11 +50,9 @@ void Pathinfo::_setPathInfo(Piecewise > pwd2) void Pathinfo::_setPathInfo(Geom::PathVector path_vector, bool skip_degenerate) { data.clear(); - Geom::PathVector path_in = - path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t counter = 0; - for (PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) { + for (PathVector::const_iterator path_it = path_vector.begin(); + path_it != path_vector.end(); ++path_it) { if (path_it->empty()) { continue; } diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 021fcca2b..7a597202f 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -39,8 +39,6 @@ public: private: void _setPathInfo(Piecewise > pwd2); void _setPathInfo(Geom::PathVector path_vector, bool skip_degenerate = false); - Piecewise > _pwd2; - Geom::PathVector _path_vector; }; } //namespace Geom -- cgit v1.2.3 From 74649824e41b26bcf560ba485364a6ffe7b80fca Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 20:12:48 +0200 Subject: rename pathinfo function (bzr r13645.1.78) --- src/helper/geom-pathinfo.cpp | 4 ++-- src/helper/geom-pathinfo.h | 2 +- src/helper/geom-pointwise.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index ac94c0281..0cb7c64dd 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -80,9 +80,9 @@ void Pathinfo::_setPathInfo(Geom::PathVector path_vector, bool skip_degenerate) } } -size_t Pathinfo::numberCurves() const +size_t Pathinfo::size() const { - return data.back().first; + return data.back().first + 1; } size_t Pathinfo::subPathIndex(size_t index) const diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 7a597202f..73220b959 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -27,7 +27,7 @@ public: virtual ~Pathinfo(); void setPwd2(Piecewise > pwd2); void setPathVector(Geom::PathVector path_vector, bool skip_degenerate = false); - size_t numberCurves() const; + size_t size() const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; size_t first(size_t index) const; diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index f68c9b13f..54cfbb45d 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -238,7 +238,7 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV { size_t size_A = A.size(); _path_info.setPathVector(B); - size_t size_B = _path_info.numberCurves(); + size_t size_B = _path_info.size(); size_t satellite_gap = size_B - size_A; if (satellite_gap == 0){ return; -- cgit v1.2.3 From 1a4fb1c5b0c91ed84f3a98bc78cfc725d043e629 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 7 Apr 2015 00:22:14 +0200 Subject: Adding and renaming methofs to pathinfo (bzr r13645.1.79) --- src/helper/geom-pathinfo.cpp | 5 +++++ src/helper/geom-pathinfo.h | 1 + src/helper/geom-pointwise.cpp | 40 +++++++++++----------------------------- src/helper/geom-pointwise.h | 6 +++--- 4 files changed, 20 insertions(+), 32 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 0cb7c64dd..8144564cb 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -85,6 +85,11 @@ size_t Pathinfo::size() const return data.back().first + 1; } +size_t Pathinfo::subPathSize(size_t index) const +{ + return data[index].first + 1; +} + size_t Pathinfo::subPathIndex(size_t index) const { for (size_t i = 0; i < data.size(); i++) { diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 73220b959..85c4ca6fa 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -28,6 +28,7 @@ public: void setPwd2(Piecewise > pwd2); void setPathVector(Geom::PathVector path_vector, bool skip_degenerate = false); size_t size() const; + size_t subPathSize(size_t index) const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; size_t first(size_t index) const; diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 54cfbb45d..5b153841b 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -78,14 +78,14 @@ void Pointwise::setStart() /** Fired when a path is modified. */ -void Pointwise::recalculateForNewPwd2(Piecewise > A, Geom::PathVector B) +void Pointwise::recalculateForNewPwd2(Piecewise > A, Geom::PathVector B, Satellite S) { if (_pwd2.size() > A.size()) { pwd2Sustract(A); } else if (_pwd2.size() < A.size()) { - pwd2Append(A); + pwd2Append(A, S); } else { - insertDegenerateSatellites(A,B); + insertDegenerateSatellites(A, B, S); } } @@ -110,11 +110,10 @@ void Pointwise::pwd2Sustract(Piecewise > A) /** Append nodes/subpaths to current pointwise */ -void Pointwise::pwd2Append(Piecewise > A) +void Pointwise::pwd2Append(Piecewise > A, Satellite S) { size_t counter = 0; std::vector sats; - bool reversed = false; bool reorder = false; for (size_t i = 0; i < A.size(); i++) { size_t first = _path_info.first(i - counter); @@ -130,6 +129,7 @@ void Pointwise::pwd2Append(Piecewise > A) } else { subpath_is_changed = new_subpath_index != _path_info.subPathIndex(i - counter); } + if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { //Send the modified subpath to back subpathToBack(_path_info.subPathIndex(first)); @@ -137,23 +137,14 @@ void Pointwise::pwd2Append(Piecewise > A) i--; continue; } - if (!reversed && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { + + if (first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { subpathReverse(first, last); - reversed = true; } if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0())){ counter++; - bool active = true; - bool hidden = false; - bool is_time = _satellites[0].isTime; - bool mirror_knots = _satellites[0].hasMirror; - double amount = 0.0; - double degrees = 0.0; - int steps = 0; - Satellite sat(_satellites[0].satelliteType, is_time, active, mirror_knots, - hidden, amount, degrees, steps); - sats.push_back(sat); + sats.push_back(S); } else { sats.push_back(_satellites[i - counter]); } @@ -205,7 +196,7 @@ void Pointwise::subpathReverse(size_t start, size_t end) { start++; for (size_t i = end; i >= start; i--) { - _satellites.push_back(_satellites[i]); + _satellites.insert(_satellites.begin() + end + 1, _satellites[i]); _satellites.erase(_satellites.begin() + i); } std::vector path_in = @@ -234,7 +225,7 @@ void Pointwise::subpathReverse(size_t start, size_t end) /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. */ -void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathVector B) +void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S) { size_t size_A = A.size(); _path_info.setPathVector(B); @@ -261,16 +252,7 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV while (curve_it1 != curve_endit) { if ((*curve_it1).isDegenerate() && counter_added < satellite_gap){ counter_added++; - bool active = true; - bool hidden = false; - bool is_time = _satellites[0].isTime; - bool mirror_knots = _satellites[0].hasMirror; - double amount = 0.0; - double degrees = 0.0; - int steps = 0; - Satellite sat(_satellites[0].satelliteType, is_time, active, mirror_knots, - hidden, amount, degrees, steps); - _satellites.insert(_satellites.begin() + counter + 1 ,sat); + _satellites.insert(_satellites.begin() + counter + 1 ,S); } ++curve_it1; counter++; diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 48ee36255..e4b9f2b05 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -48,12 +48,12 @@ public: void setStart(); - void recalculateForNewPwd2(Piecewise > A, Geom::PathVector B); + void recalculateForNewPwd2(Piecewise > A, Geom::PathVector B, Satellite S); void pwd2Sustract(Piecewise > A); - void pwd2Append(Piecewise > A); + void pwd2Append(Piecewise > A, Satellite S); void subpathToBack(size_t subpath); void subpathReverse(size_t start, size_t end); - void insertDegenerateSatellites(Piecewise > A, Geom::PathVector B); + void insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S); private: Piecewise > _pwd2; -- cgit v1.2.3 From b0de25aa4da8128cb2c3b8b92b67db5070c5ef72 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 7 Apr 2015 00:25:02 +0200 Subject: added comment (bzr r13645.1.80) --- src/helper/geom-pointwise.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 5b153841b..6521e10b2 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -132,6 +132,7 @@ void Pointwise::pwd2Append(Piecewise > A, Satellite S) if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { //Send the modified subpath to back + //TODO: change subpathToBack to subpath move for the case of multiple subpath reverse subpathToBack(_path_info.subPathIndex(first)); reorder = true; i--; -- cgit v1.2.3 From f3f25749ce81d3664a53e723c611645f78bdefa2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 22 Apr 2015 18:47:54 +0200 Subject: adding suport to full path reverse (bzr r13645.1.82) --- src/helper/geom-pathinfo.cpp | 6 +++++- src/helper/geom-pointwise.cpp | 24 ++++++++++++++++++++++++ src/helper/geom-pointwise.h | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 8144564cb..38d58d417 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -87,7 +87,11 @@ size_t Pathinfo::size() const size_t Pathinfo::subPathSize(size_t index) const { - return data[index].first + 1; + size_t size = 0; + if( data.size() > index){ + size = data[index].first + 1; + } + return size; } size_t Pathinfo::subPathIndex(size_t index) const diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 6521e10b2..74c594d68 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -223,6 +223,26 @@ void Pointwise::subpathReverse(size_t start, size_t end) setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); } +void Pointwise::pathReverse() +{ + start++; + for (size_t i = _satellites.size()-1; i >= 0; i--) { + _satellites.insert(_satellites.begin() + _satellites.size(), _satellites[i]); + _satellites.erase(_satellites.begin() + i); + } + std::vector path_in = + path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); + std::vector tmp_path; + for (PathVector::const_iterator path_it = path_in.begin(); + path_it != path_in.end(); ++path_it) { + if (path_it->empty()) { + continue; + } + tmp_path.push_back(path_it->reverse()); + } + setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); +} + /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. */ @@ -233,6 +253,10 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV size_t size_B = _path_info.size(); size_t satellite_gap = size_B - size_A; if (satellite_gap == 0){ + if(_path_info.subPathSize(1) > 0 && !are_near(_pwd2[0].initialPoint(), A[0].initialPoint()) && + !are_near(_pwd2[size_A-1].finalPoint(), A[size_A-1].finalPoint())){ + pathReverse(); + } return; } size_t counter = 0; diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index e4b9f2b05..590f25f6f 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -52,6 +52,7 @@ public: void pwd2Sustract(Piecewise > A); void pwd2Append(Piecewise > A, Satellite S); void subpathToBack(size_t subpath); + void pathReverse(); void subpathReverse(size_t start, size_t end); void insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S); -- cgit v1.2.3 From 81dd40474313f2adbb1f59fb4ad9a38342f03752 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 22 Apr 2015 20:51:06 +0200 Subject: prevent overflow index on a pathinfo function (bzr r13645.1.84) --- src/helper/geom-pointwise.cpp | 25 ------------------------- src/helper/geom-pointwise.h | 1 - 2 files changed, 26 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 74c594d68..89bde4130 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -223,27 +223,6 @@ void Pointwise::subpathReverse(size_t start, size_t end) setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); } -void Pointwise::pathReverse() -{ - start++; - for (size_t i = _satellites.size()-1; i >= 0; i--) { - _satellites.insert(_satellites.begin() + _satellites.size(), _satellites[i]); - _satellites.erase(_satellites.begin() + i); - } - std::vector path_in = - path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); - std::vector tmp_path; - for (PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) { - if (path_it->empty()) { - continue; - } - tmp_path.push_back(path_it->reverse()); - } - setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); -} - - /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. */ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S) @@ -253,10 +232,6 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV size_t size_B = _path_info.size(); size_t satellite_gap = size_B - size_A; if (satellite_gap == 0){ - if(_path_info.subPathSize(1) > 0 && !are_near(_pwd2[0].initialPoint(), A[0].initialPoint()) && - !are_near(_pwd2[size_A-1].finalPoint(), A[size_A-1].finalPoint())){ - pathReverse(); - } return; } size_t counter = 0; diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 590f25f6f..e4b9f2b05 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -52,7 +52,6 @@ public: void pwd2Sustract(Piecewise > A); void pwd2Append(Piecewise > A, Satellite S); void subpathToBack(size_t subpath); - void pathReverse(); void subpathReverse(size_t start, size_t end); void insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S); -- cgit v1.2.3 From 3ce6cb91e8259ec064956c79c2cc4f9050dccbce Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 9 May 2015 22:48:48 +0200 Subject: fixing review (bzr r13645.1.86) --- src/helper/geom-pathinfo.cpp | 73 ++++++-------- src/helper/geom-pathinfo.h | 25 +++-- src/helper/geom-pointwise.cpp | 45 ++++----- src/helper/geom-pointwise.h | 23 ++--- src/helper/geom-satellite-enum.h | 39 -------- src/helper/geom-satellite.cpp | 201 +++++++++++++++++++-------------------- src/helper/geom-satellite.h | 50 +++++----- 7 files changed, 200 insertions(+), 256 deletions(-) delete mode 100644 src/helper/geom-satellite-enum.h (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 38d58d417..9e5e409c3 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -1,6 +1,6 @@ /** * \file - * \brief Pathinfo store the data of a pathvector and allow get info about it + * \brief Pathinfo store the _data of a pathvector and allow get info about it */ /* * Authors: * 2015 Jabier Arraiza Cenoz @@ -11,48 +11,37 @@ #include #include <2geom/sbasis-to-bezier.h> -namespace Geom { - /** - * @brief Pathinfo store the data of a pathvector and allow get info about it + * @brief Pathinfo store the _data of a pathvector and allow get info about it * */ Pathinfo::Pathinfo(Piecewise > pwd2) { - _setPathInfo(pwd2); + set(pwd2); } -; + Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate) { - _setPathInfo(path_vector, skip_degenerate); + set(path_vector, skip_degenerate); } -; -Pathinfo::~Pathinfo() {} -; -void Pathinfo::setPwd2(Piecewise > pwd2) -{ - _setPathInfo(pwd2); -} +Pathinfo::~Pathinfo() {} -void Pathinfo::setPathVector(Geom::PathVector path_vector, bool skip_degenerate) -{ - _setPathInfo(path_vector, skip_degenerate); -} -void Pathinfo::_setPathInfo(Piecewise > pwd2) +void Pathinfo::set(Piecewise > pwd2) { - _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); + set(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); } -/** Store the base path data +/** Store the base path _data */ -void Pathinfo::_setPathInfo(Geom::PathVector path_vector, bool skip_degenerate) +void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate) { - data.clear(); + _data.clear(); size_t counter = 0; for (PathVector::const_iterator path_it = path_vector.begin(); - path_it != path_vector.end(); ++path_it) { + path_it != path_vector.end(); ++path_it) + { if (path_it->empty()) { continue; } @@ -73,31 +62,31 @@ void Pathinfo::_setPathInfo(Geom::PathVector path_vector, bool skip_degenerate) counter++; } if (path_it->closed()) { - data.push_back(std::make_pair(counter - 1, true)); + _data.push_back(std::make_pair(counter - 1, true)); } else { - data.push_back(std::make_pair(counter - 1, false)); + _data.push_back(std::make_pair(counter - 1, false)); } } } -size_t Pathinfo::size() const +size_t Pathinfo::subPathCounter() const { - return data.back().first + 1; + return _data.back().first + 1; } size_t Pathinfo::subPathSize(size_t index) const { size_t size = 0; - if( data.size() > index){ - size = data[index].first + 1; + if( _data.size() > index){ + size = _data[index].first + 1; } return size; } size_t Pathinfo::subPathIndex(size_t index) const { - for (size_t i = 0; i < data.size(); i++) { - if (index <= data[i].first) { + for (size_t i = 0; i < _data.size(); i++) { + if (index <= _data[i].first) { return i; } } @@ -106,9 +95,9 @@ size_t Pathinfo::subPathIndex(size_t index) const size_t Pathinfo::last(size_t index) const { - for (size_t i = 0; i < data.size(); i++) { - if (index <= data[i].first) { - return data[i].first; + for (size_t i = 0; i < _data.size(); i++) { + if (index <= _data[i].first) { + return _data[i].first; } } return 0; @@ -116,12 +105,12 @@ size_t Pathinfo::last(size_t index) const size_t Pathinfo::first(size_t index) const { - for (size_t i = 0; i < data.size(); i++) { - if (index <= data[i].first) { + for (size_t i = 0; i < _data.size(); i++) { + if (index <= _data[i].first) { if (i == 0) { return 0; } else { - return data[i - 1].first + 1; + return _data[i - 1].first + 1; } } } @@ -152,16 +141,14 @@ boost::optional Pathinfo::next(size_t index) const bool Pathinfo::closed(size_t index) const { - for (size_t i = 0; i < data.size(); i++) { - if (index <= data[i].first) { - return data[i].second; + for (size_t i = 0; i < _data.size(); i++) { + if (index <= _data[i].first) { + return _data[i].second; } } return false; } -}; // namespace Geom - /* Local Variables: mode:c++ diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 85c4ca6fa..ae05f5b89 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -1,6 +1,7 @@ /** * \file - * \brief Pathinfo store the data of a pathvector and allow get info about it + * \brief Pathinfo store data of a pathvector and allow get info about it + * \ */ /* * Authors: * 2015 Jabier Arraiza Cenoz @@ -8,26 +9,26 @@ * This code is in public domain */ -#ifndef SEEN_GEOM_PATHINFO_H -#define SEEN_GEOM_PATHINFO_H +#ifndef SEEN_PATHINFO_H +#define SEEN_PATHINFO_H #include <2geom/path.h> #include -namespace Geom { - /** * @brief Pathinfo store the data of a pathvector and allow get info about it * */ +using namespace Geom; class Pathinfo { public: Pathinfo(Piecewise > pwd2); Pathinfo(Geom::PathVector path_vector, bool skip_degenerate = false); virtual ~Pathinfo(); - void setPwd2(Piecewise > pwd2); - void setPathVector(Geom::PathVector path_vector, bool skip_degenerate = false); - size_t size() const; + void set(Piecewise > pwd2); + void set(Geom::PathVector path_vector, bool skip_degenerate = false); + std::vector > get(){return _data;}; + size_t subPathCounter() const; size_t subPathSize(size_t index) const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; @@ -35,16 +36,12 @@ public: boost::optional previous(size_t index) const; boost::optional next(size_t index) const; bool closed(size_t index) const; - std::vector > data; private: - void _setPathInfo(Piecewise > pwd2); - void _setPathInfo(Geom::PathVector path_vector, bool skip_degenerate = false); + std::vector > _data; }; -} //namespace Geom - -#endif //SEEN_GEOM_PATHINFO_H +#endif //SEEN_PATHINFO_H /* Local Variables: mode:c++ diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 89bde4130..bd03f1d89 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -10,8 +10,6 @@ #include -namespace Geom { - /** * @brief Pointwise a class to manage a vector of satellites per piecewise curve * @@ -31,20 +29,20 @@ Pointwise::Pointwise(Piecewise > pwd2, { setStart(); } -; + Pointwise::~Pointwise() {} -; + Piecewise > Pointwise::getPwd2() const { return _pwd2; } -void Pointwise::setPwd2(Piecewise > pwd2_in) +void Pointwise::setPwd2(Piecewise > const pwd2_in) { _pwd2 = pwd2_in; - _path_info.setPwd2(_pwd2); + _path_info.set(_pwd2); } std::vector Pointwise::getSatellites() const @@ -52,7 +50,7 @@ std::vector Pointwise::getSatellites() const return _satellites; } -void Pointwise::setSatellites(std::vector sats) +void Pointwise::setSatellites(std::vector const sats) { _satellites = sats; setStart(); @@ -62,7 +60,7 @@ void Pointwise::setSatellites(std::vector sats) */ void Pointwise::setStart() { - std::vector > path_info = _path_info.data; + std::vector > path_info = _path_info.get(); for (size_t i = 0; i < path_info.size(); i++) { size_t firstNode = _path_info.first(path_info[i].first); size_t lastNode = _path_info.last(path_info[i].first); @@ -78,7 +76,7 @@ void Pointwise::setStart() /** Fired when a path is modified. */ -void Pointwise::recalculateForNewPwd2(Piecewise > A, Geom::PathVector B, Satellite S) +void Pointwise::recalculateForNewPwd2(Piecewise > const A, Geom::PathVector const B, Satellite const S) { if (_pwd2.size() > A.size()) { pwd2Sustract(A); @@ -91,7 +89,7 @@ void Pointwise::recalculateForNewPwd2(Piecewise > A, Geom::PathVector /** Some nodes/subpaths are removed. */ -void Pointwise::pwd2Sustract(Piecewise > A) +void Pointwise::pwd2Sustract(Piecewise > const A) { size_t counter = 0; std::vector sats; @@ -99,7 +97,8 @@ void Pointwise::pwd2Sustract(Piecewise > A) setPwd2(A); for (size_t i = 0; i < _satellites.size(); i++) { if (_path_info.last(i - counter) < i - counter || - !are_near(pwd2[i].at0(), A[i - counter].at0())) { + !are_near(pwd2[i].at0(), A[i - counter].at0())) + { counter++; } else { sats.push_back(_satellites[i - counter]); @@ -110,7 +109,7 @@ void Pointwise::pwd2Sustract(Piecewise > A) /** Append nodes/subpaths to current pointwise */ -void Pointwise::pwd2Append(Piecewise > A, Satellite S) +void Pointwise::pwd2Append(Piecewise > const A, Satellite const S) { size_t counter = 0; std::vector sats; @@ -120,9 +119,9 @@ void Pointwise::pwd2Append(Piecewise > A, Satellite S) size_t last = _path_info.last(i - counter); //Check for subpath closed. If a subpath is closed, is not reversed or moved //to back - _path_info.setPwd2(A); + _path_info.set(A); size_t new_subpath_index = _path_info.subPathIndex(i); - _path_info.setPwd2(_pwd2); + _path_info.set(_pwd2); bool subpath_is_changed = false; if (_pwd2.size() <= i - counter) { subpath_is_changed = false; @@ -163,7 +162,8 @@ void Pointwise::subpathToBack(size_t subpath) std::vector tmp_path; Geom::Path to_back; for (PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) { + path_it != path_in.end(); ++path_it) + { if (path_it->empty()) { continue; } @@ -208,7 +208,8 @@ void Pointwise::subpathReverse(size_t start, size_t end) std::vector tmp_path; Geom::Path rev; for (PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) { + path_it != path_in.end(); ++path_it) + { if (path_it->empty()) { continue; } @@ -225,11 +226,11 @@ void Pointwise::subpathReverse(size_t start, size_t end) /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. */ -void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S) +void Pointwise::insertDegenerateSatellites(Piecewise > const A, Geom::PathVector const B, Satellite const S) { size_t size_A = A.size(); - _path_info.setPathVector(B); - size_t size_B = _path_info.size(); + _path_info.set(B); + size_t size_B = _path_info.subPathCounter(); size_t satellite_gap = size_B - size_A; if (satellite_gap == 0){ return; @@ -237,7 +238,8 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV size_t counter = 0; size_t counter_added = 0; for (PathVector::const_iterator path_it = B.begin(); - path_it != B.end(); ++path_it) { + path_it != B.end(); ++path_it) + { if (path_it->empty()) { continue; } @@ -259,11 +261,10 @@ void Pointwise::insertDegenerateSatellites(Piecewise > A, Geom::PathV } } - _path_info.setPwd2(A); + _path_info.set(A); setPwd2(A); } -} // namespace Geom /* Local Variables: mode:c++ diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index e4b9f2b05..787cdbfff 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -8,8 +8,8 @@ * This code is in public domain */ -#ifndef SEEN_GEOM_POINTWISE_H -#define SEEN_GEOM_POINTWISE_H +#ifndef SEEN_POINTWISE_H +#define SEEN_POINTWISE_H #include #include @@ -20,8 +20,6 @@ #include <2geom/path.h> #include -namespace Geom { - /** * @brief Pointwise a class to manage a vector of satellites per piecewise curve * @@ -35,25 +33,26 @@ namespace Geom { * optional satellites, and remove the active variable in satellites. * */ +using namespace Geom; class Pointwise { public: Pointwise(Piecewise > pwd2, std::vector satellites); virtual ~Pointwise(); Piecewise > getPwd2() const; - void setPwd2(Piecewise > pwd2_in); + void setPwd2(Piecewise > const pwd2_in); std::vector getSatellites() const; - void setSatellites(std::vector sats); + void setSatellites(std::vector const sats); void setStart(); - void recalculateForNewPwd2(Piecewise > A, Geom::PathVector B, Satellite S); - void pwd2Sustract(Piecewise > A); - void pwd2Append(Piecewise > A, Satellite S); + void recalculateForNewPwd2(Piecewise > const A, Geom::PathVector const B, Satellite const S); + void pwd2Sustract(Piecewise > const A); + void pwd2Append(Piecewise > const A, Satellite const S); void subpathToBack(size_t subpath); void subpathReverse(size_t start, size_t end); - void insertDegenerateSatellites(Piecewise > A, Geom::PathVector B, Satellite S); + void insertDegenerateSatellites(Piecewise > const A, Geom::PathVector const B, Satellite const S); private: Piecewise > _pwd2; @@ -61,9 +60,7 @@ private: Pathinfo _path_info; }; -} // end namespace Geom - -#endif //SEEN_GEOM_POINTWISE_H +#endif //SEEN_POINTWISE_H /* Local Variables: mode:c++ diff --git a/src/helper/geom-satellite-enum.h b/src/helper/geom-satellite-enum.h deleted file mode 100644 index d82cdabe0..000000000 --- a/src/helper/geom-satellite-enum.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef LIB2GEOM_SEEN_SATELLITE_ENUM_H -#define LIB2GEOM_SEEN_SATELLITE_ENUM_H - -/** - * \file - * \brief Satellite types enum - */ /* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ - -#include "util/enums.h" - -namespace Geom { - -enum SatelliteType { - F = 0, //Fillet - IF, //Inverse Fillet - C, //Chamfer - IC, //Inverse Chamfer - KO // Invalid Satellite) -}; - -} //namespace Geom - -#endif - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index efe6bb37a..397a556a9 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -17,38 +17,32 @@ #include <2geom/ray.h> #include -namespace Geom { - /** * @brief Satellite a per ?node/curve holder of data. */ Satellite::Satellite() {} -; -Satellite::Satellite(SatelliteType satelliteType, bool isTime, bool active, - bool hasMirror, bool hidden, double amount, double angle, - size_t steps) - : satelliteType(satelliteType), isTime(isTime), active(active), - hasMirror(hasMirror), hidden(hidden), amount(amount), angle(angle), - steps(steps) {} -; + +Satellite::Satellite(SatelliteType satellite_type) + : satellite_type(satellite_type) +{} Satellite::~Satellite() {} -; /** * Calculate the time in d2_in with a size of A + * TODO: find a better place to it */ -double Satellite::toTime(double A, Geom::D2 d2_in) const +double timeAtArcLength(double A, Geom::D2 const d2_in) { if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { return 0; } double t = 0; - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) { - if (lenghtPart != 0) { - t = A / lenghtPart; + double length_part = Geom::length(d2_in, Geom::EPSILON); + if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + if (length_part != 0) { + t = A / length_part; } } else if (d2_in[0].degreesOfFreedom() != 2) { Geom::Piecewise > u; @@ -65,16 +59,17 @@ double Satellite::toTime(double A, Geom::D2 d2_in) const /** * Calculate the size in d2_in with a point at A + * TODO: find a better place to it */ -double Satellite::toSize(double A, Geom::D2 d2_in) const +double arcLengthAt(double A, Geom::D2 const d2_in) { if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { return 0; } double s = 0; - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - if (A > lenghtPart || d2_in[0].degreesOfFreedom() == 2) { - s = (A * lenghtPart); + double length_part = Geom::length(d2_in, Geom::EPSILON); + if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + s = (A * length_part); } else if (d2_in[0].degreesOfFreedom() != 2) { Geom::Piecewise > u; u.push_cut(0); @@ -86,81 +81,79 @@ double Satellite::toSize(double A, Geom::D2 d2_in) const } /** - * Calculate the lenght of a satellite from a radious A input. + * Calculate the length of a satellite from a radious A input. + * convert a arc radius to a satellite length */ double Satellite::radToLen( - double A, boost::optional > d2_in, - Geom::D2 d2_out, - boost::optional previousSatellite) const + double A, Geom::D2 const d2_in, + Geom::D2 const d2_out, + Satellite const previousSatellite) const { double len = 0; - if (d2_in && previousSatellite) { - Piecewise > offset_curve0 = - Piecewise >(*d2_in) + - rot90(unitVector(derivative(*d2_in))) * (A); - Piecewise > offset_curve1 = - Piecewise >(d2_out) + - rot90(unitVector(derivative(d2_out))) * (A); - Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; - Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; - Geom::Crossings cs = Geom::crossings(p0, p1); - if (cs.size() > 0) { - Point cp = p0(cs[0].ta); - double p0pt = nearest_point(cp, d2_out); - len = (*previousSatellite).toSize(p0pt, d2_out); - } else { - if (A > 0) { - len = radToLen(A * -1, *d2_in, d2_out, previousSatellite); - } + Piecewise > offset_curve0 = + Piecewise >(d2_in) + + rot90(unitVector(derivative(d2_in))) * (A); + Piecewise > offset_curve1 = + Piecewise >(d2_out) + + rot90(unitVector(derivative(d2_out))) * (A); + Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; + Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; + Geom::Crossings cs = Geom::crossings(p0, p1); + if (cs.size() > 0) { + Point cp = p0(cs[0].ta); + double p0pt = nearest_point(cp, d2_out); + len = arcLengthAt(p0pt, d2_out); + } else { + if (A > 0) { + len = radToLen(A * -1, d2_in, d2_out, previousSatellite); } } return len; } /** -* Calculate the radious of a satellite from a lenght A input. +* Calculate the radious of a satellite from a length A input. +* convert a satellite length to a arc radius */ double Satellite::lenToRad( - double A, boost::optional > d2_in, - Geom::D2 d2_out, - boost::optional previousSatellite) const + double A, Geom::D2 const d2_in, + Geom::D2 const d2_out, + Satellite const previousSatellite) const { - if (d2_in && previousSatellite) { - double time_in = (*previousSatellite).time(A, true, *d2_in); - double time_out = (*previousSatellite).toTime(A, d2_out); - Geom::Point startArcPoint = (*d2_in).valueAt(time_in); - Geom::Point endArcPoint = d2_out.valueAt(time_out); - Piecewise > u; - u.push_cut(0); - u.push(*d2_in, 1); - Geom::Curve *C = path_from_piecewise(u, 0.1)[0][0].duplicate(); - Piecewise > u2; - u2.push_cut(0); - u2.push(d2_out, 1); - Geom::Curve *D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); - Curve *knotCurve1 = C->portion(0, time_in); - Curve *knotCurve2 = D->portion(time_out, 1); - Geom::CubicBezier const *cubic1 = - dynamic_cast(&*knotCurve1); - Ray ray1(startArcPoint, (*d2_in).valueAt(1)); - if (cubic1) { - ray1.setPoints((*cubic1)[2], startArcPoint); - } - Geom::CubicBezier const *cubic2 = - dynamic_cast(&*knotCurve2); - Ray ray2(d2_out.valueAt(0), endArcPoint); - if (cubic2) { - ray2.setPoints(endArcPoint, (*cubic2)[1]); - } - bool ccwToggle = cross((*d2_in).valueAt(1) - startArcPoint, - endArcPoint - startArcPoint) < 0; - double distanceArc = - Geom::distance(startArcPoint, middle_point(startArcPoint, endArcPoint)); - double angleBetween = angle_between(ray1, ray2, ccwToggle); - double divisor = std::sin(angleBetween / 2.0); - if (divisor > 0) { - return distanceArc / divisor; - } + double time_in = (previousSatellite).time(A, true, d2_in); + double time_out = timeAtArcLength(A, d2_out); + Geom::Point startArcPoint = (d2_in).valueAt(time_in); + Geom::Point endArcPoint = d2_out.valueAt(time_out); + Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + Geom::Curve *C = path_from_piecewise(u, 0.1)[0][0].duplicate(); + Piecewise > u2; + u2.push_cut(0); + u2.push(d2_out, 1); + Geom::Curve *D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); + Curve *knotCurve1 = C->portion(0, time_in); + Curve *knotCurve2 = D->portion(time_out, 1); + Geom::CubicBezier const *cubic1 = + dynamic_cast(&*knotCurve1); + Ray ray1(startArcPoint, (d2_in).valueAt(1)); + if (cubic1) { + ray1.setPoints((*cubic1)[2], startArcPoint); + } + Geom::CubicBezier const *cubic2 = + dynamic_cast(&*knotCurve2); + Ray ray2(d2_out.valueAt(0), endArcPoint); + if (cubic2) { + ray2.setPoints(endArcPoint, (*cubic2)[1]); + } + bool ccwToggle = cross((d2_in).valueAt(1) - startArcPoint, + endArcPoint - startArcPoint) < 0; + double distanceArc = + Geom::distance(startArcPoint, middle_point(startArcPoint, endArcPoint)); + double angleBetween = angle_between(ray1, ray2, ccwToggle); + double divisor = std::sin(angleBetween / 2.0); + if (divisor > 0) { + return distanceArc / divisor; } return 0; } @@ -171,8 +164,8 @@ double Satellite::lenToRad( double Satellite::time(Geom::D2 d2_in) const { double t = amount; - if (!isTime) { - t = toTime(t, d2_in); + if (!is_time) { + t = timeAtArcLength(t, d2_in); } if (t > 1) { t = 1; @@ -181,7 +174,7 @@ double Satellite::time(Geom::D2 d2_in) const } /**. - * Get the time from a lenght A in other curve, a bolean I gived to reverse time + * Get the time from a length A in other curve, a bolean I gived to reverse time */ double Satellite::time(double A, bool I, Geom::D2 d2_in) const @@ -193,21 +186,21 @@ double Satellite::time(double A, bool I, return 0; } if (!I) { - return toTime(A, d2_in); + return timeAtArcLength(A, d2_in); } - double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - A = lenghtPart - A; - return toTime(A, d2_in); + double length_part = Geom::length(d2_in, Geom::EPSILON); + A = length_part - A; + return timeAtArcLength(A, d2_in); } /** - * Get the lenght of the satellite in d2_in + * Get the length of the satellite in d2_in */ -double Satellite::size(Geom::D2 d2_in) const +double Satellite::arcDistance(Geom::D2 d2_in) const { double s = amount; - if (isTime) { - s = toSize(s, d2_in); + if (is_time) { + s = arcLengthAt(s, d2_in); } return s; } @@ -227,8 +220,8 @@ Geom::Point Satellite::getPosition(Geom::D2 d2_in) const void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) { double A = Geom::nearest_point(p, d2_in); - if (!isTime) { - A = toSize(A, d2_in); + if (!is_time) { + A = arcLengthAt(A, d2_in); } amount = A; } @@ -238,9 +231,13 @@ void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) */ void Satellite::setSatelliteType(gchar const *A) { - std::map GcharMapToSatelliteType = - boost::assign::map_list_of("F", F)("IF", IF)("C", C)("IC", IC)("KO", KO); - satelliteType = GcharMapToSatelliteType.find(std::string(A))->second; + std::map gchar_map_to_satellite_type = + boost::assign::map_list_of("F", FILLET)("IF", INVERSE_FILLET)("C", CHAMFER)("IC", INVERSE_CHAMFER)("KO", INVALID_SATELLITE); + std::map::iterator it = gchar_map_to_satellite_type.find(std::string(A)); + if(it != gchar_map_to_satellite_type.end()) + { + satellite_type = it->second; + } } /** @@ -248,13 +245,11 @@ void Satellite::setSatelliteType(gchar const *A) */ gchar const *Satellite::getSatelliteTypeGchar() const { - std::map SatelliteTypeToGcharMap = - boost::assign::map_list_of(F, "F")(IF, "IF")(C, "C")(IC, "IC")(KO, "KO"); - return SatelliteTypeToGcharMap.at(satelliteType); + std::map satellite_type_to_gchar_map = + boost::assign::map_list_of(FILLET, "F")(INVERSE_FILLET, "IF")(CHAMFER, "C")(INVERSE_CHAMFER, "IC")(INVALID_SATELLITE, "KO"); + return satellite_type_to_gchar_map.at(satellite_type); } -} //namespace Geom - /* Local Variables: mode:c++ diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index df54819fd..263cefa68 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -8,61 +8,67 @@ * This code is in public domain */ -#ifndef LIB2GEOM_SEEN_SATELLITE_H -#define LIB2GEOM_SEEN_SATELLITE_H +#ifndef SEEN_SATELLITE_H +#define SEEN_SATELLITE_H -#include #include <2geom/d2.h> #include #include +#include "util/enums.h" -namespace Geom { +enum SatelliteType { + FILLET = 0, //Fillet + INVERSE_FILLET, //Inverse Fillet + CHAMFER, //Chamfer + INVERSE_CHAMFER, //Inverse Chamfer + INVALID_SATELLITE // Invalid Satellite) +}; /** * @brief Satellite a per ?node/curve holder of data. */ +using namespace Geom; class Satellite { public: Satellite(); - Satellite(SatelliteType satelliteType, bool isTime, bool active, - bool hasMirror, bool hidden, double amount, double angle, - size_t steps); + Satellite(SatelliteType satellite_type); virtual ~Satellite(); - - double toSize(double A, Geom::D2 d2_in) const; - double toTime(double A, Geom::D2 d2_in) const; - double lenToRad(double A, boost::optional > d2_in, + void setIsTime(bool set_is_time){is_time = set_is_time;} + void setActive(bool set_active){active = set_active;} + void setHasMirror(bool set_has_mirror){has_mirror = set_has_mirror;} + void setHidden(bool set_hidden){hidden = set_hidden;} + void setAmount(bool set_amount){amount = set_amount;} + void setAngle(bool set_angle){angle = set_angle;} + void setSteps(bool set_steps){steps = set_steps;} + double lenToRad(double A, Geom::D2 d2_in, Geom::D2 d2_out, - boost::optional previousSatellite) const; - double radToLen(double A, boost::optional > d2_in, + Satellite previousSatellite) const; + double radToLen(double A, Geom::D2 d2_in, Geom::D2 d2_out, - boost::optional previousSatellite) const; + Satellite previousSatellite) const; double time(Geom::D2 d2_in) const; double time(double A, bool I, Geom::D2 d2_in) const; - double size(Geom::D2 d2_in) const; + double arcDistance(Geom::D2 d2_in) const; void setPosition(Geom::Point p, Geom::D2 d2_in); Geom::Point getPosition(Geom::D2 d2_in) const; void setSatelliteType(gchar const *A); gchar const *getSatelliteTypeGchar() const; - //TODO: maybe make after variables protected? - SatelliteType satelliteType; - bool isTime; + SatelliteType satellite_type; + bool is_time; bool active; - bool hasMirror; + bool has_mirror; bool hidden; double amount; double angle; size_t steps; }; -} // end namespace Geom - -#endif // LIB2GEOM_SEEN_SATELLITE_H +#endif // SEEN_SATELLITE_H /* Local Variables: -- cgit v1.2.3 From 6195a5fd157ff2681534aa90a279627e0048d4e1 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 00:37:31 +0200 Subject: fixing review (bzr r13645.1.87) --- src/helper/geom-satellite.cpp | 50 --------------------------------------- src/helper/geom-satellite.h | 54 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 51 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 397a556a9..51cff7d79 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -11,7 +11,6 @@ #include #include <2geom/curve.h> #include <2geom/nearest-point.h> -#include <2geom/sbasis-geometric.h> #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> #include <2geom/ray.h> @@ -29,56 +28,7 @@ Satellite::Satellite(SatelliteType satellite_type) Satellite::~Satellite() {} -/** - * Calculate the time in d2_in with a size of A - * TODO: find a better place to it - */ -double timeAtArcLength(double A, Geom::D2 const d2_in) -{ - if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { - return 0; - } - double t = 0; - double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { - if (length_part != 0) { - t = A / length_part; - } - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - std::vector t_roots = roots(arcLengthSb(u) - A); - if (t_roots.size() > 0) { - t = t_roots[0]; - } - } - return t; -} - -/** - * Calculate the size in d2_in with a point at A - * TODO: find a better place to it - */ -double arcLengthAt(double A, Geom::D2 const d2_in) -{ - if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { - return 0; - } - double s = 0; - double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { - s = (A * length_part); - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - u = Geom::portion(u, 0.0, A); - s = Geom::length(u, 0.001); - } - return s; -} /** * Calculate the length of a satellite from a radious A input. diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index 263cefa68..a4b1b23b9 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -14,6 +14,7 @@ #include <2geom/d2.h> #include #include +#include <2geom/sbasis-geometric.h> #include "util/enums.h" @@ -22,7 +23,7 @@ enum SatelliteType { INVERSE_FILLET, //Inverse Fillet CHAMFER, //Chamfer INVERSE_CHAMFER, //Inverse Chamfer - INVALID_SATELLITE // Invalid Satellite) + INVALID_SATELLITE // Invalid Satellite }; /** * @brief Satellite a per ?node/curve holder of data. @@ -68,6 +69,57 @@ public: size_t steps; }; +/** + * Calculate the time in d2_in with a size of A + * TODO: find a better place to it + */ +double timeAtArcLength(double A, Geom::D2 const d2_in) +{ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { + return 0; + } + double t = 0; + double length_part = Geom::length(d2_in, Geom::EPSILON); + if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + if (length_part != 0) { + t = A / length_part; + } + } else if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + std::vector t_roots = roots(arcLengthSb(u) - A); + if (t_roots.size() > 0) { + t = t_roots[0]; + } + } + + return t; +} + +/** + * Calculate the size in d2_in with a point at A + * TODO: find a better place to it + */ +double arcLengthAt(double A, Geom::D2 const d2_in) +{ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { + return 0; + } + double s = 0; + double length_part = Geom::length(d2_in, Geom::EPSILON); + if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + s = (A * length_part); + } else if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + u = Geom::portion(u, 0.0, A); + s = Geom::length(u, 0.001); + } + return s; +} + #endif // SEEN_SATELLITE_H /* -- cgit v1.2.3 From 870dbb0348163f55263eb9dca601d525d53a8d79 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 13:40:31 +0200 Subject: Working on Krzysztof review. Seems to be all fixed. TODO: double check review and comment (bzr r13645.1.89) --- src/helper/Makefile_insert | 1 - src/helper/geom-pathinfo.cpp | 20 +++++++----- src/helper/geom-pathinfo.h | 12 ++++---- src/helper/geom-pointwise.cpp | 34 ++++++++++++--------- src/helper/geom-pointwise.h | 20 ++++++------ src/helper/geom-satellite.cpp | 71 ++++++++++++++++++++++++++++++++++++------- src/helper/geom-satellite.h | 55 ++------------------------------- 7 files changed, 111 insertions(+), 102 deletions(-) (limited to 'src/helper') diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 1d051734e..919234b47 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -20,7 +20,6 @@ ink_common_sources += \ helper/geom-pointwise.h \ helper/geom-satellite.cpp \ helper/geom-satellite.h \ - helper/geom-satellite-enum.h \ helper/gnome-utils.cpp \ helper/gnome-utils.h \ helper/mathfns.h \ diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 9e5e409c3..5ffd1d31e 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -1,6 +1,6 @@ /** * \file - * \brief Pathinfo store the _data of a pathvector and allow get info about it + * \brief Pathinfo store the _data of a Geom::PathVector and allow get info about it */ /* * Authors: * 2015 Jabier Arraiza Cenoz @@ -12,10 +12,10 @@ #include <2geom/sbasis-to-bezier.h> /** - * @brief Pathinfo store the _data of a pathvector and allow get info about it + * @brief Pathinfo store the _data of a Geom::PathVector and allow get info about it * */ -Pathinfo::Pathinfo(Piecewise > pwd2) +Pathinfo::Pathinfo(Geom::Piecewise > pwd2) { set(pwd2); } @@ -29,7 +29,7 @@ Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate) Pathinfo::~Pathinfo() {} -void Pathinfo::set(Piecewise > pwd2) +void Pathinfo::set(Geom::Piecewise > pwd2) { set(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); } @@ -39,7 +39,7 @@ void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate) { _data.clear(); size_t counter = 0; - for (PathVector::const_iterator path_it = path_vector.begin(); + for (Geom::PathVector::const_iterator path_it = path_vector.begin(); path_it != path_vector.end(); ++path_it) { if (path_it->empty()) { @@ -48,7 +48,7 @@ void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate) Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Curve &closingline = path_it->back_closed(); + Geom::Curve const &closingline = path_it->back_closed(); if (are_near(closingline.initialPoint(), closingline.finalPoint())) { curve_endit = path_it->end_open(); } @@ -69,7 +69,7 @@ void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate) } } -size_t Pathinfo::subPathCounter() const +size_t Pathinfo::size() const { return _data.back().first + 1; } @@ -78,7 +78,11 @@ size_t Pathinfo::subPathSize(size_t index) const { size_t size = 0; if( _data.size() > index){ - size = _data[index].first + 1; + double prev = 0; + if(index != 0){ + prev = _data[index - 1].first; + } + size = prev - _data[index].first + 1; } return size; } diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index ae05f5b89..8a6c51e51 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -1,6 +1,6 @@ /** * \file - * \brief Pathinfo store data of a pathvector and allow get info about it + * \brief Pathinfo store data of a Geom::PathVector and allow get info about it * \ */ /* * Authors: @@ -16,19 +16,19 @@ #include /** - * @brief Pathinfo store the data of a pathvector and allow get info about it + * @brief Pathinfo store the data of a Geom::PathVector and allow get info about it * */ -using namespace Geom; + class Pathinfo { public: - Pathinfo(Piecewise > pwd2); + Pathinfo(Geom::Piecewise > pwd2); Pathinfo(Geom::PathVector path_vector, bool skip_degenerate = false); virtual ~Pathinfo(); - void set(Piecewise > pwd2); + void set(Geom::Piecewise > pwd2); void set(Geom::PathVector path_vector, bool skip_degenerate = false); std::vector > get(){return _data;}; - size_t subPathCounter() const; + size_t size() const; size_t subPathSize(size_t index) const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index bd03f1d89..3041c60ea 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -23,7 +23,7 @@ * optional satellites, and remove the active variable in satellites. * */ -Pointwise::Pointwise(Piecewise > pwd2, +Pointwise::Pointwise(Geom::Piecewise > pwd2, std::vector satellites) : _pwd2(pwd2), _satellites(satellites), _path_info(pwd2) { @@ -34,17 +34,23 @@ Pointwise::Pointwise(Piecewise > pwd2, Pointwise::~Pointwise() {} -Piecewise > Pointwise::getPwd2() const +Geom::Piecewise > Pointwise::getPwd2() const { return _pwd2; } -void Pointwise::setPwd2(Piecewise > const pwd2_in) +void Pointwise::setPwd2(Geom::Piecewise > const pwd2_in) { _pwd2 = pwd2_in; _path_info.set(_pwd2); } +void Pointwise::setPathInfo(Geom::PathVector const pv) +{ + _path_info.set(pv); + setStart(); +} + std::vector Pointwise::getSatellites() const { return _satellites; @@ -76,7 +82,7 @@ void Pointwise::setStart() /** Fired when a path is modified. */ -void Pointwise::recalculateForNewPwd2(Piecewise > const A, Geom::PathVector const B, Satellite const S) +void Pointwise::recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S) { if (_pwd2.size() > A.size()) { pwd2Sustract(A); @@ -89,11 +95,11 @@ void Pointwise::recalculateForNewPwd2(Piecewise > const A, Geom::Path /** Some nodes/subpaths are removed. */ -void Pointwise::pwd2Sustract(Piecewise > const A) +void Pointwise::pwd2Sustract(Geom::Piecewise > const A) { size_t counter = 0; std::vector sats; - Piecewise > pwd2 = _pwd2; + Geom::Piecewise > pwd2 = _pwd2; setPwd2(A); for (size_t i = 0; i < _satellites.size(); i++) { if (_path_info.last(i - counter) < i - counter || @@ -109,7 +115,7 @@ void Pointwise::pwd2Sustract(Piecewise > const A) /** Append nodes/subpaths to current pointwise */ -void Pointwise::pwd2Append(Piecewise > const A, Satellite const S) +void Pointwise::pwd2Append(Geom::Piecewise > const A, Satellite const S) { size_t counter = 0; std::vector sats; @@ -161,7 +167,7 @@ void Pointwise::subpathToBack(size_t subpath) size_t counter = 0; std::vector tmp_path; Geom::Path to_back; - for (PathVector::const_iterator path_it = path_in.begin(); + for (Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { if (path_it->empty()) { @@ -169,7 +175,7 @@ void Pointwise::subpathToBack(size_t subpath) } Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); - const Curve &closingline = path_it->back_closed(); + Geom::Curve const &closingline = path_it->back_closed(); if (are_near(closingline.initialPoint(), closingline.finalPoint())) { curve_endit = path_it->end_open(); } @@ -207,7 +213,7 @@ void Pointwise::subpathReverse(size_t start, size_t end) size_t subpath = _path_info.subPathIndex(start); std::vector tmp_path; Geom::Path rev; - for (PathVector::const_iterator path_it = path_in.begin(); + for (Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { if (path_it->empty()) { @@ -226,18 +232,18 @@ void Pointwise::subpathReverse(size_t start, size_t end) /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. */ -void Pointwise::insertDegenerateSatellites(Piecewise > const A, Geom::PathVector const B, Satellite const S) +void Pointwise::insertDegenerateSatellites(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S) { size_t size_A = A.size(); _path_info.set(B); - size_t size_B = _path_info.subPathCounter(); + size_t size_B = _path_info.size(); size_t satellite_gap = size_B - size_A; if (satellite_gap == 0){ return; } size_t counter = 0; size_t counter_added = 0; - for (PathVector::const_iterator path_it = B.begin(); + for (Geom::PathVector::const_iterator path_it = B.begin(); path_it != B.end(); ++path_it) { if (path_it->empty()) { @@ -246,7 +252,7 @@ void Pointwise::insertDegenerateSatellites(Piecewise > const A, Geom: Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Curve &closingline = path_it->back_closed(); + Geom::Curve const &closingline = path_it->back_closed(); if (are_near(closingline.initialPoint(), closingline.finalPoint())) { curve_endit = path_it->end_open(); } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 787cdbfff..b1f2235c6 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -33,29 +33,29 @@ * optional satellites, and remove the active variable in satellites. * */ -using namespace Geom; + class Pointwise { public: - Pointwise(Piecewise > pwd2, std::vector satellites); + Pointwise(Geom::Piecewise > pwd2, std::vector satellites); virtual ~Pointwise(); - Piecewise > getPwd2() const; - void setPwd2(Piecewise > const pwd2_in); + Geom::Piecewise > getPwd2() const; + void setPwd2(Geom::Piecewise > const pwd2_in); std::vector getSatellites() const; void setSatellites(std::vector const sats); - + void setPathInfo(Geom::PathVector const pv); void setStart(); - void recalculateForNewPwd2(Piecewise > const A, Geom::PathVector const B, Satellite const S); - void pwd2Sustract(Piecewise > const A); - void pwd2Append(Piecewise > const A, Satellite const S); + void recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S); + void pwd2Sustract(Geom::Piecewise > const A); + void pwd2Append(Geom::Piecewise > const A, Satellite const S); void subpathToBack(size_t subpath); void subpathReverse(size_t start, size_t end); - void insertDegenerateSatellites(Piecewise > const A, Geom::PathVector const B, Satellite const S); + void insertDegenerateSatellites(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S); private: - Piecewise > _pwd2; + Geom::Piecewise > _pwd2; std::vector _satellites; Pathinfo _path_info; }; diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 51cff7d79..c2d4ef715 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -28,7 +28,56 @@ Satellite::Satellite(SatelliteType satellite_type) Satellite::~Satellite() {} +/** + * Calculate the time in d2_in with a size of A + * TODO: find a better place to it + */ +double timeAtArcLength(double A, Geom::D2 const d2_in) +{ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { + return 0; + } + double t = 0; + double length_part = Geom::length(d2_in, Geom::EPSILON); + if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + if (length_part != 0) { + t = A / length_part; + } + } else if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + std::vector t_roots = roots(arcLengthSb(u) - A); + if (t_roots.size() > 0) { + t = t_roots[0]; + } + } + return t; +} + +/** + * Calculate the size in d2_in with a point at A + * TODO: find a better place to it + */ +double arcLengthAt(double A, Geom::D2 const d2_in) +{ + if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { + return 0; + } + double s = 0; + double length_part = Geom::length(d2_in, Geom::EPSILON); + if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + s = (A * length_part); + } else if (d2_in[0].degreesOfFreedom() != 2) { + Geom::Piecewise > u; + u.push_cut(0); + u.push(d2_in, 1); + u = Geom::portion(u, 0.0, A); + s = Geom::length(u, 0.001); + } + return s; +} /** * Calculate the length of a satellite from a radious A input. @@ -40,17 +89,17 @@ double Satellite::radToLen( Satellite const previousSatellite) const { double len = 0; - Piecewise > offset_curve0 = - Piecewise >(d2_in) + + Geom::Piecewise > offset_curve0 = + Geom::Piecewise >(d2_in) + rot90(unitVector(derivative(d2_in))) * (A); - Piecewise > offset_curve1 = - Piecewise >(d2_out) + + Geom::Piecewise > offset_curve1 = + Geom::Piecewise >(d2_out) + rot90(unitVector(derivative(d2_out))) * (A); Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; Geom::Crossings cs = Geom::crossings(p0, p1); if (cs.size() > 0) { - Point cp = p0(cs[0].ta); + Geom::Point cp = p0(cs[0].ta); double p0pt = nearest_point(cp, d2_out); len = arcLengthAt(p0pt, d2_out); } else { @@ -74,25 +123,25 @@ double Satellite::lenToRad( double time_out = timeAtArcLength(A, d2_out); Geom::Point startArcPoint = (d2_in).valueAt(time_in); Geom::Point endArcPoint = d2_out.valueAt(time_out); - Piecewise > u; + Geom::Piecewise > u; u.push_cut(0); u.push(d2_in, 1); Geom::Curve *C = path_from_piecewise(u, 0.1)[0][0].duplicate(); - Piecewise > u2; + Geom::Piecewise > u2; u2.push_cut(0); u2.push(d2_out, 1); Geom::Curve *D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); - Curve *knotCurve1 = C->portion(0, time_in); - Curve *knotCurve2 = D->portion(time_out, 1); + Geom::Curve *knotCurve1 = C->portion(0, time_in); + Geom::Curve *knotCurve2 = D->portion(time_out, 1); Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); - Ray ray1(startArcPoint, (d2_in).valueAt(1)); + Geom::Ray ray1(startArcPoint, (d2_in).valueAt(1)); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); - Ray ray2(d2_out.valueAt(0), endArcPoint); + Geom::Ray ray2(d2_out.valueAt(0), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); } diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index a4b1b23b9..722adbef4 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -28,7 +28,7 @@ enum SatelliteType { /** * @brief Satellite a per ?node/curve holder of data. */ -using namespace Geom; + class Satellite { public: @@ -68,57 +68,8 @@ public: double angle; size_t steps; }; - -/** - * Calculate the time in d2_in with a size of A - * TODO: find a better place to it - */ -double timeAtArcLength(double A, Geom::D2 const d2_in) -{ - if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { - return 0; - } - double t = 0; - double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { - if (length_part != 0) { - t = A / length_part; - } - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - std::vector t_roots = roots(arcLengthSb(u) - A); - if (t_roots.size() > 0) { - t = t_roots[0]; - } - } - - return t; -} - -/** - * Calculate the size in d2_in with a point at A - * TODO: find a better place to it - */ -double arcLengthAt(double A, Geom::D2 const d2_in) -{ - if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { - return 0; - } - double s = 0; - double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { - s = (A * length_part); - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - u = Geom::portion(u, 0.0, A); - s = Geom::length(u, 0.001); - } - return s; -} +double timeAtArcLength(double A, Geom::D2 const d2_in); +double arcLengthAt(double A, Geom::D2 const d2_in); #endif // SEEN_SATELLITE_H -- cgit v1.2.3 From 63b289b4a3341f435e49dde40503636ba7b01b6a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 21:27:46 +0200 Subject: Added some comments (bzr r13645.1.90) --- src/helper/geom-pathinfo.cpp | 30 ++++++++++++++++++++++++------ src/helper/geom-pathinfo.h | 4 ++-- src/helper/geom-pointwise.h | 2 +- src/helper/geom-satellite.cpp | 6 ++---- 4 files changed, 29 insertions(+), 13 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 5ffd1d31e..d37b8b6da 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -1,6 +1,8 @@ /** * \file - * \brief Pathinfo store the _data of a Geom::PathVector and allow get info about it + * \brief Pathinfo iterate a Geom::PathVector and allow get info about it. + * \Usualy need a curve index to get the results + * \TODO: migrate more Inkscape loops to use it. */ /* * Authors: * 2015 Jabier Arraiza Cenoz @@ -69,24 +71,30 @@ void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate) } } +/** Size of pathvector + */ size_t Pathinfo::size() const { return _data.back().first + 1; } -size_t Pathinfo::subPathSize(size_t index) const +/** Size of subpath + */ +size_t Pathinfo::subPathSize(size_t subpath_index) const { size_t size = 0; - if( _data.size() > index){ + if( _data.size() > subpath_index){ double prev = 0; - if(index != 0){ - prev = _data[index - 1].first; + if(subpath_index != 0){ + prev = _data[subpath_index - 1].first; } - size = prev - _data[index].first + 1; + size = prev - _data[subpath_index].first + 1; } return size; } +/** Get subpath index from a curve index + */ size_t Pathinfo::subPathIndex(size_t index) const { for (size_t i = 0; i < _data.size(); i++) { @@ -97,6 +105,8 @@ size_t Pathinfo::subPathIndex(size_t index) const return 0; } +/** Get subpath last index given a curve index + */ size_t Pathinfo::last(size_t index) const { for (size_t i = 0; i < _data.size(); i++) { @@ -107,6 +117,8 @@ size_t Pathinfo::last(size_t index) const return 0; } +/** Get subpath first index given a curve index + */ size_t Pathinfo::first(size_t index) const { for (size_t i = 0; i < _data.size(); i++) { @@ -121,6 +133,8 @@ size_t Pathinfo::first(size_t index) const return 0; } +/** Get previous index given a curve index + */ boost::optional Pathinfo::previous(size_t index) const { if (first(index) == index && closed(index)) { @@ -132,6 +146,8 @@ boost::optional Pathinfo::previous(size_t index) const return index - 1; } +/** Get next index given a curve index + */ boost::optional Pathinfo::next(size_t index) const { if (last(index) == index && closed(index)) { @@ -143,6 +159,8 @@ boost::optional Pathinfo::next(size_t index) const return index + 1; } +/** Get if subpath is closed given a curve index + */ bool Pathinfo::closed(size_t index) const { for (size_t i = 0; i < _data.size(); i++) { diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index 8a6c51e51..cd3a3b2b8 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -1,6 +1,6 @@ /** * \file - * \brief Pathinfo store data of a Geom::PathVector and allow get info about it + * \brief Pathinfo iterate a Geom::PathVector and allow get info about it. * \ */ /* * Authors: @@ -29,7 +29,7 @@ public: void set(Geom::PathVector path_vector, bool skip_degenerate = false); std::vector > get(){return _data;}; size_t size() const; - size_t subPathSize(size_t index) const; + size_t subPathSize(size_t subpath_index) const; size_t subPathIndex(size_t index) const; size_t last(size_t index) const; size_t first(size_t index) const; diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index b1f2235c6..3cb4ff136 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -1,6 +1,6 @@ /** * \file - * \brief Pointwise a class to manage a vector of satellites per piecewise curve + * \brief Pointwise a class to manage a vector of satellites, once per piecewise curve */ /* * Authors: * 2015 Jabier Arraiza Cenoz diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index c2d4ef715..d03839875 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -80,8 +80,7 @@ double arcLengthAt(double A, Geom::D2 const d2_in) } /** - * Calculate the length of a satellite from a radious A input. - * convert a arc radius to a satellite length + * Convert a arc radius of a fillet/chamfer to his satellite length -point position where fillet/chamferknot be on original curve */ double Satellite::radToLen( double A, Geom::D2 const d2_in, @@ -111,8 +110,7 @@ double Satellite::radToLen( } /** -* Calculate the radious of a satellite from a length A input. -* convert a satellite length to a arc radius +* Convert a satelite length -point position where fillet/chamfer knot be on original curve- to a arc radius of fillet/chamfer */ double Satellite::lenToRad( double A, Geom::D2 const d2_in, -- cgit v1.2.3 From c7925bda67f038dd5054329c43936658ca2cae76 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 22:36:27 +0200 Subject: some comments and pointwise related refactor (bzr r13645.1.91) --- src/helper/geom-pathinfo.cpp | 11 +---------- src/helper/geom-pathinfo.h | 3 +-- src/helper/geom-pointwise.cpp | 23 +++++++++++------------ src/helper/geom-pointwise.h | 14 ++++++++++---- src/helper/geom-satellite.cpp | 2 +- 5 files changed, 24 insertions(+), 29 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index d37b8b6da..d73f8f707 100644 --- a/src/helper/geom-pathinfo.cpp +++ b/src/helper/geom-pathinfo.cpp @@ -17,16 +17,7 @@ * @brief Pathinfo store the _data of a Geom::PathVector and allow get info about it * */ -Pathinfo::Pathinfo(Geom::Piecewise > pwd2) -{ - set(pwd2); -} - -Pathinfo::Pathinfo(Geom::PathVector path_vector, bool skip_degenerate) -{ - set(path_vector, skip_degenerate); -} - +Pathinfo::Pathinfo() {} Pathinfo::~Pathinfo() {} diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h index cd3a3b2b8..41753c68f 100644 --- a/src/helper/geom-pathinfo.h +++ b/src/helper/geom-pathinfo.h @@ -22,8 +22,7 @@ class Pathinfo { public: - Pathinfo(Geom::Piecewise > pwd2); - Pathinfo(Geom::PathVector path_vector, bool skip_degenerate = false); + Pathinfo(); virtual ~Pathinfo(); void set(Geom::Piecewise > pwd2); void set(Geom::PathVector path_vector, bool skip_degenerate = false); diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 3041c60ea..5f6c0d29e 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -3,8 +3,14 @@ * \brief Pointwise a class to manage a vector of satellites per piecewise curve */ /* * Authors: - * 2015 Jabier Arraiza Cenoz - * + * Jabiertxof + * Johan Engelen + * Josh Andler + * suv + * Mc- + * Liam P. White + * Nathan Hurst + * Krzysztof Kosiński * This code is in public domain */ @@ -23,12 +29,7 @@ * optional satellites, and remove the active variable in satellites. * */ -Pointwise::Pointwise(Geom::Piecewise > pwd2, - std::vector satellites) - : _pwd2(pwd2), _satellites(satellites), _path_info(pwd2) -{ - setStart(); -} +Pointwise::Pointwise() {} Pointwise::~Pointwise() {} @@ -48,7 +49,6 @@ void Pointwise::setPwd2(Geom::Piecewise > const pwd2_in) void Pointwise::setPathInfo(Geom::PathVector const pv) { _path_info.set(pv); - setStart(); } std::vector Pointwise::getSatellites() const @@ -59,10 +59,9 @@ std::vector Pointwise::getSatellites() const void Pointwise::setSatellites(std::vector const sats) { _satellites = sats; - setStart(); } -/** Update the start satellite on ope/closed paths. +/** Update the start satellite on open/closed paths. */ void Pointwise::setStart() { @@ -137,7 +136,6 @@ void Pointwise::pwd2Append(Geom::Piecewise > const A, Sat if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { //Send the modified subpath to back - //TODO: change subpathToBack to subpath move for the case of multiple subpath reverse subpathToBack(_path_info.subPathIndex(first)); reorder = true; i--; @@ -145,6 +143,7 @@ void Pointwise::pwd2Append(Geom::Piecewise > const A, Sat } if (first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { + //reverse subpath subpathReverse(first, last); } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 3cb4ff136..d83b54b79 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -1,10 +1,16 @@ /** * \file - * \brief Pointwise a class to manage a vector of satellites, once per piecewise curve + * \brief Pointwise a class to manage a vector of satellites per piecewise curve */ /* * Authors: - * 2015 Jabier Arraiza Cenoz - * + * Jabiertxof + * Johan Engelen + * Josh Andler + * suv + * Mc- + * Liam P. White + * Nathan Hurst + * Krzysztof Kosiński * This code is in public domain */ @@ -36,7 +42,7 @@ class Pointwise { public: - Pointwise(Geom::Piecewise > pwd2, std::vector satellites); + Pointwise(); virtual ~Pointwise(); Geom::Piecewise > getPwd2() const; diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index d03839875..cd3f65f68 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -80,7 +80,7 @@ double arcLengthAt(double A, Geom::D2 const d2_in) } /** - * Convert a arc radius of a fillet/chamfer to his satellite length -point position where fillet/chamferknot be on original curve + * Convert a arc radius of a fillet/chamfer to his satellite length -point position where fillet/chamfer knot be on original curve */ double Satellite::radToLen( double A, Geom::D2 const d2_in, -- cgit v1.2.3 From d11134922137f029c42919ed3298924135bec386 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 11 May 2015 00:24:25 +0200 Subject: fix a minor bug calculating max time (bzr r13645.1.92) --- src/helper/geom-satellite.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/helper') diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index cd3f65f68..eed9706cf 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -39,7 +39,7 @@ double timeAtArcLength(double A, Geom::D2 const d2_in) } double t = 0; double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + if (A >= length_part || d2_in[0].degreesOfFreedom() == 2) { if (length_part != 0) { t = A / length_part; } -- cgit v1.2.3 From d6710f8318ba6f95e9dd5ad96d341acc41b14a4e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 25 Jun 2015 19:54:53 +0200 Subject: attemp to handle reverse path (bzr r13645.1.95) --- src/helper/geom-pointwise.cpp | 14 +++++++++++++- src/helper/geom-pointwise.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 5f6c0d29e..dc95ffda4 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -83,7 +83,11 @@ void Pointwise::setStart() */ void Pointwise::recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S) { - if (_pwd2.size() > A.size()) { + Geom::PathVector const reversed = path_from_piecewise(remove_short_cuts(reverse(_pwd2), 0.1), 0.001); + Geom::PathVector const original = path_from_piecewise(remove_short_cuts(reverse(A), 0.1), 0.001); + if (reversed == original) { + pwd2Reverse(A); + } else if (_pwd2.size() > A.size()) { pwd2Sustract(A); } else if (_pwd2.size() < A.size()) { pwd2Append(A, S); @@ -112,6 +116,14 @@ void Pointwise::pwd2Sustract(Geom::Piecewise > const A) setSatellites(sats); } +/** Reverse a path + */ +void Pointwise::pwd2Reverse(Geom::Piecewise > const A){ + std::reverse(_satellites.begin(), _satellites.end()); + setPwd2(A); + setSatellites(_satellites); +} + /** Append nodes/subpaths to current pointwise */ void Pointwise::pwd2Append(Geom::Piecewise > const A, Satellite const S) diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index d83b54b79..79504ecff 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -54,6 +54,7 @@ public: void setStart(); void recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S); + void pwd2Reverse(Geom::Piecewise > const A); void pwd2Sustract(Geom::Piecewise > const A); void pwd2Append(Geom::Piecewise > const A, Satellite const S); void subpathToBack(size_t subpath); -- cgit v1.2.3 From a5d2901e1f17879bc65e23b3ff26f8c304658ce4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 26 Jun 2015 17:58:32 +0200 Subject: removed reverse path, commented why (bzr r13645.1.97) --- src/helper/geom-pointwise.cpp | 14 +------------- src/helper/geom-pointwise.h | 1 - 2 files changed, 1 insertion(+), 14 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index dc95ffda4..5f6c0d29e 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -83,11 +83,7 @@ void Pointwise::setStart() */ void Pointwise::recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S) { - Geom::PathVector const reversed = path_from_piecewise(remove_short_cuts(reverse(_pwd2), 0.1), 0.001); - Geom::PathVector const original = path_from_piecewise(remove_short_cuts(reverse(A), 0.1), 0.001); - if (reversed == original) { - pwd2Reverse(A); - } else if (_pwd2.size() > A.size()) { + if (_pwd2.size() > A.size()) { pwd2Sustract(A); } else if (_pwd2.size() < A.size()) { pwd2Append(A, S); @@ -116,14 +112,6 @@ void Pointwise::pwd2Sustract(Geom::Piecewise > const A) setSatellites(sats); } -/** Reverse a path - */ -void Pointwise::pwd2Reverse(Geom::Piecewise > const A){ - std::reverse(_satellites.begin(), _satellites.end()); - setPwd2(A); - setSatellites(_satellites); -} - /** Append nodes/subpaths to current pointwise */ void Pointwise::pwd2Append(Geom::Piecewise > const A, Satellite const S) diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 79504ecff..d83b54b79 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -54,7 +54,6 @@ public: void setStart(); void recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S); - void pwd2Reverse(Geom::Piecewise > const A); void pwd2Sustract(Geom::Piecewise > const A); void pwd2Append(Geom::Piecewise > const A, Satellite const S); void subpathToBack(size_t subpath); -- cgit v1.2.3 From 57b065b5ffb5a871b5efac52f03cb95355bfa119 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 5 Jul 2015 02:57:00 +0200 Subject: fix to compile on Krzysztof merge previous to fix the improvements in the merge request (bzr r13645.1.100) --- src/helper/geom-pointwise.cpp | 10 +++++----- src/helper/geom-satellite.cpp | 11 +++++------ src/helper/geom-satellite.h | 3 +-- 3 files changed, 11 insertions(+), 13 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 5f6c0d29e..6910207bf 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -160,11 +160,11 @@ void Pointwise::pwd2Append(Geom::Piecewise > const A, Sat void Pointwise::subpathToBack(size_t subpath) { - std::vector path_in = + Geom::PathVector path_in = path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t subpath_counter = 0; size_t counter = 0; - std::vector tmp_path; + Geom::PathVector tmp_path; Geom::Path to_back; for (Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) @@ -205,12 +205,12 @@ void Pointwise::subpathReverse(size_t start, size_t end) _satellites.insert(_satellites.begin() + end + 1, _satellites[i]); _satellites.erase(_satellites.begin() + i); } - std::vector path_in = + Geom::PathVector path_in = path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t counter = 0; size_t subpath_counter = 0; size_t subpath = _path_info.subPathIndex(start); - std::vector tmp_path; + Geom::PathVector tmp_path; Geom::Path rev; for (Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) @@ -220,7 +220,7 @@ void Pointwise::subpathReverse(size_t start, size_t end) } counter++; if (subpath_counter == subpath) { - tmp_path.push_back(path_it->reverse()); + tmp_path.push_back(path_it->reversed()); } else { tmp_path.push_back(*path_it); } diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index eed9706cf..f5f28544d 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -10,7 +10,7 @@ #include #include <2geom/curve.h> -#include <2geom/nearest-point.h> +#include <2geom/nearest-time.h> #include <2geom/path-intersection.h> #include <2geom/sbasis-to-bezier.h> #include <2geom/ray.h> @@ -84,8 +84,7 @@ double arcLengthAt(double A, Geom::D2 const d2_in) */ double Satellite::radToLen( double A, Geom::D2 const d2_in, - Geom::D2 const d2_out, - Satellite const previousSatellite) const + Geom::D2 const d2_out) const { double len = 0; Geom::Piecewise > offset_curve0 = @@ -99,11 +98,11 @@ double Satellite::radToLen( Geom::Crossings cs = Geom::crossings(p0, p1); if (cs.size() > 0) { Geom::Point cp = p0(cs[0].ta); - double p0pt = nearest_point(cp, d2_out); + double p0pt = nearest_time(cp, d2_out); len = arcLengthAt(p0pt, d2_out); } else { if (A > 0) { - len = radToLen(A * -1, d2_in, d2_out, previousSatellite); + len = radToLen(A * -1, d2_in, d2_out); } } return len; @@ -216,7 +215,7 @@ Geom::Point Satellite::getPosition(Geom::D2 d2_in) const */ void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) { - double A = Geom::nearest_point(p, d2_in); + double A = Geom::nearest_time(p, d2_in); if (!is_time) { A = arcLengthAt(A, d2_in); } diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index 722adbef4..42c5687bd 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -47,8 +47,7 @@ public: Geom::D2 d2_out, Satellite previousSatellite) const; double radToLen(double A, Geom::D2 d2_in, - Geom::D2 d2_out, - Satellite previousSatellite) const; + Geom::D2 d2_out) const; double time(Geom::D2 d2_in) const; double time(double A, bool I, Geom::D2 d2_in) const; -- cgit v1.2.3 From 936f6512b26120b882a1c68e50968a15002f3af4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Jul 2015 12:01:17 +0200 Subject: Fixes from branch review (bzr r13645.1.102) --- src/helper/CMakeLists.txt | 4 + src/helper/Makefile_insert | 2 - src/helper/geom-pathinfo.cpp | 176 ------------------------------------------ src/helper/geom-pathinfo.h | 55 ------------- src/helper/geom-pointwise.cpp | 124 +++++++++++++++++------------ src/helper/geom-pointwise.h | 24 +++--- 6 files changed, 89 insertions(+), 296 deletions(-) delete mode 100644 src/helper/geom-pathinfo.cpp delete mode 100644 src/helper/geom-pathinfo.h (limited to 'src/helper') diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt index ff4760c24..aa99934b6 100644 --- a/src/helper/CMakeLists.txt +++ b/src/helper/CMakeLists.txt @@ -14,6 +14,8 @@ set(helper_SRC geom.cpp geom-nodetype.cpp geom-pathstroke.cpp + geom-pointwise.cpp + geom-satellite.cpp gnome-utils.cpp pixbuf-ops.cpp png-write.cpp @@ -32,6 +34,8 @@ set(helper_SRC geom-curves.h geom-nodetype.h geom-pathstroke.h + geom-pointwise.h + geom-satellite.h geom.h gnome-utils.h mathfns.h diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 919234b47..54588d0ce 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -12,8 +12,6 @@ ink_common_sources += \ helper/geom-curves.h \ helper/geom-nodetype.cpp \ helper/geom-nodetype.h \ - helper/geom-pathinfo.cpp \ - helper/geom-pathinfo.h \ helper/geom-pathstroke.cpp \ helper/geom-pathstroke.h \ helper/geom-pointwise.cpp \ diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp deleted file mode 100644 index d73f8f707..000000000 --- a/src/helper/geom-pathinfo.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/** - * \file - * \brief Pathinfo iterate a Geom::PathVector and allow get info about it. - * \Usualy need a curve index to get the results - * \TODO: migrate more Inkscape loops to use it. - */ /* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ - -#include -#include <2geom/sbasis-to-bezier.h> - -/** - * @brief Pathinfo store the _data of a Geom::PathVector and allow get info about it - * - */ -Pathinfo::Pathinfo() {} - -Pathinfo::~Pathinfo() {} - - -void Pathinfo::set(Geom::Piecewise > pwd2) -{ - set(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001)); -} -/** Store the base path _data - */ -void Pathinfo::set(Geom::PathVector path_vector, bool skip_degenerate) -{ - _data.clear(); - size_t counter = 0; - for (Geom::PathVector::const_iterator path_it = path_vector.begin(); - path_it != path_vector.end(); ++path_it) - { - if (path_it->empty()) { - continue; - } - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed()) { - Geom::Curve const &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - while (curve_it1 != curve_endit) { - if(curve_it1->isDegenerate() && skip_degenerate ){ - ++curve_it1; - continue; - } - ++curve_it1; - counter++; - } - if (path_it->closed()) { - _data.push_back(std::make_pair(counter - 1, true)); - } else { - _data.push_back(std::make_pair(counter - 1, false)); - } - } -} - -/** Size of pathvector - */ -size_t Pathinfo::size() const -{ - return _data.back().first + 1; -} - -/** Size of subpath - */ -size_t Pathinfo::subPathSize(size_t subpath_index) const -{ - size_t size = 0; - if( _data.size() > subpath_index){ - double prev = 0; - if(subpath_index != 0){ - prev = _data[subpath_index - 1].first; - } - size = prev - _data[subpath_index].first + 1; - } - return size; -} - -/** Get subpath index from a curve index - */ -size_t Pathinfo::subPathIndex(size_t index) const -{ - for (size_t i = 0; i < _data.size(); i++) { - if (index <= _data[i].first) { - return i; - } - } - return 0; -} - -/** Get subpath last index given a curve index - */ -size_t Pathinfo::last(size_t index) const -{ - for (size_t i = 0; i < _data.size(); i++) { - if (index <= _data[i].first) { - return _data[i].first; - } - } - return 0; -} - -/** Get subpath first index given a curve index - */ -size_t Pathinfo::first(size_t index) const -{ - for (size_t i = 0; i < _data.size(); i++) { - if (index <= _data[i].first) { - if (i == 0) { - return 0; - } else { - return _data[i - 1].first + 1; - } - } - } - return 0; -} - -/** Get previous index given a curve index - */ -boost::optional Pathinfo::previous(size_t index) const -{ - if (first(index) == index && closed(index)) { - return last(index); - } - if (first(index) == index && !closed(index)) { - return boost::none; - } - return index - 1; -} - -/** Get next index given a curve index - */ -boost::optional Pathinfo::next(size_t index) const -{ - if (last(index) == index && closed(index)) { - return first(index); - } - if (last(index) == index && !closed(index)) { - return boost::none; - } - return index + 1; -} - -/** Get if subpath is closed given a curve index - */ -bool Pathinfo::closed(size_t index) const -{ - for (size_t i = 0; i < _data.size(); i++) { - if (index <= _data[i].first) { - return _data[i].second; - } - } - return false; -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: -// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 -// : diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h deleted file mode 100644 index 41753c68f..000000000 --- a/src/helper/geom-pathinfo.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * \file - * \brief Pathinfo iterate a Geom::PathVector and allow get info about it. - * \ - */ /* - * Authors: - * 2015 Jabier Arraiza Cenoz - * - * This code is in public domain - */ - -#ifndef SEEN_PATHINFO_H -#define SEEN_PATHINFO_H - -#include <2geom/path.h> -#include - -/** - * @brief Pathinfo store the data of a Geom::PathVector and allow get info about it - * - */ - -class Pathinfo { -public: - Pathinfo(); - virtual ~Pathinfo(); - void set(Geom::Piecewise > pwd2); - void set(Geom::PathVector path_vector, bool skip_degenerate = false); - std::vector > get(){return _data;}; - size_t size() const; - size_t subPathSize(size_t subpath_index) const; - size_t subPathIndex(size_t index) const; - size_t last(size_t index) const; - size_t first(size_t index) const; - boost::optional previous(size_t index) const; - boost::optional next(size_t index) const; - bool closed(size_t index) const; - -private: - std::vector > _data; -}; - -#endif //SEEN_PATHINFO_H -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: -// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 -// : diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 6910207bf..7627b5dc3 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -29,26 +29,15 @@ * optional satellites, and remove the active variable in satellites. * */ -Pointwise::Pointwise() {} - -Pointwise::~Pointwise() {} - - -Geom::Piecewise > Pointwise::getPwd2() const +pwd2sb Pointwise::getPwd2() const { return _pwd2; } -void Pointwise::setPwd2(Geom::Piecewise > const pwd2_in) +void Pointwise::setPwd2(pwd2sb const &pwd2_in) { _pwd2 = pwd2_in; - _path_info.set(_pwd2); -} - -void Pointwise::setPathInfo(Geom::PathVector const pv) -{ - _path_info.set(pv); } std::vector Pointwise::getSatellites() const @@ -56,7 +45,7 @@ std::vector Pointwise::getSatellites() const return _satellites; } -void Pointwise::setSatellites(std::vector const sats) +void Pointwise::setSatellites(std::vector const &sats) { _satellites = sats; } @@ -65,26 +54,39 @@ void Pointwise::setSatellites(std::vector const sats) */ void Pointwise::setStart() { - std::vector > path_info = _path_info.get(); - for (size_t i = 0; i < path_info.size(); i++) { - size_t firstNode = _path_info.first(path_info[i].first); - size_t lastNode = _path_info.last(path_info[i].first); - if (!_path_info.closed(lastNode)) { - _satellites[firstNode].hidden = true; - _satellites[firstNode].active = false; - } else { - _satellites[firstNode].active = true; - _satellites[firstNode].hidden = _satellites[firstNode + 1].hidden; + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + int counter = 0; + for (Geom::PathVector::const_iterator path_it = pointwise_pv.begin(); + path_it != pointwise_pv.end(); ++path_it) { + if (path_it->empty()) { + continue; + } + Geom::Path::const_iterator curve_it = path_it->begin(); + Geom::Path::const_iterator curve_endit = path_it->end_default(); + int index = 0; + while (curve_it != curve_endit) { + if(index == 0){ + if (!path_it->closed()) { + _satellites[counter].hidden = true; + _satellites[counter].active = false; + } else { + _satellites[counter].active = true; + _satellites[counter].hidden = _satellites[counter].hidden; + } + } + ++index; + ++counter; + ++curve_it; } } } /** Fired when a path is modified. */ -void Pointwise::recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S) +void Pointwise::recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S) { if (_pwd2.size() > A.size()) { - pwd2Sustract(A); + pwd2Subtract(A); } else if (_pwd2.size() < A.size()) { pwd2Append(A, S); } else { @@ -94,14 +96,18 @@ void Pointwise::recalculateForNewPwd2(Geom::Piecewise > c /** Some nodes/subpaths are removed. */ -void Pointwise::pwd2Sustract(Geom::Piecewise > const A) +void Pointwise::pwd2Subtract(pwd2sb const &A) { size_t counter = 0; std::vector sats; - Geom::Piecewise > pwd2 = _pwd2; + pwd2sb pwd2 = _pwd2; setPwd2(A); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); for (size_t i = 0; i < _satellites.size(); i++) { - if (_path_info.last(i - counter) < i - counter || + Geom::Path sat_path = pointwise_pv.pathAt(i - counter); + Geom::PathTime sat_curve_time = sat_path.nearestTime(pointwise_pv.curveAt(i - counter).initialPoint()); + Geom::PathTime sat_curve_time_start = sat_path.nearestTime(sat_path.initialPoint()); + if (sat_curve_time_start.curve_index < sat_curve_time.curve_index|| !are_near(pwd2[i].at0(), A[i - counter].at0())) { counter++; @@ -114,36 +120,53 @@ void Pointwise::pwd2Sustract(Geom::Piecewise > const A) /** Append nodes/subpaths to current pointwise */ -void Pointwise::pwd2Append(Geom::Piecewise > const A, Satellite const S) +void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) { size_t counter = 0; std::vector sats; bool reorder = false; for (size_t i = 0; i < A.size(); i++) { - size_t first = _path_info.first(i - counter); - size_t last = _path_info.last(i - counter); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + Geom::Path sat_path = pointwise_pv.pathAt(i - counter); + boost::optional< Geom::PathVectorTime > sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i-counter).initialPoint()); + Geom::PathVectorTime sat_curve_time; + if(sat_curve_time_optional){ + sat_curve_time = *sat_curve_time_optional; + } + sat_curve_time.normalizeForward(sat_path.size()); + size_t first = Geom::nearest_time(sat_path.initialPoint(),_pwd2); + size_t last = first + sat_path.size() - 1; + bool is_start = false; + if(sat_curve_time.curve_index == 0){ + is_start = true; + } //Check for subpath closed. If a subpath is closed, is not reversed or moved //to back - _path_info.set(A); - size_t new_subpath_index = _path_info.subPathIndex(i); - _path_info.set(_pwd2); + size_t old_subpath_index = sat_curve_time.path_index; + pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); + sat_path = pointwise_pv.pathAt(i); + sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i).initialPoint()); + if(sat_curve_time_optional){ + sat_curve_time = *sat_curve_time_optional; + } + sat_curve_time.normalizeForward(sat_path.size()); + size_t new_subpath_index = sat_curve_time.path_index; bool subpath_is_changed = false; - if (_pwd2.size() <= i - counter) { - subpath_is_changed = false; - } else { - subpath_is_changed = new_subpath_index != _path_info.subPathIndex(i - counter); + if (_pwd2.size() > i - counter) { + subpath_is_changed = old_subpath_index != new_subpath_index; } - if (!reorder && first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { + if (!reorder && is_start && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { //Send the modified subpath to back - subpathToBack(_path_info.subPathIndex(first)); + subpathToBack(old_subpath_index); reorder = true; i--; continue; } - if (first == i - counter && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { - //reverse subpath + if (is_start && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { + //Krzysztof this code is hiden because i need a clean way to acced to the first and last index of a subpath based in + //his position on pathvector. Maybe the result Geom::PathVectorTime of nearestTime method can also return the time in the pathvector without calling two times to nearestTime subpathReverse(first, last); } @@ -209,7 +232,14 @@ void Pointwise::subpathReverse(size_t start, size_t end) path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); size_t counter = 0; size_t subpath_counter = 0; - size_t subpath = _path_info.subPathIndex(start); + Geom::Path sat_path = path_in.pathAt(start); + boost::optional< Geom::PathVectorTime > sat_curve_time_optional = path_in.nearestTime(path_in.curveAt(start).initialPoint()); + Geom::PathVectorTime sat_curve_time; + if(sat_curve_time_optional){ + sat_curve_time = *sat_curve_time_optional; + } + sat_curve_time.normalizeForward(sat_path.size()); + size_t subpath = sat_curve_time.path_index; Geom::PathVector tmp_path; Geom::Path rev; for (Geom::PathVector::const_iterator path_it = path_in.begin(); @@ -231,11 +261,10 @@ void Pointwise::subpathReverse(size_t start, size_t end) /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. */ -void Pointwise::insertDegenerateSatellites(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S) +void Pointwise::insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S) { size_t size_A = A.size(); - _path_info.set(B); - size_t size_B = _path_info.size(); + size_t size_B = B.curveCount(); size_t satellite_gap = size_B - size_A; if (satellite_gap == 0){ return; @@ -266,7 +295,6 @@ void Pointwise::insertDegenerateSatellites(Geom::Piecewise -#include #include <2geom/sbasis.h> #include <2geom/sbasis-2d.h> #include <2geom/piecewise.h> @@ -39,31 +38,26 @@ * optional satellites, and remove the active variable in satellites. * */ - +typedef Geom::Piecewise > pwd2sb; class Pointwise { public: - Pointwise(); - virtual ~Pointwise(); - - Geom::Piecewise > getPwd2() const; - void setPwd2(Geom::Piecewise > const pwd2_in); + pwd2sb getPwd2() const; + void setPwd2(pwd2sb const &pwd2_in); std::vector getSatellites() const; - void setSatellites(std::vector const sats); - void setPathInfo(Geom::PathVector const pv); + void setSatellites(std::vector const &sats); void setStart(); - void recalculateForNewPwd2(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S); - void pwd2Sustract(Geom::Piecewise > const A); - void pwd2Append(Geom::Piecewise > const A, Satellite const S); + void recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); + void pwd2Subtract(pwd2sb const &A); + void pwd2Append(pwd2sb const &A, Satellite const &S); void subpathToBack(size_t subpath); void subpathReverse(size_t start, size_t end); - void insertDegenerateSatellites(Geom::Piecewise > const A, Geom::PathVector const B, Satellite const S); + void insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); private: - Geom::Piecewise > _pwd2; + pwd2sb _pwd2; std::vector _satellites; - Pathinfo _path_info; }; #endif //SEEN_POINTWISE_H -- cgit v1.2.3 From ada767e2ad124b9dad0f80b7979a156513976aaa Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Jul 2015 12:20:05 +0200 Subject: pointwise tweak (bzr r13645.1.104) --- src/helper/geom-pointwise.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 7627b5dc3..db66162ca 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -165,8 +165,6 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) } if (is_start && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { - //Krzysztof this code is hiden because i need a clean way to acced to the first and last index of a subpath based in - //his position on pathvector. Maybe the result Geom::PathVectorTime of nearestTime method can also return the time in the pathvector without calling two times to nearestTime subpathReverse(first, last); } -- cgit v1.2.3 From 2207d9110e54540a7408642099c9217d8037a6b0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Jul 2015 12:22:52 +0200 Subject: astyle (bzr r13645.1.105) --- src/helper/geom-pointwise.cpp | 30 +++++++++++++----------------- src/helper/geom-satellite.cpp | 5 ++--- src/helper/geom-satellite.h | 35 ++++++++++++++++++++++++++++------- 3 files changed, 43 insertions(+), 27 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index db66162ca..91281ed7d 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -57,7 +57,7 @@ void Pointwise::setStart() Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); int counter = 0; for (Geom::PathVector::const_iterator path_it = pointwise_pv.begin(); - path_it != pointwise_pv.end(); ++path_it) { + path_it != pointwise_pv.end(); ++path_it) { if (path_it->empty()) { continue; } @@ -65,7 +65,7 @@ void Pointwise::setStart() Geom::Path::const_iterator curve_endit = path_it->end_default(); int index = 0; while (curve_it != curve_endit) { - if(index == 0){ + if(index == 0) { if (!path_it->closed()) { _satellites[counter].hidden = true; _satellites[counter].active = false; @@ -108,8 +108,7 @@ void Pointwise::pwd2Subtract(pwd2sb const &A) Geom::PathTime sat_curve_time = sat_path.nearestTime(pointwise_pv.curveAt(i - counter).initialPoint()); Geom::PathTime sat_curve_time_start = sat_path.nearestTime(sat_path.initialPoint()); if (sat_curve_time_start.curve_index < sat_curve_time.curve_index|| - !are_near(pwd2[i].at0(), A[i - counter].at0())) - { + !are_near(pwd2[i].at0(), A[i - counter].at0())) { counter++; } else { sats.push_back(_satellites[i - counter]); @@ -130,14 +129,14 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) Geom::Path sat_path = pointwise_pv.pathAt(i - counter); boost::optional< Geom::PathVectorTime > sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i-counter).initialPoint()); Geom::PathVectorTime sat_curve_time; - if(sat_curve_time_optional){ + if(sat_curve_time_optional) { sat_curve_time = *sat_curve_time_optional; } sat_curve_time.normalizeForward(sat_path.size()); size_t first = Geom::nearest_time(sat_path.initialPoint(),_pwd2); size_t last = first + sat_path.size() - 1; bool is_start = false; - if(sat_curve_time.curve_index == 0){ + if(sat_curve_time.curve_index == 0) { is_start = true; } //Check for subpath closed. If a subpath is closed, is not reversed or moved @@ -146,7 +145,7 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); sat_path = pointwise_pv.pathAt(i); sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i).initialPoint()); - if(sat_curve_time_optional){ + if(sat_curve_time_optional) { sat_curve_time = *sat_curve_time_optional; } sat_curve_time.normalizeForward(sat_path.size()); @@ -168,7 +167,7 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) subpathReverse(first, last); } - if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0())){ + if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0())) { counter++; sats.push_back(S); } else { @@ -188,8 +187,7 @@ void Pointwise::subpathToBack(size_t subpath) Geom::PathVector tmp_path; Geom::Path to_back; for (Geom::PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) - { + path_it != path_in.end(); ++path_it) { if (path_it->empty()) { continue; } @@ -233,7 +231,7 @@ void Pointwise::subpathReverse(size_t start, size_t end) Geom::Path sat_path = path_in.pathAt(start); boost::optional< Geom::PathVectorTime > sat_curve_time_optional = path_in.nearestTime(path_in.curveAt(start).initialPoint()); Geom::PathVectorTime sat_curve_time; - if(sat_curve_time_optional){ + if(sat_curve_time_optional) { sat_curve_time = *sat_curve_time_optional; } sat_curve_time.normalizeForward(sat_path.size()); @@ -241,8 +239,7 @@ void Pointwise::subpathReverse(size_t start, size_t end) Geom::PathVector tmp_path; Geom::Path rev; for (Geom::PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) - { + path_it != path_in.end(); ++path_it) { if (path_it->empty()) { continue; } @@ -264,14 +261,13 @@ void Pointwise::insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector con size_t size_A = A.size(); size_t size_B = B.curveCount(); size_t satellite_gap = size_B - size_A; - if (satellite_gap == 0){ + if (satellite_gap == 0) { return; } size_t counter = 0; size_t counter_added = 0; for (Geom::PathVector::const_iterator path_it = B.begin(); - path_it != B.end(); ++path_it) - { + path_it != B.end(); ++path_it) { if (path_it->empty()) { continue; } @@ -284,7 +280,7 @@ void Pointwise::insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector con } } while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() && counter_added < satellite_gap){ + if ((*curve_it1).isDegenerate() && counter_added < satellite_gap) { counter_added++; _satellites.insert(_satellites.begin() + counter + 1 ,S); } diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index f5f28544d..ddef7685a 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -230,9 +230,8 @@ void Satellite::setSatelliteType(gchar const *A) std::map gchar_map_to_satellite_type = boost::assign::map_list_of("F", FILLET)("IF", INVERSE_FILLET)("C", CHAMFER)("IC", INVERSE_CHAMFER)("KO", INVALID_SATELLITE); std::map::iterator it = gchar_map_to_satellite_type.find(std::string(A)); - if(it != gchar_map_to_satellite_type.end()) - { - satellite_type = it->second; + if(it != gchar_map_to_satellite_type.end()) { + satellite_type = it->second; } } diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index 42c5687bd..ef76060c4 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -36,13 +36,34 @@ public: Satellite(SatelliteType satellite_type); virtual ~Satellite(); - void setIsTime(bool set_is_time){is_time = set_is_time;} - void setActive(bool set_active){active = set_active;} - void setHasMirror(bool set_has_mirror){has_mirror = set_has_mirror;} - void setHidden(bool set_hidden){hidden = set_hidden;} - void setAmount(bool set_amount){amount = set_amount;} - void setAngle(bool set_angle){angle = set_angle;} - void setSteps(bool set_steps){steps = set_steps;} + void setIsTime(bool set_is_time) + { + is_time = set_is_time; + } + void setActive(bool set_active) + { + active = set_active; + } + void setHasMirror(bool set_has_mirror) + { + has_mirror = set_has_mirror; + } + void setHidden(bool set_hidden) + { + hidden = set_hidden; + } + void setAmount(bool set_amount) + { + amount = set_amount; + } + void setAngle(bool set_angle) + { + angle = set_angle; + } + void setSteps(bool set_steps) + { + steps = set_steps; + } double lenToRad(double A, Geom::D2 d2_in, Geom::D2 d2_out, Satellite previousSatellite) const; -- cgit v1.2.3 From 6962e3344dea73a3bc7d5599cc223ed8cc7cdbe7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 21 Aug 2015 23:53:14 +0200 Subject: Not sure about this changes :( (bzr r13645.1.107) --- src/helper/geom-pointwise.cpp | 93 ++++++++++++++++++++++++++++--------------- src/helper/geom-pointwise.h | 37 ++++++++++------- src/helper/geom-satellite.cpp | 9 ++++- 3 files changed, 90 insertions(+), 49 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 91281ed7d..526df7957 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -1,35 +1,21 @@ /** * \file - * \brief Pointwise a class to manage a vector of satellites per piecewise curve + * \brief Pointwise a class to manage a vector of satellites per piecewise node */ /* * Authors: * Jabiertxof + * Nathan Hurst * Johan Engelen * Josh Andler * suv * Mc- * Liam P. White - * Nathan Hurst * Krzysztof Kosiński * This code is in public domain */ #include -/** - * @brief Pointwise a class to manage a vector of satellites per piecewise curve - * - * For the moment is a per curve satellite holder not per node. This is ok for - * much cases but not a real node satellite on open paths - * To implement this we can: - * add extra satellite in open paths, and take notice of current open paths - * or put extra satellites on back for each open subpath - * - * Also maybe the vector of satellites become a vector of - * optional satellites, and remove the active variable in satellites. - * - */ - pwd2sb Pointwise::getPwd2() const { return _pwd2; @@ -40,18 +26,69 @@ void Pointwise::setPwd2(pwd2sb const &pwd2_in) _pwd2 = pwd2_in; } -std::vector Pointwise::getSatellites() const +std::vector Pointwise::getSatellites(bool curve_based) { + if(curve_based){ + size_t global_counter = 0; + size_t satellite_gap = 0; + Geom::PathVector pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + for (Geom::PathVector::const_iterator path_it = pathvector.begin(); + path_it != pathvector.end(); ++path_it) { + if (path_it->empty()) { + continue; + } + size_t counter = 0; + for (Geom::Path::const_iterator curve_it = path_it->begin(); + curve_it != path_it->end_closed(); ++curve_it) { + if(!path_it->closed()){ + if(path_it->size_closed()-1 == counter){ + _satellites.erase(_satellites.begin() + (global_counter - 1 - satellite_gap)); + satellite_gap++; + std::cout << counter << "get satellites" << "\n"; + } + } + counter++; + global_counter++; + } + } + } return _satellites; } -void Pointwise::setSatellites(std::vector const &sats) +void Pointwise::setSatellites(std::vector const &sats, bool curve_based) { _satellites = sats; + if(curve_based){ + size_t global_counter = 0; + Geom::PathVector pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + for (Geom::PathVector::const_iterator path_it = pathvector.begin(); + path_it != pathvector.end(); ++path_it) { + if (path_it->empty()) { + continue; + } + size_t counter = 0; + size_t start = global_counter; + for (Geom::Path::const_iterator curve_it = path_it->begin(); + curve_it != path_it->end_closed(); ++curve_it) { + if(!path_it->closed()){ + if(path_it->size_closed()-1 == counter){ + if(global_counter == _satellites.size()){ + _satellites.push_back(_satellites[start]); + } else { + _satellites.insert(_satellites.begin() + global_counter + 1,_satellites[start]); + } + std::cout << counter << "set satellites" << "\n"; + } + } + counter++; + global_counter++; + } + } + } } -/** Update the start satellite on open/closed paths. - */ + + void Pointwise::setStart() { Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); @@ -61,28 +98,24 @@ void Pointwise::setStart() if (path_it->empty()) { continue; } - Geom::Path::const_iterator curve_it = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); int index = 0; - while (curve_it != curve_endit) { + for (Geom::Path::const_iterator curve_it = path_it->begin(); + curve_it != path_it->end(); ++curve_it) { if(index == 0) { if (!path_it->closed()) { _satellites[counter].hidden = true; _satellites[counter].active = false; } else { _satellites[counter].active = true; - _satellites[counter].hidden = _satellites[counter].hidden; + _satellites[counter].hidden = _satellites[counter+1].hidden; } } ++index; ++counter; - ++curve_it; } } } -/** Fired when a path is modified. - */ void Pointwise::recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S) { if (_pwd2.size() > A.size()) { @@ -94,8 +127,6 @@ void Pointwise::recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B } } -/** Some nodes/subpaths are removed. - */ void Pointwise::pwd2Subtract(pwd2sb const &A) { size_t counter = 0; @@ -117,8 +148,6 @@ void Pointwise::pwd2Subtract(pwd2sb const &A) setSatellites(sats); } -/** Append nodes/subpaths to current pointwise - */ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) { size_t counter = 0; @@ -254,8 +283,6 @@ void Pointwise::subpathReverse(size_t start, size_t end) setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); } -/** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. - */ void Pointwise::insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S) { size_t size_A = A.size(); diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 6a8ea8881..fe8f6f157 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -1,15 +1,15 @@ /** * \file - * \brief Pointwise a class to manage a vector of satellites per piecewise curve + * \brief Pointwise a class to manage a vector of satellites per piecewise node */ /* * Authors: * Jabiertxof + * Nathan Hurst * Johan Engelen * Josh Andler * suv * Mc- * Liam P. White - * Nathan Hurst * Krzysztof Kosiński * This code is in public domain */ @@ -27,16 +27,6 @@ /** * @brief Pointwise a class to manage a vector of satellites per piecewise curve - * - * For the moment is a per curve satellite holder not per node. This is ok for - * much cases but not a real node satellite on open paths - * To implement this we can: - * add extra satellite in open paths, and take notice of current open paths - * or put extra satellites on back for each open subpath - * - * Also maybe the vector of satellites become a vector of - * optional satellites, and remove the active variable in satellites. - * */ typedef Geom::Piecewise > pwd2sb; class Pointwise { @@ -44,15 +34,32 @@ public: pwd2sb getPwd2() const; void setPwd2(pwd2sb const &pwd2_in); - std::vector getSatellites() const; - void setSatellites(std::vector const &sats); + /** + * @parameter curve_based allow the use of a satellite on last node of open paths + * if not curve based + */ + std::vector getSatellites(bool curve_based = true); + void setSatellites(std::vector const &sats, bool curve_based = true); + /** Update the start satellite on open/closed paths. + */ void setStart(); - + /** Fired when a path is modified. + */ void recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); + /** Some nodes/subpaths are removed. + */ void pwd2Subtract(pwd2sb const &A); + /** Append nodes/subpaths to current pointwise + */ void pwd2Append(pwd2sb const &A, Satellite const &S); + /** Send a subpath to end and update satellites + */ void subpathToBack(size_t subpath); + /** Reverse a subpath and update satellites + */ void subpathReverse(size_t start, size_t end); + /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. + */ void insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); private: diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index ddef7685a..9b2691a33 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -23,7 +23,14 @@ Satellite::Satellite() {} Satellite::Satellite(SatelliteType satellite_type) - : satellite_type(satellite_type) + : satellite_type(satellite_type), + is_time(false), + active(false), + has_mirror(false), + hidden(true), + amount(0.0), + angle(0.0), + steps(0) {} Satellite::~Satellite() {} -- cgit v1.2.3 From 9e8b8be725180905f537a0c20183c209abc5476f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 22 Aug 2015 00:05:38 +0200 Subject: remove couts (bzr r13645.1.109) --- src/helper/geom-pointwise.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 526df7957..8a0db6258 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -44,7 +44,6 @@ std::vector Pointwise::getSatellites(bool curve_based) if(path_it->size_closed()-1 == counter){ _satellites.erase(_satellites.begin() + (global_counter - 1 - satellite_gap)); satellite_gap++; - std::cout << counter << "get satellites" << "\n"; } } counter++; @@ -77,7 +76,6 @@ void Pointwise::setSatellites(std::vector const &sats, bool curve_bas } else { _satellites.insert(_satellites.begin() + global_counter + 1,_satellites[start]); } - std::cout << counter << "set satellites" << "\n"; } } counter++; -- cgit v1.2.3 From 4f78e3e4289b52ba4b7a3fbe24fd0d6fcb6f2250 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 23 Aug 2015 23:03:12 +0200 Subject: satellites in curves (bzr r13645.1.110) --- src/helper/geom-pointwise.cpp | 61 ++-------------- src/helper/geom-pointwise.h | 6 +- src/helper/geom-satellite.cpp | 163 +++++++++++++++++++++++++----------------- src/helper/geom-satellite.h | 25 ++++--- 4 files changed, 119 insertions(+), 136 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 8a0db6258..8ae2125a4 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -23,76 +23,25 @@ pwd2sb Pointwise::getPwd2() const void Pointwise::setPwd2(pwd2sb const &pwd2_in) { + _pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); _pwd2 = pwd2_in; } -std::vector Pointwise::getSatellites(bool curve_based) +std::vector Pointwise::getSatellites(e) { - if(curve_based){ - size_t global_counter = 0; - size_t satellite_gap = 0; - Geom::PathVector pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); - for (Geom::PathVector::const_iterator path_it = pathvector.begin(); - path_it != pathvector.end(); ++path_it) { - if (path_it->empty()) { - continue; - } - size_t counter = 0; - for (Geom::Path::const_iterator curve_it = path_it->begin(); - curve_it != path_it->end_closed(); ++curve_it) { - if(!path_it->closed()){ - if(path_it->size_closed()-1 == counter){ - _satellites.erase(_satellites.begin() + (global_counter - 1 - satellite_gap)); - satellite_gap++; - } - } - counter++; - global_counter++; - } - } - } return _satellites; } -void Pointwise::setSatellites(std::vector const &sats, bool curve_based) +void Pointwise::setSatellites(std::vector const &sats) { _satellites = sats; - if(curve_based){ - size_t global_counter = 0; - Geom::PathVector pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); - for (Geom::PathVector::const_iterator path_it = pathvector.begin(); - path_it != pathvector.end(); ++path_it) { - if (path_it->empty()) { - continue; - } - size_t counter = 0; - size_t start = global_counter; - for (Geom::Path::const_iterator curve_it = path_it->begin(); - curve_it != path_it->end_closed(); ++curve_it) { - if(!path_it->closed()){ - if(path_it->size_closed()-1 == counter){ - if(global_counter == _satellites.size()){ - _satellites.push_back(_satellites[start]); - } else { - _satellites.insert(_satellites.begin() + global_counter + 1,_satellites[start]); - } - } - } - counter++; - global_counter++; - } - } - } } - - void Pointwise::setStart() { - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); int counter = 0; - for (Geom::PathVector::const_iterator path_it = pointwise_pv.begin(); - path_it != pointwise_pv.end(); ++path_it) { + for (Geom::PathVector::const_iterator path_it = _pathvector.begin(); + path_it != _pathvector.end(); ++path_it) { if (path_it->empty()) { continue; } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index fe8f6f157..9d2993a23 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -33,13 +33,13 @@ class Pointwise { public: pwd2sb getPwd2() const; void setPwd2(pwd2sb const &pwd2_in); - /** * @parameter curve_based allow the use of a satellite on last node of open paths * if not curve based */ - std::vector getSatellites(bool curve_based = true); - void setSatellites(std::vector const &sats, bool curve_based = true); + std::vector getSatellites(); + void setSatellites(std::vector const &sats); + /** Update the start satellite on open/closed paths. */ void setStart(); diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 9b2691a33..10afca725 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -36,53 +36,88 @@ Satellite::Satellite(SatelliteType satellite_type) Satellite::~Satellite() {} /** - * Calculate the time in d2_in with a size of A + * Calculate the time in curve_in with a size of A * TODO: find a better place to it */ -double timeAtArcLength(double A, Geom::D2 const d2_in) +double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit) { - if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { + if ( A == 0 || curve_in.isDegenerate()) { return 0; } + + //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- + Geom::D2 d2_in = curve_in.toSBasis(); + static std::deque > > > deque_cache; + if(cache_limit > 0 && deque_cache.size() > cache_limit){ + std::deque > > > deque_cache_split(deque_cache.begin(), deque_cache.begin() + cache_limit); + deque_cache = deque_cache_split; + } + if(cache_limit > 0){ + return 1; + } + std::deque > > >::iterator it; + for (it = deque_cache.begin() ; it != deque_cache.end(); ++it){ + if(it->second.first == A){ + if(it->second.second == d2_in){ + return it->first; + } + } + } + double t = 0; - double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A >= length_part || d2_in[0].degreesOfFreedom() == 2) { + double length_part = curve_in.length(); + if (A >= length_part || curve_in.isLineSegment()) { if (length_part != 0) { t = A / length_part; } - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - std::vector t_roots = roots(arcLengthSb(u) - A); + } else if (!curve_in.isLineSegment()) { + + std::vector t_roots = roots(Geom::arcLengthSb(d2_in) - A); if (t_roots.size() > 0) { t = t_roots[0]; } } - + deque_cache.push_front(std::make_pair(t, std::make_pair(A, d2_in))); return t; } /** - * Calculate the size in d2_in with a point at A + * Calculate the size in curve_in with a point at A * TODO: find a better place to it */ -double arcLengthAt(double A, Geom::D2 const d2_in) +double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_limit) { - if (!d2_in.isFinite() || d2_in.isZero() || A == 0) { + if ( A == 0 || curve_in.isDegenerate()) { return 0; } + + //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- + Geom::D2 d2_in = curve_in.toSBasis(); + static std::deque > > > deque_cache; + if(cache_limit > 0 && deque_cache.size() > cache_limit){ + std::deque > > > deque_cache_split(deque_cache.begin(), deque_cache.begin() + cache_limit); + deque_cache = deque_cache_split; + } + if(cache_limit > 0){ + return 1; + } + std::deque > > >::iterator it; + for (it = deque_cache.begin() ; it != deque_cache.end(); ++it){ + if(it->second.first == A){ + if(it->second.second == d2_in){ + return it->first; + } + } + } double s = 0; - double length_part = Geom::length(d2_in, Geom::EPSILON); - if (A > length_part || d2_in[0].degreesOfFreedom() == 2) { + double length_part = curve_in.length(); + if (A > length_part || curve_in.isLineSegment()) { s = (A * length_part); - } else if (d2_in[0].degreesOfFreedom() != 2) { - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - u = Geom::portion(u, 0.0, A); - s = Geom::length(u, 0.001); + } else if (!curve_in.isLineSegment()) { + Geom::Curve *curve = curve_in.portion(0.0, A); + s = curve->length(0.001); } + deque_cache.push_front(std::make_pair(s, std::make_pair(A, d2_in))); return s; } @@ -90,10 +125,12 @@ double arcLengthAt(double A, Geom::D2 const d2_in) * Convert a arc radius of a fillet/chamfer to his satellite length -point position where fillet/chamfer knot be on original curve */ double Satellite::radToLen( - double A, Geom::D2 const d2_in, - Geom::D2 const d2_out) const + double const A, Geom::Curve const &curve_in, + Geom::Curve const &curve_out) const { double len = 0; + Geom::D2 d2_in = curve_in.toSBasis(); + Geom::D2 d2_out = curve_out.toSBasis(); Geom::Piecewise > offset_curve0 = Geom::Piecewise >(d2_in) + rot90(unitVector(derivative(d2_in))) * (A); @@ -105,11 +142,11 @@ double Satellite::radToLen( Geom::Crossings cs = Geom::crossings(p0, p1); if (cs.size() > 0) { Geom::Point cp = p0(cs[0].ta); - double p0pt = nearest_time(cp, d2_out); - len = arcLengthAt(p0pt, d2_out); + double p0pt = nearest_time(cp, curve_out); + len = arcLengthAt(p0pt, curve_out); } else { if (A > 0) { - len = radToLen(A * -1, d2_in, d2_out); + len = radToLen(A * -1, curve_in, curve_out); } } return len; @@ -119,37 +156,29 @@ double Satellite::radToLen( * Convert a satelite length -point position where fillet/chamfer knot be on original curve- to a arc radius of fillet/chamfer */ double Satellite::lenToRad( - double A, Geom::D2 const d2_in, - Geom::D2 const d2_out, + double const A, Geom::Curve const &curve_in, + Geom::Curve const &curve_out, Satellite const previousSatellite) const { - double time_in = (previousSatellite).time(A, true, d2_in); - double time_out = timeAtArcLength(A, d2_out); - Geom::Point startArcPoint = (d2_in).valueAt(time_in); - Geom::Point endArcPoint = d2_out.valueAt(time_out); - Geom::Piecewise > u; - u.push_cut(0); - u.push(d2_in, 1); - Geom::Curve *C = path_from_piecewise(u, 0.1)[0][0].duplicate(); - Geom::Piecewise > u2; - u2.push_cut(0); - u2.push(d2_out, 1); - Geom::Curve *D = path_from_piecewise(u2, 0.1)[0][0].duplicate(); - Geom::Curve *knotCurve1 = C->portion(0, time_in); - Geom::Curve *knotCurve2 = D->portion(time_out, 1); + double time_in = (previousSatellite).time(A, true, curve_in); + double time_out = timeAtArcLength(A, curve_out); + Geom::Point startArcPoint = curve_in.pointAt(time_in); + Geom::Point endArcPoint = curve_out.pointAt(time_out); + Geom::Curve *knotCurve1 = curve_in.portion(0, time_in); + Geom::Curve *knotCurve2 = curve_out.portion(time_out, 1); Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); - Geom::Ray ray1(startArcPoint, (d2_in).valueAt(1)); + Geom::Ray ray1(startArcPoint, curve_in.pointAt(1)); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); - Geom::Ray ray2(d2_out.valueAt(0), endArcPoint); + Geom::Ray ray2(curve_out.pointAt(0), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); } - bool ccwToggle = cross((d2_in).valueAt(1) - startArcPoint, + bool ccwToggle = cross(curve_in.pointAt(1) - startArcPoint, endArcPoint - startArcPoint) < 0; double distanceArc = Geom::distance(startArcPoint, middle_point(startArcPoint, endArcPoint)); @@ -162,13 +191,15 @@ double Satellite::lenToRad( } /** - * Get the time position of the satellite in d2_in + * Get the time position of the satellite in curve_in */ -double Satellite::time(Geom::D2 d2_in) const +double Satellite::time(Geom::Curve const &curve_in, bool const I) const { double t = amount; if (!is_time) { - t = timeAtArcLength(t, d2_in); + t = time(t, I, curve_in); + } else if (I) { + t = 1-t; } if (t > 1) { t = 1; @@ -179,8 +210,8 @@ double Satellite::time(Geom::D2 d2_in) const /**. * Get the time from a length A in other curve, a bolean I gived to reverse time */ -double Satellite::time(double A, bool I, - Geom::D2 d2_in) const +double Satellite::time(double A, bool const I, + Geom::Curve const &curve_in) const { if (A == 0 && I) { return 1; @@ -189,21 +220,21 @@ double Satellite::time(double A, bool I, return 0; } if (!I) { - return timeAtArcLength(A, d2_in); + return timeAtArcLength(A, curve_in); } - double length_part = Geom::length(d2_in, Geom::EPSILON); + double length_part = curve_in.length(); A = length_part - A; - return timeAtArcLength(A, d2_in); + return timeAtArcLength(A, curve_in); } /** - * Get the length of the satellite in d2_in + * Get the length of the satellite in curve_in */ -double Satellite::arcDistance(Geom::D2 d2_in) const +double Satellite::arcDistance(Geom::Curve const &curve_in) const { double s = amount; if (is_time) { - s = arcLengthAt(s, d2_in); + s = arcLengthAt(s, curve_in); } return s; } @@ -211,22 +242,26 @@ double Satellite::arcDistance(Geom::D2 d2_in) const /** * Get the point position of the satellite */ -Geom::Point Satellite::getPosition(Geom::D2 d2_in) const +Geom::Point Satellite::getPosition(Geom::Curve const &curve_in, bool const I) const { - double t = time(d2_in); - return d2_in.valueAt(t); + double t = time(curve_in, I); + return curve_in.pointAt(t); } /** * Set the position of the satellite from a gived point P */ -void Satellite::setPosition(Geom::Point p, Geom::D2 d2_in) +void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool const I) { - double A = Geom::nearest_time(p, d2_in); + Geom::Curve * curve = const_cast(&curve_in); + if (I) { + curve = curve->reverse(); + } + double A = Geom::nearest_time(p, *curve); if (!is_time) { - A = arcLengthAt(A, d2_in); + A = arcLengthAt(A, *curve); } - amount = A; + this->setAmount(A); } /** diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index ef76060c4..ed1ec221b 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -11,7 +11,6 @@ #ifndef SEEN_SATELLITE_H #define SEEN_SATELLITE_H -#include <2geom/d2.h> #include #include #include <2geom/sbasis-geometric.h> @@ -64,18 +63,18 @@ public: { steps = set_steps; } - double lenToRad(double A, Geom::D2 d2_in, - Geom::D2 d2_out, - Satellite previousSatellite) const; - double radToLen(double A, Geom::D2 d2_in, - Geom::D2 d2_out) const; + double lenToRad(double const A, Geom::Curve const &curve_in, + Geom::Curve const &curve_out, + Satellite const previousSatellite) const; + double radToLen(double const A, Geom::Curve const &curve_in, + Geom::Curve const &curve_out) const; - double time(Geom::D2 d2_in) const; - double time(double A, bool I, Geom::D2 d2_in) const; - double arcDistance(Geom::D2 d2_in) const; + double time(Geom::Curve const &curve_in, bool const I = false) const; + double time(double A, bool const I, Geom::Curve const &curve_in) const; + double arcDistance(Geom::Curve const &curve_in) const; - void setPosition(Geom::Point p, Geom::D2 d2_in); - Geom::Point getPosition(Geom::D2 d2_in) const; + void setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool const I = false); + Geom::Point getPosition(Geom::Curve const &curve_in, bool const I = false) const; void setSatelliteType(gchar const *A); gchar const *getSatelliteTypeGchar() const; @@ -88,8 +87,8 @@ public: double angle; size_t steps; }; -double timeAtArcLength(double A, Geom::D2 const d2_in); -double arcLengthAt(double A, Geom::D2 const d2_in); +double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit = 0); +double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_limit = 0); #endif // SEEN_SATELLITE_H -- cgit v1.2.3 From 89b565d68326ada49d11d0735ffb6b602c26a54f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 24 Aug 2015 00:58:37 +0200 Subject: Cached some functions (bzr r13645.1.111) --- src/helper/geom-pointwise.cpp | 20 ++++++++++---------- src/helper/geom-pointwise.h | 1 + src/helper/geom-satellite.cpp | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 8ae2125a4..9aa90df01 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -27,7 +27,7 @@ void Pointwise::setPwd2(pwd2sb const &pwd2_in) _pwd2 = pwd2_in; } -std::vector Pointwise::getSatellites(e) +std::vector Pointwise::getSatellites() { return _satellites; } @@ -80,10 +80,10 @@ void Pointwise::pwd2Subtract(pwd2sb const &A) std::vector sats; pwd2sb pwd2 = _pwd2; setPwd2(A); - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); for (size_t i = 0; i < _satellites.size(); i++) { - Geom::Path sat_path = pointwise_pv.pathAt(i - counter); - Geom::PathTime sat_curve_time = sat_path.nearestTime(pointwise_pv.curveAt(i - counter).initialPoint()); + Geom::Path sat_path = pathv.pathAt(i - counter); + Geom::PathTime sat_curve_time = sat_path.nearestTime(pathv.curveAt(i - counter).initialPoint()); Geom::PathTime sat_curve_time_start = sat_path.nearestTime(sat_path.initialPoint()); if (sat_curve_time_start.curve_index < sat_curve_time.curve_index|| !are_near(pwd2[i].at0(), A[i - counter].at0())) { @@ -101,9 +101,9 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) std::vector sats; bool reorder = false; for (size_t i = 0; i < A.size(); i++) { - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); - Geom::Path sat_path = pointwise_pv.pathAt(i - counter); - boost::optional< Geom::PathVectorTime > sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i-counter).initialPoint()); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + Geom::Path sat_path = pathv.pathAt(i - counter); + boost::optional< Geom::PathVectorTime > sat_curve_time_optional = pathv.nearestTime(pathv.curveAt(i-counter).initialPoint()); Geom::PathVectorTime sat_curve_time; if(sat_curve_time_optional) { sat_curve_time = *sat_curve_time_optional; @@ -118,9 +118,9 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) //Check for subpath closed. If a subpath is closed, is not reversed or moved //to back size_t old_subpath_index = sat_curve_time.path_index; - pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); - sat_path = pointwise_pv.pathAt(i); - sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i).initialPoint()); + pathv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); + sat_path = pathv.pathAt(i); + sat_curve_time_optional = pathv.nearestTime(pathv.curveAt(i).initialPoint()); if(sat_curve_time_optional) { sat_curve_time = *sat_curve_time_optional; } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 9d2993a23..a2324accd 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -64,6 +64,7 @@ public: private: pwd2sb _pwd2; + Geom::PathVector _pathvector; std::vector _satellites; }; diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 10afca725..35d21ef32 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -115,7 +115,7 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_lim s = (A * length_part); } else if (!curve_in.isLineSegment()) { Geom::Curve *curve = curve_in.portion(0.0, A); - s = curve->length(0.001); + s = curve->length(); } deque_cache.push_front(std::make_pair(s, std::make_pair(A, d2_in))); return s; @@ -261,7 +261,7 @@ void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bo if (!is_time) { A = arcLengthAt(A, *curve); } - this->setAmount(A); + amount = A; } /** -- cgit v1.2.3 From d34b8dca901083e5b68fd22899cb2c014238f8a4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 25 Aug 2015 13:39:35 +0200 Subject: addes cache and log to a function, result of the test, no diference so remove cache on next commit (bzr r13645.1.112) --- src/helper/geom-satellite.cpp | 108 ++++++++++++++++++++++++++++++------------ src/helper/geom-satellite.h | 7 +-- 2 files changed, 83 insertions(+), 32 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 35d21ef32..fac314b7f 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -15,6 +15,13 @@ #include <2geom/sbasis-to-bezier.h> #include <2geom/ray.h> #include +//log cache +#ifdef _WIN32 +#include +#else +#include +#include +#endif /** * @brief Satellite a per ?node/curve holder of data. @@ -39,6 +46,49 @@ Satellite::~Satellite() {} * Calculate the time in curve_in with a size of A * TODO: find a better place to it */ + +//http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c +/* Remove if already defined */ +typedef long long int64; typedef unsigned long long uint64; + +/* Returns the amount of milliseconds elapsed since the UNIX epoch. Works on both + * windows and linux. */ + +uint64 GetTimeMs64() +{ +#ifdef _WIN32 + /* Windows */ + FILETIME ft; + LARGE_INTEGER li; + + /* Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and copy it + * to a LARGE_INTEGER structure. */ + GetSystemTimeAsFileTime(&ft); + li.LowPart = ft.dwLowDateTime; + li.HighPart = ft.dwHighDateTime; + + uint64 ret = li.QuadPart; + ret -= 116444736000000000LL; /* Convert from file time to UNIX epoch time. */ + ret /= 10000; /* From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals */ + + return ret; +#else + /* Linux */ + struct timeval tv; + + gettimeofday(&tv, NULL); + + uint64 ret = tv.tv_usec; + /* Convert from micro seconds (10^-6) to milliseconds (10^-3) */ + ret /= 1000; + + /* Adds the seconds (10^0) after converting them to milliseconds (10^-3) */ + ret += (tv.tv_sec * 1000); + + return ret; +#endif +} + double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit) { if ( A == 0 || curve_in.isDegenerate()) { @@ -47,19 +97,34 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- Geom::D2 d2_in = curve_in.toSBasis(); - static std::deque > > > deque_cache; - if(cache_limit > 0 && deque_cache.size() > cache_limit){ - std::deque > > > deque_cache_split(deque_cache.begin(), deque_cache.begin() + cache_limit); - deque_cache = deque_cache_split; + + static bool cached = false; + if(cache_limit == 0){ + cached = false; + } else if(cache_limit > 1){ + cached = true; } - if(cache_limit > 0){ + static size_t count = 0; + static uint64 start = GetTimeMs64(); + static uint64 time_diff = GetTimeMs64(); + static cache_item cache_value = std::make_pair(0.0, std::make_pair(A, d2_in)); + if(cache_limit > 1 || cache_limit == 0){ + uint64 end = GetTimeMs64(); + uint64 elapsed_ms = end-start; + if(count == 0){ + time_diff = 0; + } else if(elapsed_ms < 1000){ + time_diff += elapsed_ms; + } + std::cout << "counter:" << count << ", cached:" << cached << ", function:timeAtArcLength" << ", miliseconds:" << elapsed_ms << ", acumulated ms:" << time_diff << "\n"; + start = end; + count++; return 1; } - std::deque > > >::iterator it; - for (it = deque_cache.begin() ; it != deque_cache.end(); ++it){ - if(it->second.first == A){ - if(it->second.second == d2_in){ - return it->first; + if(cached){ + if(cache_value.second.first == A){ + if(cache_value.second.second == d2_in ){ + return cache_value.first; } } } @@ -77,7 +142,9 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache t = t_roots[0]; } } - deque_cache.push_front(std::make_pair(t, std::make_pair(A, d2_in))); + if(cached){ + cache_value = std::make_pair(t, std::make_pair(A, d2_in)); + } return t; } @@ -85,7 +152,7 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache * Calculate the size in curve_in with a point at A * TODO: find a better place to it */ -double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_limit) +double arcLengthAt(double const A, Geom::Curve const &curve_in) { if ( A == 0 || curve_in.isDegenerate()) { return 0; @@ -93,22 +160,6 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_lim //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- Geom::D2 d2_in = curve_in.toSBasis(); - static std::deque > > > deque_cache; - if(cache_limit > 0 && deque_cache.size() > cache_limit){ - std::deque > > > deque_cache_split(deque_cache.begin(), deque_cache.begin() + cache_limit); - deque_cache = deque_cache_split; - } - if(cache_limit > 0){ - return 1; - } - std::deque > > >::iterator it; - for (it = deque_cache.begin() ; it != deque_cache.end(); ++it){ - if(it->second.first == A){ - if(it->second.second == d2_in){ - return it->first; - } - } - } double s = 0; double length_part = curve_in.length(); if (A > length_part || curve_in.isLineSegment()) { @@ -117,7 +168,6 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_lim Geom::Curve *curve = curve_in.portion(0.0, A); s = curve->length(); } - deque_cache.push_front(std::make_pair(s, std::make_pair(A, d2_in))); return s; } diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index ed1ec221b..61ac6be75 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -27,7 +27,7 @@ enum SatelliteType { /** * @brief Satellite a per ?node/curve holder of data. */ - +typedef std::pair > > cache_item; class Satellite { public: @@ -87,8 +87,9 @@ public: double angle; size_t steps; }; -double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit = 0); -double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_limit = 0); +//cache_limit never called as 1 +double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit = 1); +double arcLengthAt(double const A, Geom::Curve const &curve_in); #endif // SEEN_SATELLITE_H -- cgit v1.2.3 From 6d0ce49991a442e7e3f26c3922c26e54d927dd93 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 25 Aug 2015 13:48:02 +0200 Subject: Removed cache work :( (bzr r13645.1.113) --- src/helper/geom-satellite.cpp | 78 +------------------------------------------ src/helper/geom-satellite.h | 4 +-- 2 files changed, 3 insertions(+), 79 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index fac314b7f..547caf539 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -47,49 +47,8 @@ Satellite::~Satellite() {} * TODO: find a better place to it */ -//http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c -/* Remove if already defined */ -typedef long long int64; typedef unsigned long long uint64; -/* Returns the amount of milliseconds elapsed since the UNIX epoch. Works on both - * windows and linux. */ - -uint64 GetTimeMs64() -{ -#ifdef _WIN32 - /* Windows */ - FILETIME ft; - LARGE_INTEGER li; - - /* Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and copy it - * to a LARGE_INTEGER structure. */ - GetSystemTimeAsFileTime(&ft); - li.LowPart = ft.dwLowDateTime; - li.HighPart = ft.dwHighDateTime; - - uint64 ret = li.QuadPart; - ret -= 116444736000000000LL; /* Convert from file time to UNIX epoch time. */ - ret /= 10000; /* From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals */ - - return ret; -#else - /* Linux */ - struct timeval tv; - - gettimeofday(&tv, NULL); - - uint64 ret = tv.tv_usec; - /* Convert from micro seconds (10^-6) to milliseconds (10^-3) */ - ret /= 1000; - - /* Adds the seconds (10^0) after converting them to milliseconds (10^-3) */ - ret += (tv.tv_sec * 1000); - - return ret; -#endif -} - -double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit) +double timeAtArcLength(double const A, Geom::Curve const &curve_in) { if ( A == 0 || curve_in.isDegenerate()) { return 0; @@ -97,38 +56,6 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- Geom::D2 d2_in = curve_in.toSBasis(); - - static bool cached = false; - if(cache_limit == 0){ - cached = false; - } else if(cache_limit > 1){ - cached = true; - } - static size_t count = 0; - static uint64 start = GetTimeMs64(); - static uint64 time_diff = GetTimeMs64(); - static cache_item cache_value = std::make_pair(0.0, std::make_pair(A, d2_in)); - if(cache_limit > 1 || cache_limit == 0){ - uint64 end = GetTimeMs64(); - uint64 elapsed_ms = end-start; - if(count == 0){ - time_diff = 0; - } else if(elapsed_ms < 1000){ - time_diff += elapsed_ms; - } - std::cout << "counter:" << count << ", cached:" << cached << ", function:timeAtArcLength" << ", miliseconds:" << elapsed_ms << ", acumulated ms:" << time_diff << "\n"; - start = end; - count++; - return 1; - } - if(cached){ - if(cache_value.second.first == A){ - if(cache_value.second.second == d2_in ){ - return cache_value.first; - } - } - } - double t = 0; double length_part = curve_in.length(); if (A >= length_part || curve_in.isLineSegment()) { @@ -142,9 +69,6 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache t = t_roots[0]; } } - if(cached){ - cache_value = std::make_pair(t, std::make_pair(A, d2_in)); - } return t; } diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index 61ac6be75..2369dddbd 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -27,7 +27,7 @@ enum SatelliteType { /** * @brief Satellite a per ?node/curve holder of data. */ -typedef std::pair > > cache_item; + class Satellite { public: @@ -88,7 +88,7 @@ public: size_t steps; }; //cache_limit never called as 1 -double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit = 1); +double timeAtArcLength(double const A, Geom::Curve const &curve_in); double arcLengthAt(double const A, Geom::Curve const &curve_in); #endif // SEEN_SATELLITE_H -- cgit v1.2.3 From be65fc811e309e3a126f272601c3cb7997ef465e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 26 Aug 2015 22:09:46 +0200 Subject: astyle code (bzr r13645.1.116) --- src/helper/geom-pointwise.cpp | 2 +- src/helper/geom-satellite.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 9aa90df01..7074761da 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -47,7 +47,7 @@ void Pointwise::setStart() } int index = 0; for (Geom::Path::const_iterator curve_it = path_it->begin(); - curve_it != path_it->end(); ++curve_it) { + curve_it != path_it->end(); ++curve_it) { if(index == 0) { if (!path_it->closed()) { _satellites[counter].hidden = true; diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 547caf539..615106dd9 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -31,13 +31,13 @@ Satellite::Satellite() {} Satellite::Satellite(SatelliteType satellite_type) : satellite_type(satellite_type), - is_time(false), - active(false), - has_mirror(false), - hidden(true), - amount(0.0), - angle(0.0), - steps(0) + is_time(false), + active(false), + has_mirror(false), + hidden(true), + amount(0.0), + angle(0.0), + steps(0) {} Satellite::~Satellite() {} @@ -46,7 +46,7 @@ Satellite::~Satellite() {} * Calculate the time in curve_in with a size of A * TODO: find a better place to it */ - + double timeAtArcLength(double const A, Geom::Curve const &curve_in) { -- cgit v1.2.3 From 97bd182d6a2113eab1dd5faf51402ebd5382791c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 May 2016 22:57:37 +0200 Subject: First attempt to make fixed tweenk review (bzr r13645.1.128) --- src/helper/geom-pointwise.cpp | 277 ++++++++++++------------------------------ src/helper/geom-pointwise.h | 49 +++----- src/helper/geom-satellite.cpp | 60 ++++----- src/helper/geom-satellite.h | 16 ++- 4 files changed, 131 insertions(+), 271 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 7074761da..a96b7cbda 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -16,221 +16,116 @@ #include -pwd2sb Pointwise::getPwd2() const +PwD2SBasis Pointwise::getPwd2() const { return _pwd2; } -void Pointwise::setPwd2(pwd2sb const &pwd2_in) +Geom::Pathvector Pointwise::getPV() const { - _pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); - _pwd2 = pwd2_in; + return _pathvector; } -std::vector Pointwise::getSatellites() +void Pointwise::setPwd2(PwD2SBasis const &pwd2_in) { - return _satellites; + _pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + _pwd2 = pwd2_in; } -void Pointwise::setSatellites(std::vector const &sats) +Satelites Pointwise::getSatellites() { - _satellites = sats; + return _satellites; } -void Pointwise::setStart() +size_t Pointwise::getTotalSatellites() { - int counter = 0; - for (Geom::PathVector::const_iterator path_it = _pathvector.begin(); - path_it != _pathvector.end(); ++path_it) { - if (path_it->empty()) { - continue; - } - int index = 0; - for (Geom::Path::const_iterator curve_it = path_it->begin(); - curve_it != path_it->end(); ++curve_it) { - if(index == 0) { - if (!path_it->closed()) { - _satellites[counter].hidden = true; - _satellites[counter].active = false; - } else { - _satellites[counter].active = true; - _satellites[counter].hidden = _satellites[counter+1].hidden; - } - } - ++index; - ++counter; + size_t counter = 0 + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + counter++; } } + return counter; } -void Pointwise::recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S) +void Pointwise::setSatellites(Satelites const &sats) { - if (_pwd2.size() > A.size()) { - pwd2Subtract(A); - } else if (_pwd2.size() < A.size()) { - pwd2Append(A, S); - } else { - insertDegenerateSatellites(A, B, S); - } + _satellites = sats; } -void Pointwise::pwd2Subtract(pwd2sb const &A) +void Pointwise::recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) { - size_t counter = 0; - std::vector sats; - pwd2sb pwd2 = _pwd2; - setPwd2(A); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); - for (size_t i = 0; i < _satellites.size(); i++) { - Geom::Path sat_path = pathv.pathAt(i - counter); - Geom::PathTime sat_curve_time = sat_path.nearestTime(pathv.curveAt(i - counter).initialPoint()); - Geom::PathTime sat_curve_time_start = sat_path.nearestTime(sat_path.initialPoint()); - if (sat_curve_time_start.curve_index < sat_curve_time.curve_index|| - !are_near(pwd2[i].at0(), A[i - counter].at0())) { - counter++; - } else { - sats.push_back(_satellites[i - counter]); - } + if (_pwd2.size() > A.size() || _pwd2.size() < A.size()) { + recalculatePwD2(A, S); + } else { + insertDegenerateSatellites(A, B, S); } - setSatellites(sats); } -void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) +void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) { - size_t counter = 0; - std::vector sats; - bool reorder = false; - for (size_t i = 0; i < A.size(); i++) { - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); - Geom::Path sat_path = pathv.pathAt(i - counter); - boost::optional< Geom::PathVectorTime > sat_curve_time_optional = pathv.nearestTime(pathv.curveAt(i-counter).initialPoint()); - Geom::PathVectorTime sat_curve_time; - if(sat_curve_time_optional) { - sat_curve_time = *sat_curve_time_optional; - } - sat_curve_time.normalizeForward(sat_path.size()); - size_t first = Geom::nearest_time(sat_path.initialPoint(),_pwd2); - size_t last = first + sat_path.size() - 1; - bool is_start = false; - if(sat_curve_time.curve_index == 0) { - is_start = true; - } - //Check for subpath closed. If a subpath is closed, is not reversed or moved - //to back - size_t old_subpath_index = sat_curve_time.path_index; - pathv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); - sat_path = pathv.pathAt(i); - sat_curve_time_optional = pathv.nearestTime(pathv.curveAt(i).initialPoint()); - if(sat_curve_time_optional) { - sat_curve_time = *sat_curve_time_optional; - } - sat_curve_time.normalizeForward(sat_path.size()); - size_t new_subpath_index = sat_curve_time.path_index; - bool subpath_is_changed = false; - if (_pwd2.size() > i - counter) { - subpath_is_changed = old_subpath_index != new_subpath_index; - } - - if (!reorder && is_start && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { - //Send the modified subpath to back - subpathToBack(old_subpath_index); - reorder = true; - i--; - continue; - } - - if (is_start && !are_near(_pwd2[i - counter].at0(), A[i].at0()) && !subpath_is_changed) { - subpathReverse(first, last); + Satelites sats; + Geom::PathVector new_pathv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); + Geom::PathVector old_pathv = _pathvector; + _pathvector.clear(); + size_t new_size = new_pathv.size(); + size_t old_size = old_pathv.size(); + size_t old_increments = old_size; + for (size_t i = 0; i < new_pathv.size(); i++) { + bool match = false; + for (size_t j = 0; j < old_pathv.size(); j++) { + std::vector subpath_satellites; + if ( new_pathv[i] == old_pathv[j]){ + _pathvector.push_back(old_pathv[j]; + sats.push_back(_satellites[j]); + _satellites.erase(_satellites.begin() + j); + old_pathv.erase(old_pathv.begin() + j); + new_pathv.erase(new_pathv.begin() + i); + match = true; + break; + } } - - if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0())) { - counter++; - sats.push_back(S); - } else { - sats.push_back(_satellites[i - counter]); + if (!match && new_size > old_increments){ + _pathvector.push_back(new_pathv[i]); + std::vector subpath_satellites; + for (size_t k = 0; k < new_pathv[i].size(); k++) { + subpath_satellites.push_back(Satellite(_satellites[0][0].satellite_type)); + } + sats.push_back(subpath_satellites); + old_increments ++; } } - setPwd2(A); - setSatellites(sats); -} - -void Pointwise::subpathToBack(size_t subpath) -{ - Geom::PathVector path_in = - path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); - size_t subpath_counter = 0; - size_t counter = 0; - Geom::PathVector tmp_path; - Geom::Path to_back; - for (Geom::PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) { - if (path_it->empty()) { - continue; - } - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - Geom::Curve const &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - while (curve_it1 != curve_endit) { - if (subpath_counter == subpath) { - _satellites.push_back(_satellites[counter]); - _satellites.erase(_satellites.begin() + counter); + if (new_size == old_size) { + //we asume not change the order of subpaths when remove or add nodes to existing subpaths + for (size_t l = 0; l < old_pathv.size(); l++) { + //we assume we only can delete or add nodes not a mix of both + if (old_pathv[l].size() > new_pathv[l].size()){ + //erase nodes + for (size_t m = 0; m < old_pathv[l].size(); m++) { + if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint()) { + _satellites[l].erase(_satellites.begin() + m); + } + } + } else if (old_pathv[l].size() > new_pathv[l].size()) { + //add nodes + for (size_t m = 0; m < old_pathv[l].size(); m++) { + if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint()) { + _satellites[l].insert(_satellites.begin() + m, S); + } + } } else { - counter++; + //never happends } - ++curve_it1; + sats.push_back(_satellites[l]); + _pathvector.push_back(new_pathv[l]); + } - if (subpath_counter == subpath) { - to_back = *path_it; - } else { - tmp_path.push_back(*path_it); - } - subpath_counter++; - } - tmp_path.push_back(to_back); - setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); -} - -void Pointwise::subpathReverse(size_t start, size_t end) -{ - start++; - for (size_t i = end; i >= start; i--) { - _satellites.insert(_satellites.begin() + end + 1, _satellites[i]); - _satellites.erase(_satellites.begin() + i); - } - Geom::PathVector path_in = - path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); - size_t counter = 0; - size_t subpath_counter = 0; - Geom::Path sat_path = path_in.pathAt(start); - boost::optional< Geom::PathVectorTime > sat_curve_time_optional = path_in.nearestTime(path_in.curveAt(start).initialPoint()); - Geom::PathVectorTime sat_curve_time; - if(sat_curve_time_optional) { - sat_curve_time = *sat_curve_time_optional; } - sat_curve_time.normalizeForward(sat_path.size()); - size_t subpath = sat_curve_time.path_index; - Geom::PathVector tmp_path; - Geom::Path rev; - for (Geom::PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) { - if (path_it->empty()) { - continue; - } - counter++; - if (subpath_counter == subpath) { - tmp_path.push_back(path_it->reversed()); - } else { - tmp_path.push_back(*path_it); - } - subpath_counter++; - } - setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01)); + setPwd2(A); + setSatellites(sats); } -void Pointwise::insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S) +void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) { size_t size_A = A.size(); size_t size_B = B.curveCount(); @@ -238,31 +133,21 @@ void Pointwise::insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector con if (satellite_gap == 0) { return; } - size_t counter = 0; size_t counter_added = 0; - for (Geom::PathVector::const_iterator path_it = B.begin(); - path_it != B.end(); ++path_it) { - if (path_it->empty()) { + for (size_t i = 0; i < B.size(); i++) { + size_t counter = 0; + if (B[i]->empty()) { continue; } - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed()) { - Geom::Curve const &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() && counter_added < satellite_gap) { + for (size_t j = 0; j < B[i].size(); j++) { + if ((B[i][j].isDegenerate() && counter_added < satellite_gap) { counter_added++; - _satellites.insert(_satellites.begin() + counter + 1 ,S); + _satellites[i].insert(_satellites[i].begin() + counter + 1 ,S); } ++curve_it1; counter++; } } - setPwd2(A); } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index a2324accd..4c2ec7957 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -28,44 +28,27 @@ /** * @brief Pointwise a class to manage a vector of satellites per piecewise curve */ -typedef Geom::Piecewise > pwd2sb; +typedef Geom::Piecewise > PwD2SBasisasis; +typedef std::vector< Satelites > Satelites; class Pointwise { public: - pwd2sb getPwd2() const; - void setPwd2(pwd2sb const &pwd2_in); - /** - * @parameter curve_based allow the use of a satellite on last node of open paths - * if not curve based - */ - std::vector getSatellites(); - void setSatellites(std::vector const &sats); - - /** Update the start satellite on open/closed paths. - */ - void setStart(); - /** Fired when a path is modified. - */ - void recalculateForNewPwd2(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); - /** Some nodes/subpaths are removed. - */ - void pwd2Subtract(pwd2sb const &A); - /** Append nodes/subpaths to current pointwise - */ - void pwd2Append(pwd2sb const &A, Satellite const &S); - /** Send a subpath to end and update satellites - */ - void subpathToBack(size_t subpath); - /** Reverse a subpath and update satellites - */ - void subpathReverse(size_t start, size_t end); - /** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. - */ - void insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); + PwD2SBasis getPwd2() const; + Geom::Pathvector getPV() const; + void setPwd2(PwD2SBasis const &pwd2_in); + Satelites getSatellites(); + size_t getTotalSatellites(); + void setSatellites(Satelites const &sats); + void recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S); + //Fired when a path is modified. + void recalculatePwD2(PwD2SBasis const &A, Satellite const &S); + //Recalculate satellites + void insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S); + //Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. private: - pwd2sb _pwd2; + PwD2SBasis _pwd2; Geom::PathVector _pathvector; - std::vector _satellites; + Satelites _satellites; }; #endif //SEEN_POINTWISE_H diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 615106dd9..027497d78 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -32,7 +32,6 @@ Satellite::Satellite() {} Satellite::Satellite(SatelliteType satellite_type) : satellite_type(satellite_type), is_time(false), - active(false), has_mirror(false), hidden(true), amount(0.0), @@ -54,7 +53,6 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in) return 0; } - //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- Geom::D2 d2_in = curve_in.toSBasis(); double t = 0; double length_part = curve_in.length(); @@ -63,9 +61,8 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in) t = A / length_part; } } else if (!curve_in.isLineSegment()) { - std::vector t_roots = roots(Geom::arcLengthSb(d2_in) - A); - if (t_roots.size() > 0) { + if (!t_roots.empty()) { t = t_roots[0]; } } @@ -82,8 +79,6 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in) return 0; } - //using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast- - Geom::D2 d2_in = curve_in.toSBasis(); double s = 0; double length_part = curve_in.length(); if (A > length_part || curve_in.isLineSegment()) { @@ -91,6 +86,7 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in) } else if (!curve_in.isLineSegment()) { Geom::Curve *curve = curve_in.portion(0.0, A); s = curve->length(); + delete curve; } return s; } @@ -105,7 +101,7 @@ double Satellite::radToLen( double len = 0; Geom::D2 d2_in = curve_in.toSBasis(); Geom::D2 d2_out = curve_out.toSBasis(); - Geom::Piecewise > offset_curve0 = + Geom::Piecewise > offset_curve0 = Geom::Piecewise >(d2_in) + rot90(unitVector(derivative(d2_in))) * (A); Geom::Piecewise > offset_curve1 = @@ -136,30 +132,28 @@ double Satellite::lenToRad( { double time_in = (previousSatellite).time(A, true, curve_in); double time_out = timeAtArcLength(A, curve_out); - Geom::Point startArcPoint = curve_in.pointAt(time_in); - Geom::Point endArcPoint = curve_out.pointAt(time_out); - Geom::Curve *knotCurve1 = curve_in.portion(0, time_in); - Geom::Curve *knotCurve2 = curve_out.portion(time_out, 1); - Geom::CubicBezier const *cubic1 = - dynamic_cast(&*knotCurve1); + Geom::Point start_arc_point = curve_in.pointAt(time_in); + Geom::Point end_arc_point = curve_out.pointAt(time_out); + Geom::Curve *knot_curve1 = curve_in.portion(0, time_in); + Geom::Curve *knot_curve2 = curve_out.portion(time_out, 1); + Geom::cubic_bezier const *cubic1 = dynamic_cast(&*knot_curve1); Geom::Ray ray1(startArcPoint, curve_in.pointAt(1)); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } - Geom::CubicBezier const *cubic2 = - dynamic_cast(&*knotCurve2); + Geom::cubic_bezier const *cubic2 = dynamic_cast(&*knot_curve2); Geom::Ray ray2(curve_out.pointAt(0), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); } - bool ccwToggle = cross(curve_in.pointAt(1) - startArcPoint, - endArcPoint - startArcPoint) < 0; - double distanceArc = + bool ccw_toggle = cross(curve_in.pointAt(1) - startArcPoint, + end_arc_point - startArcPoint) < 0; + double distance_arc = Geom::distance(startArcPoint, middle_point(startArcPoint, endArcPoint)); - double angleBetween = angle_between(ray1, ray2, ccwToggle); - double divisor = std::sin(angleBetween / 2.0); + double angle_between = angle_between(ray1, ray2, ccw_toggle); + double divisor = std::sin(angle_between / 2.0); if (divisor > 0) { - return distanceArc / divisor; + return distance_arc / divisor; } return 0; } @@ -167,12 +161,12 @@ double Satellite::lenToRad( /** * Get the time position of the satellite in curve_in */ -double Satellite::time(Geom::Curve const &curve_in, bool const I) const +double Satellite::time(Geom::Curve const &curve_in, bool inverse) const { double t = amount; if (!is_time) { - t = time(t, I, curve_in); - } else if (I) { + t = time(t, inverse, curve_in); + } else if (inverse) { t = 1-t; } if (t > 1) { @@ -182,18 +176,18 @@ double Satellite::time(Geom::Curve const &curve_in, bool const I) const } /**. - * Get the time from a length A in other curve, a bolean I gived to reverse time + * Get the time from a length A in other curve, a bolean inverse gived to reverse time */ -double Satellite::time(double A, bool const I, +double Satellite::time(double A, bool inverse, Geom::Curve const &curve_in) const { - if (A == 0 && I) { + if (A == 0 && inverse) { return 1; } - if (A == 0 && !I) { + if (A == 0 && !inverse) { return 0; } - if (!I) { + if (!inverse) { return timeAtArcLength(A, curve_in); } double length_part = curve_in.length(); @@ -216,19 +210,19 @@ double Satellite::arcDistance(Geom::Curve const &curve_in) const /** * Get the point position of the satellite */ -Geom::Point Satellite::getPosition(Geom::Curve const &curve_in, bool const I) const +Geom::Point Satellite::getPosition(Geom::Curve const &curve_in, bool inverse) const { - double t = time(curve_in, I); + double t = time(curve_in, inverse); return curve_in.pointAt(t); } /** * Set the position of the satellite from a gived point P */ -void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool const I) +void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool inverse) { Geom::Curve * curve = const_cast(&curve_in); - if (I) { + if (inverse) { curve = curve->reverse(); } double A = Geom::nearest_time(p, *curve); diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index 2369dddbd..6cf891ec5 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -39,10 +39,6 @@ public: { is_time = set_is_time; } - void setActive(bool set_active) - { - active = set_active; - } void setHasMirror(bool set_has_mirror) { has_mirror = set_has_mirror; @@ -69,20 +65,22 @@ public: double radToLen(double const A, Geom::Curve const &curve_in, Geom::Curve const &curve_out) const; - double time(Geom::Curve const &curve_in, bool const I = false) const; - double time(double A, bool const I, Geom::Curve const &curve_in) const; + double time(Geom::Curve const &curve_in, bool inverse = false) const; + double time(double A, bool inverse, Geom::Curve const &curve_in) const; double arcDistance(Geom::Curve const &curve_in) const; - void setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool const I = false); - Geom::Point getPosition(Geom::Curve const &curve_in, bool const I = false) const; + void setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool inverse = false); + Geom::Point getPosition(Geom::Curve const &curve_in, bool inverse = false) const; void setSatelliteType(gchar const *A); gchar const *getSatelliteTypeGchar() const; SatelliteType satellite_type; + //The value stored could be a time value of the satellite in the curve ot a distance on the curve + //"is_time" tell is if is a time or lenght value bool is_time; - bool active; bool has_mirror; bool hidden; + //in "amount" we store the time or distance used in the satellite double amount; double angle; size_t steps; -- cgit v1.2.3 From 07717a370b8efe6ddbb0c69d115bb063a2e7686a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 10 May 2016 23:16:49 +0200 Subject: Working with path updates (bzr r13645.1.130) --- src/helper/geom-pointwise.cpp | 63 ++++++++++++++++++++++--------------------- src/helper/geom-pointwise.h | 12 ++++----- src/helper/geom-satellite.cpp | 22 +++++++-------- 3 files changed, 49 insertions(+), 48 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index a96b7cbda..a7082ec24 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -15,42 +15,41 @@ */ #include - PwD2SBasis Pointwise::getPwd2() const { return _pwd2; } -Geom::Pathvector Pointwise::getPV() const +Geom::PathVector Pointwise::getPV() const { return _pathvector; } void Pointwise::setPwd2(PwD2SBasis const &pwd2_in) { - _pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); _pwd2 = pwd2_in; + _pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); } -Satelites Pointwise::getSatellites() +Satellites Pointwise::getSatellites() { return _satellites; } size_t Pointwise::getTotalSatellites() { - size_t counter = 0 - for (size_t i = 0; i < satellites.size(); ++i) { - for (size_t j = 0; j < satellites[i].size(); ++j) { + size_t counter = 0; + for (size_t i = 0; i < _satellites.size(); ++i) { + for (size_t j = 0; j < _satellites[i].size(); ++j) { counter++; } } return counter; } -void Pointwise::setSatellites(Satelites const &sats) +void Pointwise::setSatellites(Satellites const &satellites) { - _satellites = sats; + _satellites = satellites; } void Pointwise::recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) @@ -64,7 +63,7 @@ void Pointwise::recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector cons void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) { - Satelites sats; + Satellites satellites; Geom::PathVector new_pathv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); Geom::PathVector old_pathv = _pathvector; _pathvector.clear(); @@ -74,11 +73,8 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) for (size_t i = 0; i < new_pathv.size(); i++) { bool match = false; for (size_t j = 0; j < old_pathv.size(); j++) { - std::vector subpath_satellites; if ( new_pathv[i] == old_pathv[j]){ - _pathvector.push_back(old_pathv[j]; - sats.push_back(_satellites[j]); - _satellites.erase(_satellites.begin() + j); + satellites.push_back(_satellites[j]); old_pathv.erase(old_pathv.begin() + j); new_pathv.erase(new_pathv.begin() + i); match = true; @@ -86,12 +82,11 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) } } if (!match && new_size > old_increments){ - _pathvector.push_back(new_pathv[i]); - std::vector subpath_satellites; - for (size_t k = 0; k < new_pathv[i].size(); k++) { + std::vector subpath_satellites; + for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { subpath_satellites.push_back(Satellite(_satellites[0][0].satellite_type)); } - sats.push_back(subpath_satellites); + satellites.push_back(subpath_satellites); old_increments ++; } } @@ -99,30 +94,37 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) //we asume not change the order of subpaths when remove or add nodes to existing subpaths for (size_t l = 0; l < old_pathv.size(); l++) { //we assume we only can delete or add nodes not a mix of both + std::vector subpath_satellites; if (old_pathv[l].size() > new_pathv[l].size()){ //erase nodes for (size_t m = 0; m < old_pathv[l].size(); m++) { - if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint()) { - _satellites[l].erase(_satellites.begin() + m); + if (are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint())) { + subpath_satellites.push_back(_satellites[l][m]); } } - } else if (old_pathv[l].size() > new_pathv[l].size()) { + if (!old_pathv[l].closed() && + are_near(old_pathv[l][old_pathv[l].size() - 1].finalPoint(), new_pathv[l][new_pathv[l].size() - 1].finalPoint())) + { + subpath_satellites.push_back(_satellites[l][old_pathv[l].size()]); + } + } else if (old_pathv[l].size() < new_pathv[l].size()) { //add nodes for (size_t m = 0; m < old_pathv[l].size(); m++) { - if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint()) { - _satellites[l].insert(_satellites.begin() + m, S); + if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint())) { + _satellites[l].insert(_satellites[l].begin() + m, S); } } + if (!old_pathv[l].closed() && !are_near(old_pathv[l][old_pathv[l].size()-1].finalPoint(), new_pathv[l][old_pathv[l].size()-1].finalPoint())) { + _satellites[l].insert(_satellites[l].begin() + old_pathv[l].size(), S); + } } else { //never happends } - sats.push_back(_satellites[l]); - _pathvector.push_back(new_pathv[l]); - + satellites.push_back(subpath_satellites); } } setPwd2(A); - setSatellites(sats); + setSatellites(satellites); } void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) @@ -136,15 +138,14 @@ void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector size_t counter_added = 0; for (size_t i = 0; i < B.size(); i++) { size_t counter = 0; - if (B[i]->empty()) { + if (B[i].empty()) { continue; } - for (size_t j = 0; j < B[i].size(); j++) { - if ((B[i][j].isDegenerate() && counter_added < satellite_gap) { + for (size_t j = 0; j < B[i].size_closed(); j++) { + if (B[i][j].isDegenerate() && counter_added < satellite_gap) { counter_added++; _satellites[i].insert(_satellites[i].begin() + counter + 1 ,S); } - ++curve_it1; counter++; } } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 4c2ec7957..fa03a5db7 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -28,16 +28,16 @@ /** * @brief Pointwise a class to manage a vector of satellites per piecewise curve */ -typedef Geom::Piecewise > PwD2SBasisasis; -typedef std::vector< Satelites > Satelites; +typedef Geom::Piecewise > PwD2SBasis; +typedef std::vector > Satellites; class Pointwise { public: PwD2SBasis getPwd2() const; - Geom::Pathvector getPV() const; + Geom::PathVector getPV() const; void setPwd2(PwD2SBasis const &pwd2_in); - Satelites getSatellites(); + Satellites getSatellites(); size_t getTotalSatellites(); - void setSatellites(Satelites const &sats); + void setSatellites(Satellites const &satellites); void recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S); //Fired when a path is modified. void recalculatePwD2(PwD2SBasis const &A, Satellite const &S); @@ -48,7 +48,7 @@ public: private: PwD2SBasis _pwd2; Geom::PathVector _pathvector; - Satelites _satellites; + Satellites _satellites; }; #endif //SEEN_POINTWISE_H diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 027497d78..2672a571b 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -136,22 +136,22 @@ double Satellite::lenToRad( Geom::Point end_arc_point = curve_out.pointAt(time_out); Geom::Curve *knot_curve1 = curve_in.portion(0, time_in); Geom::Curve *knot_curve2 = curve_out.portion(time_out, 1); - Geom::cubic_bezier const *cubic1 = dynamic_cast(&*knot_curve1); - Geom::Ray ray1(startArcPoint, curve_in.pointAt(1)); + Geom::CubicBezier const *cubic1 = dynamic_cast(&*knot_curve1); + Geom::Ray ray1(start_arc_point, curve_in.pointAt(1)); if (cubic1) { - ray1.setPoints((*cubic1)[2], startArcPoint); + ray1.setPoints((*cubic1)[2], start_arc_point); } - Geom::cubic_bezier const *cubic2 = dynamic_cast(&*knot_curve2); - Geom::Ray ray2(curve_out.pointAt(0), endArcPoint); + Geom::CubicBezier const *cubic2 = dynamic_cast(&*knot_curve2); + Geom::Ray ray2(curve_out.pointAt(0), end_arc_point); if (cubic2) { - ray2.setPoints(endArcPoint, (*cubic2)[1]); + ray2.setPoints(end_arc_point, (*cubic2)[1]); } - bool ccw_toggle = cross(curve_in.pointAt(1) - startArcPoint, - end_arc_point - startArcPoint) < 0; + bool ccw_toggle = cross(curve_in.pointAt(1) - start_arc_point, + end_arc_point - start_arc_point) < 0; double distance_arc = - Geom::distance(startArcPoint, middle_point(startArcPoint, endArcPoint)); - double angle_between = angle_between(ray1, ray2, ccw_toggle); - double divisor = std::sin(angle_between / 2.0); + Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)); + double angle = angle_between(ray1, ray2, ccw_toggle); + double divisor = std::sin(angle / 2.0); if (divisor > 0) { return distance_arc / divisor; } -- cgit v1.2.3 From b03cc6d03c9cfa57ebee8c70412e96c5d92f4f83 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 11 May 2016 22:27:45 +0200 Subject: pre-remove of subpath update satellites (bzr r13645.1.132) --- src/helper/geom-pointwise.cpp | 147 ++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 71 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index a7082ec24..1fbed612c 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -54,11 +54,13 @@ void Pointwise::setSatellites(Satellites const &satellites) void Pointwise::recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) { - if (_pwd2.size() > A.size() || _pwd2.size() < A.size()) { - recalculatePwD2(A, S); - } else { - insertDegenerateSatellites(A, B, S); - } +//Remove subpath update for this version of fillet chamfer +// if (_pwd2.size() > A.size() || _pwd2.size() < A.size()) { +// recalculatePwD2(A, S); +// } else { +// //insertDegenerateSatellites(A, B, S); +// } + recalculatePwD2(A, S); } void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) @@ -69,7 +71,7 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) _pathvector.clear(); size_t new_size = new_pathv.size(); size_t old_size = old_pathv.size(); - size_t old_increments = old_size; +// size_t old_increments = old_size; for (size_t i = 0; i < new_pathv.size(); i++) { bool match = false; for (size_t j = 0; j < old_pathv.size(); j++) { @@ -81,76 +83,79 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) break; } } - if (!match && new_size > old_increments){ - std::vector subpath_satellites; - for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { - subpath_satellites.push_back(Satellite(_satellites[0][0].satellite_type)); - } - satellites.push_back(subpath_satellites); - old_increments ++; - } - } - if (new_size == old_size) { - //we asume not change the order of subpaths when remove or add nodes to existing subpaths - for (size_t l = 0; l < old_pathv.size(); l++) { - //we assume we only can delete or add nodes not a mix of both - std::vector subpath_satellites; - if (old_pathv[l].size() > new_pathv[l].size()){ - //erase nodes - for (size_t m = 0; m < old_pathv[l].size(); m++) { - if (are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint())) { - subpath_satellites.push_back(_satellites[l][m]); - } - } - if (!old_pathv[l].closed() && - are_near(old_pathv[l][old_pathv[l].size() - 1].finalPoint(), new_pathv[l][new_pathv[l].size() - 1].finalPoint())) - { - subpath_satellites.push_back(_satellites[l][old_pathv[l].size()]); - } - } else if (old_pathv[l].size() < new_pathv[l].size()) { - //add nodes - for (size_t m = 0; m < old_pathv[l].size(); m++) { - if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint())) { - _satellites[l].insert(_satellites[l].begin() + m, S); - } - } - if (!old_pathv[l].closed() && !are_near(old_pathv[l][old_pathv[l].size()-1].finalPoint(), new_pathv[l][old_pathv[l].size()-1].finalPoint())) { - _satellites[l].insert(_satellites[l].begin() + old_pathv[l].size(), S); - } - } else { - //never happends - } - satellites.push_back(subpath_satellites); + //Removed subpath update for this version of fillet chamfer + std::vector subpath_satellites; + for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { + subpath_satellites.push_back(S); } + satellites.push_back(subpath_satellites); } - setPwd2(A); - setSatellites(satellites); -} -void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) -{ - size_t size_A = A.size(); - size_t size_B = B.curveCount(); - size_t satellite_gap = size_B - size_A; - if (satellite_gap == 0) { - return; - } - size_t counter_added = 0; - for (size_t i = 0; i < B.size(); i++) { - size_t counter = 0; - if (B[i].empty()) { - continue; - } - for (size_t j = 0; j < B[i].size_closed(); j++) { - if (B[i][j].isDegenerate() && counter_added < satellite_gap) { - counter_added++; - _satellites[i].insert(_satellites[i].begin() + counter + 1 ,S); - } - counter++; - } - } +// if (new_size == old_size) { +// //TODO: ensure select remaining old_path subpath with the updated subpath remaining in new_path +// //This cam make bug with reversed paths or reorderer ones. +// for (size_t l = 0; l < old_pathv.size(); l++) { +// //we assume we only can delete or add nodes not a mix of both +// std::vector subpath_satellites; +// if (old_pathv[l].size() > new_pathv[l].size()){ +// //erase nodes +// size_t erased = 0; +// for (size_t m = 0; m < old_pathv[l].size(); m++) { +// if (are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m - erased].initialPoint())) { +// subpath_satellites.push_back(_satellites[l][m]); +// } else { +// erased++; +// } +// } +// if (!old_pathv[l].closed() && +// are_near(old_pathv[l][old_pathv[l].size() - 1].finalPoint(), new_pathv[l][new_pathv[l].size() - 1].finalPoint())) +// { +// subpath_satellites.push_back(_satellites[l][old_pathv[l].size()]); +// } +// } else if (old_pathv[l].size() < new_pathv[l].size()) { +// //add nodes +// for (size_t m = 0; m < old_pathv[l].size(); m++) { +// if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint())) { +// _satellites[l].insert(_satellites[l].begin() + m, S); +// } +// } +// if (!old_pathv[l].closed() && !are_near(old_pathv[l][old_pathv[l].size()-1].finalPoint(), new_pathv[l][old_pathv[l].size()-1].finalPoint())) { +// _satellites[l].insert(_satellites[l].begin() + old_pathv[l].size(), S); +// } +// } else { +// //never happends +// } +// satellites.push_back(subpath_satellites); +// } +// } setPwd2(A); + setSatellites(satellites); } +//Remove subpath update for this version of fillet chamfer +//void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) +//{ +// size_t size_A = A.size(); +// size_t size_B = B.curveCount(); +// size_t satellite_gap = size_B - size_A; +// if (satellite_gap == 0) { +// return; +// } +// size_t counter_added = 0; +// for (size_t i = 0; i < B.size(); i++) { +// size_t counter = 0; +// if (B[i].empty()) { +// continue; +// } +// for (size_t j = 0; j < B[i].size_closed(); j++) { +// if (B[i][j].isDegenerate() && counter_added < satellite_gap) { +// counter_added++; +// _satellites[i].insert(_satellites[i].begin() + counter + 1 ,S); +// } +// counter++; +// } +// } +// setPwd2(A); +//} /* Local Variables: -- cgit v1.2.3 From c103f187da67d1e2a9d31f45248a415945b1e5c7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 13 May 2016 22:09:34 +0200 Subject: Fiximg pointwise (bzr r13645.1.133) --- src/helper/geom-pointwise.cpp | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 1fbed612c..a4e5530a4 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -77,18 +77,32 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) for (size_t j = 0; j < old_pathv.size(); j++) { if ( new_pathv[i] == old_pathv[j]){ satellites.push_back(_satellites[j]); - old_pathv.erase(old_pathv.begin() + j); - new_pathv.erase(new_pathv.begin() + i); +// old_pathv.erase(old_pathv.begin() + j); +// new_pathv.erase(new_pathv.begin() + i); + + std::cout << "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmatch\n"; + _pathvector.push_back(new_pathv[i]); match = true; break; } } - //Removed subpath update for this version of fillet chamfer - std::vector subpath_satellites; - for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { - subpath_satellites.push_back(S); + if (!match && new_size > old_size) { + //Removed subpath update for this version of fillet chamfer + std::vector subpath_satellites; + for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { + subpath_satellites.push_back(S); + } + _pathvector.push_back(new_pathv[i]); + satellites.push_back(subpath_satellites); + } else if(!match) { + //Removed subpath update for this version of fillet chamfer + std::vector subpath_satellites; + for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { + subpath_satellites.push_back(S); + } + _pathvector.push_back(new_pathv[i]); + satellites.push_back(subpath_satellites); } - satellites.push_back(subpath_satellites); } // if (new_size == old_size) { @@ -128,8 +142,10 @@ void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) // satellites.push_back(subpath_satellites); // } // } - setPwd2(A); + Geom::Piecewise > pwd2 = remove_short_cuts(paths_to_pw(_pathvector), 0.01);; + setPwd2(pwd2); setSatellites(satellites); + std::cout << _satellites.size() << "ssssssssssssssssssssss\n"; } //Remove subpath update for this version of fillet chamfer //void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) -- cgit v1.2.3 From 4c145e43f8ab8d8040fb2fa42309f7bd400f6349 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 14 May 2016 23:52:45 +0200 Subject: Fixing pointwise (bzr r13645.1.135) --- src/helper/geom-pointwise.cpp | 143 +++++------------------------------------- src/helper/geom-pointwise.h | 24 ++----- 2 files changed, 21 insertions(+), 146 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index a4e5530a4..6ed6e8f83 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -15,20 +15,14 @@ */ #include -PwD2SBasis Pointwise::getPwd2() const -{ - return _pwd2; -} - -Geom::PathVector Pointwise::getPV() const +Geom::PathVector Pointwise::getPathVector() const { return _pathvector; } -void Pointwise::setPwd2(PwD2SBasis const &pwd2_in) +void Pointwise::setPathVector(Geom::PathVector pathv) { - _pwd2 = pwd2_in; - _pathvector = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01); + _pathvector = pathv; } Satellites Pointwise::getSatellites() @@ -36,6 +30,11 @@ Satellites Pointwise::getSatellites() return _satellites; } +void Pointwise::setSatellites(Satellites satellites) +{ + _satellites = satellites; +} + size_t Pointwise::getTotalSatellites() { size_t counter = 0; @@ -47,131 +46,19 @@ size_t Pointwise::getTotalSatellites() return counter; } -void Pointwise::setSatellites(Satellites const &satellites) -{ - _satellites = satellites; -} - -void Pointwise::recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) -{ -//Remove subpath update for this version of fillet chamfer -// if (_pwd2.size() > A.size() || _pwd2.size() < A.size()) { -// recalculatePwD2(A, S); -// } else { -// //insertDegenerateSatellites(A, B, S); -// } - recalculatePwD2(A, S); -} - -void Pointwise::recalculatePwD2(PwD2SBasis const &A, Satellite const &S) +void Pointwise::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const &S) { Satellites satellites; - Geom::PathVector new_pathv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01); - Geom::PathVector old_pathv = _pathvector; - _pathvector.clear(); - size_t new_size = new_pathv.size(); - size_t old_size = old_pathv.size(); -// size_t old_increments = old_size; - for (size_t i = 0; i < new_pathv.size(); i++) { - bool match = false; - for (size_t j = 0; j < old_pathv.size(); j++) { - if ( new_pathv[i] == old_pathv[j]){ - satellites.push_back(_satellites[j]); -// old_pathv.erase(old_pathv.begin() + j); -// new_pathv.erase(new_pathv.begin() + i); - - std::cout << "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmatch\n"; - _pathvector.push_back(new_pathv[i]); - match = true; - break; - } - } - if (!match && new_size > old_size) { - //Removed subpath update for this version of fillet chamfer - std::vector subpath_satellites; - for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { - subpath_satellites.push_back(S); - } - _pathvector.push_back(new_pathv[i]); - satellites.push_back(subpath_satellites); - } else if(!match) { - //Removed subpath update for this version of fillet chamfer - std::vector subpath_satellites; - for (size_t k = 0; k < new_pathv[i].size_closed(); k++) { - subpath_satellites.push_back(S); - } - _pathvector.push_back(new_pathv[i]); - satellites.push_back(subpath_satellites); + for (size_t i = 0; i < pathv.size(); i++) { + std::vector subpath_satellites; + for (size_t k = 0; k < pathv[i].size_closed(); k++) { + subpath_satellites.push_back(S); } + satellites.push_back(subpath_satellites); } - -// if (new_size == old_size) { -// //TODO: ensure select remaining old_path subpath with the updated subpath remaining in new_path -// //This cam make bug with reversed paths or reorderer ones. -// for (size_t l = 0; l < old_pathv.size(); l++) { -// //we assume we only can delete or add nodes not a mix of both -// std::vector subpath_satellites; -// if (old_pathv[l].size() > new_pathv[l].size()){ -// //erase nodes -// size_t erased = 0; -// for (size_t m = 0; m < old_pathv[l].size(); m++) { -// if (are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m - erased].initialPoint())) { -// subpath_satellites.push_back(_satellites[l][m]); -// } else { -// erased++; -// } -// } -// if (!old_pathv[l].closed() && -// are_near(old_pathv[l][old_pathv[l].size() - 1].finalPoint(), new_pathv[l][new_pathv[l].size() - 1].finalPoint())) -// { -// subpath_satellites.push_back(_satellites[l][old_pathv[l].size()]); -// } -// } else if (old_pathv[l].size() < new_pathv[l].size()) { -// //add nodes -// for (size_t m = 0; m < old_pathv[l].size(); m++) { -// if (!are_near(old_pathv[l][m].initialPoint(), new_pathv[l][m].initialPoint())) { -// _satellites[l].insert(_satellites[l].begin() + m, S); -// } -// } -// if (!old_pathv[l].closed() && !are_near(old_pathv[l][old_pathv[l].size()-1].finalPoint(), new_pathv[l][old_pathv[l].size()-1].finalPoint())) { -// _satellites[l].insert(_satellites[l].begin() + old_pathv[l].size(), S); -// } -// } else { -// //never happends -// } -// satellites.push_back(subpath_satellites); -// } -// } - Geom::Piecewise > pwd2 = remove_short_cuts(paths_to_pw(_pathvector), 0.01);; - setPwd2(pwd2); + setPathVector(pathv); setSatellites(satellites); - std::cout << _satellites.size() << "ssssssssssssssssssssss\n"; } -//Remove subpath update for this version of fillet chamfer -//void Pointwise::insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S) -//{ -// size_t size_A = A.size(); -// size_t size_B = B.curveCount(); -// size_t satellite_gap = size_B - size_A; -// if (satellite_gap == 0) { -// return; -// } -// size_t counter_added = 0; -// for (size_t i = 0; i < B.size(); i++) { -// size_t counter = 0; -// if (B[i].empty()) { -// continue; -// } -// for (size_t j = 0; j < B[i].size_closed(); j++) { -// if (B[i][j].isDegenerate() && counter_added < satellite_gap) { -// counter_added++; -// _satellites[i].insert(_satellites[i].begin() + counter + 1 ,S); -// } -// counter++; -// } -// } -// setPwd2(A); -//} /* Local Variables: diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index fa03a5db7..047de8dd3 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -18,35 +18,23 @@ #define SEEN_POINTWISE_H #include -#include <2geom/sbasis.h> -#include <2geom/sbasis-2d.h> -#include <2geom/piecewise.h> -#include <2geom/sbasis-to-bezier.h> #include <2geom/path.h> +#include <2geom/pathvector.h> #include /** - * @brief Pointwise a class to manage a vector of satellites per piecewise curve + * @brief Pointwise a class to manage a vector of satellites per curve */ -typedef Geom::Piecewise > PwD2SBasis; typedef std::vector > Satellites; class Pointwise { public: - PwD2SBasis getPwd2() const; - Geom::PathVector getPV() const; - void setPwd2(PwD2SBasis const &pwd2_in); + Geom::PathVector getPathVector() const; + void setPathVector(Geom::PathVector pathv); Satellites getSatellites(); size_t getTotalSatellites(); - void setSatellites(Satellites const &satellites); - void recalculateForNewPwd2(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S); - //Fired when a path is modified. - void recalculatePwD2(PwD2SBasis const &A, Satellite const &S); - //Recalculate satellites - void insertDegenerateSatellites(PwD2SBasis const &A, Geom::PathVector const &B, Satellite const &S); - //Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves. - + void setSatellites(Satellites satellites); + void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const &S); private: - PwD2SBasis _pwd2; Geom::PathVector _pathvector; Satellites _satellites; }; -- cgit v1.2.3 From c511141b70995ca7295df4ae244d7cc626f6ab73 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 21 May 2016 23:06:15 +0200 Subject: Update to refresh knots (bzr r13645.1.139) --- src/helper/geom-pointwise.cpp | 2 +- src/helper/geom-pointwise.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 6ed6e8f83..5531bb849 100644 --- a/src/helper/geom-pointwise.cpp +++ b/src/helper/geom-pointwise.cpp @@ -46,7 +46,7 @@ size_t Pointwise::getTotalSatellites() return counter; } -void Pointwise::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const &S) +void Pointwise::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { Satellites satellites; for (size_t i = 0; i < pathv.size(); i++) { diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index 047de8dd3..599234473 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -33,7 +33,7 @@ public: Satellites getSatellites(); size_t getTotalSatellites(); void setSatellites(Satellites satellites); - void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const &S); + void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); private: Geom::PathVector _pathvector; Satellites _satellites; -- cgit v1.2.3 From 634be67d2fa8aa07d25d96e10a3ad24fdfdcc80e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 26 May 2016 20:44:19 +0200 Subject: Rename branch (bzr r13645.1.145) --- src/helper/CMakeLists.txt | 4 +- src/helper/Makefile_insert | 4 +- src/helper/geom-pathvectorsatellites.cpp | 74 ++++++++++++++++++++++++++++++++ src/helper/geom-pathvectorsatellites.h | 53 +++++++++++++++++++++++ src/helper/geom-pointwise.cpp | 74 -------------------------------- src/helper/geom-pointwise.h | 54 ----------------------- 6 files changed, 131 insertions(+), 132 deletions(-) create mode 100644 src/helper/geom-pathvectorsatellites.cpp create mode 100644 src/helper/geom-pathvectorsatellites.h delete mode 100644 src/helper/geom-pointwise.cpp delete mode 100644 src/helper/geom-pointwise.h (limited to 'src/helper') diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt index aa99934b6..92709e4e9 100644 --- a/src/helper/CMakeLists.txt +++ b/src/helper/CMakeLists.txt @@ -14,7 +14,7 @@ set(helper_SRC geom.cpp geom-nodetype.cpp geom-pathstroke.cpp - geom-pointwise.cpp + geom-pathvectorsatellites.cpp geom-satellite.cpp gnome-utils.cpp pixbuf-ops.cpp @@ -34,7 +34,7 @@ set(helper_SRC geom-curves.h geom-nodetype.h geom-pathstroke.h - geom-pointwise.h + geom-pathvectorsatellites.h geom-satellite.h geom.h gnome-utils.h diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 54588d0ce..6ba0efbfa 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -14,8 +14,8 @@ ink_common_sources += \ helper/geom-nodetype.h \ helper/geom-pathstroke.cpp \ helper/geom-pathstroke.h \ - helper/geom-pointwise.cpp \ - helper/geom-pointwise.h \ + helper/geom-pathvectorsatellites.cpp \ + helper/geom-pathvectorsatellites.h \ helper/geom-satellite.cpp \ helper/geom-satellite.h \ helper/gnome-utils.cpp \ diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp new file mode 100644 index 000000000..a5207ab00 --- /dev/null +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -0,0 +1,74 @@ +/** + * \file + * \brief PathVectorSatellites a class to manage a vector of satellites per piecewise node + */ /* + * Authors: + * Jabiertxof + * Nathan Hurst + * Johan Engelen + * Josh Andler + * suv + * Mc- + * Liam P. White + * Krzysztof Kosiński + * This code is in public domain + */ + +#include +Geom::PathVector PathVectorSatellites::getPathVector() const +{ + return _pathvector; +} + +void PathVectorSatellites::setPathVector(Geom::PathVector pathv) +{ + _pathvector = pathv; +} + +Satellites PathVectorSatellites::getSatellites() +{ + return _satellites; +} + +void PathVectorSatellites::setSatellites(Satellites satellites) +{ + _satellites = satellites; +} + +size_t PathVectorSatellites::getTotalSatellites() +{ + size_t counter = 0; + for (size_t i = 0; i < _satellites.size(); ++i) { + for (size_t j = 0; j < _satellites[i].size(); ++j) { + counter++; + } + } + return counter; +} + +void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) +{ + Satellites satellites; + for (size_t i = 0; i < pathv.size(); i++) { + std::vector subpath_satellites; + for (size_t k = 0; k < pathv[i].size_closed(); k++) { + subpath_satellites.push_back(S); + } + satellites.push_back(subpath_satellites); + } + setPathVector(pathv); + setSatellites(satellites); +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/helper/geom-pathvectorsatellites.h b/src/helper/geom-pathvectorsatellites.h new file mode 100644 index 000000000..72ecef38f --- /dev/null +++ b/src/helper/geom-pathvectorsatellites.h @@ -0,0 +1,53 @@ +/** + * \file + * \brief PathVectorSatellites a class to manage a vector of satellites per piecewise node + */ /* + * Authors: + * Jabiertxof + * Nathan Hurst + * Johan Engelen + * Josh Andler + * suv + * Mc- + * Liam P. White + * Krzysztof Kosiński + * This code is in public domain + */ + +#ifndef SEEN_PATHVECTORSATELLITES_H +#define SEEN_PATHVECTORSATELLITES_H + +#include +#include <2geom/path.h> +#include <2geom/pathvector.h> + +/** + * @brief PathVectorSatellites a class to manage a vector of satellites per curve + */ +typedef std::vector > Satellites; +class PathVectorSatellites { +public: + Geom::PathVector getPathVector() const; + void setPathVector(Geom::PathVector pathv); + Satellites getSatellites(); + void setSatellites(Satellites satellites); + size_t getTotalSatellites(); + void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); +private: + Geom::PathVector _pathvector; + Satellites _satellites; +}; + +#endif //SEEN_PATHVECTORSATELLITES_H +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: +// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 +// : diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp deleted file mode 100644 index 5531bb849..000000000 --- a/src/helper/geom-pointwise.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/** - * \file - * \brief Pointwise a class to manage a vector of satellites per piecewise node - */ /* - * Authors: - * Jabiertxof - * Nathan Hurst - * Johan Engelen - * Josh Andler - * suv - * Mc- - * Liam P. White - * Krzysztof Kosiński - * This code is in public domain - */ - -#include -Geom::PathVector Pointwise::getPathVector() const -{ - return _pathvector; -} - -void Pointwise::setPathVector(Geom::PathVector pathv) -{ - _pathvector = pathv; -} - -Satellites Pointwise::getSatellites() -{ - return _satellites; -} - -void Pointwise::setSatellites(Satellites satellites) -{ - _satellites = satellites; -} - -size_t Pointwise::getTotalSatellites() -{ - size_t counter = 0; - for (size_t i = 0; i < _satellites.size(); ++i) { - for (size_t j = 0; j < _satellites[i].size(); ++j) { - counter++; - } - } - return counter; -} - -void Pointwise::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) -{ - Satellites satellites; - for (size_t i = 0; i < pathv.size(); i++) { - std::vector subpath_satellites; - for (size_t k = 0; k < pathv[i].size_closed(); k++) { - subpath_satellites.push_back(S); - } - satellites.push_back(subpath_satellites); - } - setPathVector(pathv); - setSatellites(satellites); -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: -// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 -// : diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h deleted file mode 100644 index 599234473..000000000 --- a/src/helper/geom-pointwise.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - * \file - * \brief Pointwise a class to manage a vector of satellites per piecewise node - */ /* - * Authors: - * Jabiertxof - * Nathan Hurst - * Johan Engelen - * Josh Andler - * suv - * Mc- - * Liam P. White - * Krzysztof Kosiński - * This code is in public domain - */ - -#ifndef SEEN_POINTWISE_H -#define SEEN_POINTWISE_H - -#include -#include <2geom/path.h> -#include <2geom/pathvector.h> -#include - -/** - * @brief Pointwise a class to manage a vector of satellites per curve - */ -typedef std::vector > Satellites; -class Pointwise { -public: - Geom::PathVector getPathVector() const; - void setPathVector(Geom::PathVector pathv); - Satellites getSatellites(); - size_t getTotalSatellites(); - void setSatellites(Satellites satellites); - void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); -private: - Geom::PathVector _pathvector; - Satellites _satellites; -}; - -#endif //SEEN_POINTWISE_H -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: -// filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 -// : -- cgit v1.2.3 From d84bbca17771ed1a2f680328adf14b30a4c66b77 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 01:05:25 +0200 Subject: Fix the bug deleting satellites (bzr r13645.1.148) --- src/helper/geom-pathvectorsatellites.cpp | 13 +++++++++++++ src/helper/geom-pathvectorsatellites.h | 1 + 2 files changed, 14 insertions(+) (limited to 'src/helper') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index a5207ab00..c423c9b1b 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -46,6 +46,19 @@ size_t PathVectorSatellites::getTotalSatellites() return counter; } +std::pair PathVectorSatellites::getIndexData(size_t index) +{ + size_t counter = 0; + for (size_t i = 0; i < _satellites.size(); ++i) { + for (size_t j = 0; j < _satellites[i].size(); ++j) { + if (index == counter) { + return std::make_pair(i,j); + } + counter++; + } + } + return std::make_pair(0,0); +} void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { Satellites satellites; diff --git a/src/helper/geom-pathvectorsatellites.h b/src/helper/geom-pathvectorsatellites.h index 72ecef38f..483611db5 100644 --- a/src/helper/geom-pathvectorsatellites.h +++ b/src/helper/geom-pathvectorsatellites.h @@ -32,6 +32,7 @@ public: Satellites getSatellites(); void setSatellites(Satellites satellites); size_t getTotalSatellites(); + std::pair getIndexData(size_t index); void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); private: Geom::PathVector _pathvector; -- cgit v1.2.3 From 1b8a4e46125f60f7bbe497bde69a11b7b3153b00 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 12:09:57 +0200 Subject: Handle path add and remove nodes (bzr r13645.1.150) --- src/helper/geom-pathvectorsatellites.cpp | 40 ++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index c423c9b1b..625506b2f 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -59,15 +59,47 @@ std::pair PathVectorSatellites::getIndexData(size_t index) } return std::make_pair(0,0); } + void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { Satellites satellites; + bool found = false; + //TODO evaluate fix on nodes at same position + size_t number_nodes = pathv.nodes().size(); + size_t previous_number_nodes = _pathvector.nodes().size(); for (size_t i = 0; i < pathv.size(); i++) { - std::vector subpath_satellites; - for (size_t k = 0; k < pathv[i].size_closed(); k++) { - subpath_satellites.push_back(S); + satellites.reserve(pathv.size()); + std::vector pathsatellites; + for (size_t j = 0; j < pathv[i].size_closed(); j++) { + satellites[i].reserve(pathv[i].size_closed()); + found = false; + for (size_t k = 0; k < _pathvector.size(); k++) { + for (size_t l = 0; l < _pathvector[k].size_closed(); l++) { + if ((l == _pathvector[k].size_closed() -1 && + j == pathv[i].size_closed() -1 && + Geom::are_near(_pathvector[k][l-1].finalPoint(), pathv[i][j-1].finalPoint())) || + (l == _pathvector[k].size_closed() -1 && + Geom::are_near(_pathvector[k][l-1].finalPoint(), pathv[i][j].finalPoint())) || + (j == pathv[i].size_closed() -1 && + Geom::are_near(_pathvector[k][l].finalPoint(), pathv[i][j-1].finalPoint())) || + (Geom::are_near(_pathvector[k][l].initialPoint(), pathv[i][j].initialPoint()))) + { + pathsatellites.push_back(_satellites[k][l]); + std::cout << "dgsgdsgsdgsdgsdgsdgsdgsdgsdgsdgsd\n"; + found = true; + break; + } + } + if (found) { + break; + } + } + + if (found == false && previous_number_nodes < number_nodes) { + pathsatellites.push_back(S); + } } - satellites.push_back(subpath_satellites); + satellites.push_back(pathsatellites); } setPathVector(pathv); setSatellites(satellites); -- cgit v1.2.3 From 73f078b27b669c941651ecf14a3119ae491ccabf Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 13 Jun 2016 00:58:55 +0200 Subject: Fix 90% of tweenk review (bzr r13645.1.155) --- src/helper/geom-pathvectorsatellites.cpp | 111 ++++++++++++++++++++++++++++++- src/helper/geom-pathvectorsatellites.h | 11 +-- src/helper/geom-satellite.cpp | 58 +++++----------- src/helper/geom-satellite.h | 13 ++-- 4 files changed, 143 insertions(+), 50 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index 625506b2f..c56887f53 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -1,6 +1,6 @@ /** * \file - * \brief PathVectorSatellites a class to manage a vector of satellites per piecewise node + * \brief PathVectorSatellites a class to manage satellites -per node extra data- in a pathvector */ /* * Authors: * Jabiertxof @@ -60,6 +60,115 @@ std::pair PathVectorSatellites::getIndexData(size_t index) return std::make_pair(0,0); } +void PathVectorSatellites::setSelected(std::vector selected) +{ + size_t counter = 0; + for (size_t i = 0; i < _satellites.size(); ++i) { + for (size_t j = 0; j < _satellites[i].size(); ++j) { + if(find (selected.begin(), selected.end(), counter) != selected.end()){ + _satellites[i][j].setSelected(true); + } else { + _satellites[i][j].setSelected(false); + } + counter++; + } + } +} + +void PathVectorSatellites::updateSteps(size_t steps, bool apply_no_radius, bool apply_with_radius, bool only_selected) +{ + for (size_t i = 0; i < _satellites.size(); ++i) { + for (size_t j = 0; j < _satellites[i].size(); ++j) { + if ((!apply_no_radius && _satellites[i][j].amount == 0) || + (!apply_with_radius && _satellites[i][j].amount != 0)) + { + continue; + } + if (only_selected) { + if (_satellites[i][j].selected) { + _satellites[i][j].steps = steps; + } + } else { + _satellites[i][j].steps = steps; + } + } + } +} + +void PathVectorSatellites::updateAmount(double radius, bool apply_no_radius, bool apply_with_radius, bool only_selected, + bool use_knot_distance, bool flexible) +{ + double power = 0; + if (!flexible) { + power = radius; + } else { + power = radius / 100; + } + for (size_t i = 0; i < _satellites.size(); ++i) { + for (size_t j = 0; j < _satellites[i].size(); ++j) { + boost::optional previous_index = boost::none; + if(j == 0 && _pathvector[i].closed()){ + previous_index = _pathvector[i].size() - 1; + } else if(!_pathvector[i].closed() || j != 0) { + previous_index = j - 1; + } + if (!_pathvector[i].closed() && j == 0) { + _satellites[i][j].amount = 0; + continue; + } + if (_pathvector[i].size() == j) { + continue; + } + if ((!apply_no_radius && _satellites[i][j].amount == 0) || + (!apply_with_radius && _satellites[i][j].amount != 0)) + { + continue; + } + + Geom::Point satellite_point = _pathvector[i].pointAt(j); + if (_satellites[i][j].selected || !only_selected) { + if (!use_knot_distance && !flexible) { + if(previous_index) { + _satellites[i][j].amount = _satellites[i][j].radToLen(power, _pathvector[i][*previous_index], _pathvector[i][j]); + } else { + _satellites[i][j].amount = 0.0; + } + } else { + _satellites[i][j].amount = power; + } + } + } + } +} + +void PathVectorSatellites::updateSatelliteType(SatelliteType satellitetype, bool apply_no_radius, bool apply_with_radius, + bool only_selected) +{ + for (size_t i = 0; i < _satellites.size(); ++i) { + for (size_t j = 0; j < _satellites[i].size(); ++j) { + if ((!apply_no_radius && _satellites[i][j].amount == 0) || + (!apply_with_radius && _satellites[i][j].amount != 0)) + { + continue; + } + if (_pathvector[i].size() == j) { + if (!only_selected) { + _satellites[i][j].satellite_type = satellitetype; + } + continue; + } + if (only_selected) { + Geom::Point satellite_point = _pathvector[i].pointAt(j); + if (_satellites[i][j].selected) { + _satellites[i][j].satellite_type = satellitetype; + } + } else { + _satellites[i][j].satellite_type = satellitetype; + } + } + } +} + void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { Satellites satellites; diff --git a/src/helper/geom-pathvectorsatellites.h b/src/helper/geom-pathvectorsatellites.h index 483611db5..4a020f553 100644 --- a/src/helper/geom-pathvectorsatellites.h +++ b/src/helper/geom-pathvectorsatellites.h @@ -1,6 +1,6 @@ /** * \file - * \brief PathVectorSatellites a class to manage a vector of satellites per piecewise node + * \brief PathVectorSatellites a class to manage satellites -per node extra data- in a pathvector */ /* * Authors: * Jabiertxof @@ -21,10 +21,8 @@ #include <2geom/path.h> #include <2geom/pathvector.h> -/** - * @brief PathVectorSatellites a class to manage a vector of satellites per curve - */ typedef std::vector > Satellites; +///@brief PathVectorSatellites a class to manage satellites in a pathvector class PathVectorSatellites { public: Geom::PathVector getPathVector() const; @@ -32,6 +30,11 @@ public: Satellites getSatellites(); void setSatellites(Satellites satellites); size_t getTotalSatellites(); + void setSelected(std::vector selected); + void updateSteps(size_t steps, bool apply_no_radius, bool apply_with_radius, bool only_selected); + void updateAmount(double radius, bool apply_no_radius, bool apply_with_radius, bool only_selected, + bool use_knot_distance, bool flexible); + void updateSatelliteType(SatelliteType satellitetype, bool apply_no_radius, bool apply_with_radius, bool only_selected); std::pair getIndexData(size_t index); void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); private: diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 2672a571b..1242c9aaf 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -1,6 +1,6 @@ /** * \file - * \brief Satellite a per ?node/curve holder of data. + * \brief Satellite a per node holder of data. */ /* * Authors: * 2015 Jabier Arraiza Cenoz @@ -23,15 +23,14 @@ #include #endif -/** - * @brief Satellite a per ?node/curve holder of data. - */ +///@brief Satellite a per node holder of data. Satellite::Satellite() {} Satellite::Satellite(SatelliteType satellite_type) : satellite_type(satellite_type), is_time(false), + selected(false), has_mirror(false), hidden(true), amount(0.0), @@ -41,12 +40,8 @@ Satellite::Satellite(SatelliteType satellite_type) Satellite::~Satellite() {} -/** - * Calculate the time in curve_in with a size of A - * TODO: find a better place to it - */ - - +///Calculate the time in curve_in with a size of A +//TODO: find a better place to it double timeAtArcLength(double const A, Geom::Curve const &curve_in) { if ( A == 0 || curve_in.isDegenerate()) { @@ -69,10 +64,8 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in) return t; } -/** - * Calculate the size in curve_in with a point at A - * TODO: find a better place to it - */ +///Calculate the size in curve_in with a point at A +//TODO: find a better place to it double arcLengthAt(double const A, Geom::Curve const &curve_in) { if ( A == 0 || curve_in.isDegenerate()) { @@ -91,9 +84,7 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in) return s; } -/** - * Convert a arc radius of a fillet/chamfer to his satellite length -point position where fillet/chamfer knot be on original curve - */ +///Convert a arc radius of a fillet/chamfer to his satellite length -point position where fillet/chamfer knot be on original curve double Satellite::radToLen( double const A, Geom::Curve const &curve_in, Geom::Curve const &curve_out) const @@ -122,9 +113,7 @@ double Satellite::radToLen( return len; } -/** -* Convert a satelite length -point position where fillet/chamfer knot be on original curve- to a arc radius of fillet/chamfer -*/ +///Convert a satelite length -point position where fillet/chamfer knot be on original curve- to a arc radius of fillet/chamfer double Satellite::lenToRad( double const A, Geom::Curve const &curve_in, Geom::Curve const &curve_out, @@ -158,9 +147,7 @@ double Satellite::lenToRad( return 0; } -/** - * Get the time position of the satellite in curve_in - */ +///Get the time position of the satellite in curve_in double Satellite::time(Geom::Curve const &curve_in, bool inverse) const { double t = amount; @@ -175,9 +162,7 @@ double Satellite::time(Geom::Curve const &curve_in, bool inverse) const return t; } -/**. - * Get the time from a length A in other curve, a bolean inverse gived to reverse time - */ +///Get the time from a length A in other curve, a bolean inverse gived to reverse time double Satellite::time(double A, bool inverse, Geom::Curve const &curve_in) const { @@ -195,9 +180,7 @@ double Satellite::time(double A, bool inverse, return timeAtArcLength(A, curve_in); } -/** - * Get the length of the satellite in curve_in - */ +///Get the length of the satellite in curve_in double Satellite::arcDistance(Geom::Curve const &curve_in) const { double s = amount; @@ -207,18 +190,14 @@ double Satellite::arcDistance(Geom::Curve const &curve_in) const return s; } -/** - * Get the point position of the satellite - */ +///Get the point position of the satellite Geom::Point Satellite::getPosition(Geom::Curve const &curve_in, bool inverse) const { double t = time(curve_in, inverse); return curve_in.pointAt(t); } -/** - * Set the position of the satellite from a gived point P - */ +///Set the position of the satellite from a gived point P void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bool inverse) { Geom::Curve * curve = const_cast(&curve_in); @@ -232,9 +211,8 @@ void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bo amount = A; } -/** - * Map a satellite type with gchar - */ + +///Map a satellite type with gchar void Satellite::setSatelliteType(gchar const *A) { std::map gchar_map_to_satellite_type = @@ -245,9 +223,7 @@ void Satellite::setSatelliteType(gchar const *A) } } -/** - * Map a gchar with satelliteType - */ +///Map a gchar with satelliteType gchar const *Satellite::getSatelliteTypeGchar() const { std::map satellite_type_to_gchar_map = diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index 6cf891ec5..a4d63d66e 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -1,6 +1,6 @@ /** * \file - * \brief Satellite a per ?node/curve holder of data. + * \brief Satellite a per node holder of data. */ /* * Authors: * 2015 Jabier Arraiza Cenoz @@ -25,7 +25,7 @@ enum SatelliteType { INVALID_SATELLITE // Invalid Satellite }; /** - * @brief Satellite a per ?node/curve holder of data. + * @brief Satellite a per node holder of data. */ class Satellite { @@ -39,6 +39,10 @@ public: { is_time = set_is_time; } + void setSelected(bool set_selected) + { + selected = set_selected; + } void setHasMirror(bool set_has_mirror) { has_mirror = set_has_mirror; @@ -75,9 +79,10 @@ public: void setSatelliteType(gchar const *A); gchar const *getSatelliteTypeGchar() const; SatelliteType satellite_type; - //The value stored could be a time value of the satellite in the curve ot a distance on the curve + //The value stored could be a time value of the satellite in the curve or a lenght of distance to the node from the satellite //"is_time" tell is if is a time or lenght value bool is_time; + bool selected; bool has_mirror; bool hidden; //in "amount" we store the time or distance used in the satellite @@ -85,7 +90,7 @@ public: double angle; size_t steps; }; -//cache_limit never called as 1 + double timeAtArcLength(double const A, Geom::Curve const &curve_in); double arcLengthAt(double const A, Geom::Curve const &curve_in); -- cgit v1.2.3 From c5f642fbd66ccb150d361d2861d0b1baa744dcba Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 18 Jun 2016 15:07:51 +0200 Subject: Pre fixing selected points (bzr r13645.1.161) --- src/helper/geom-pathvectorsatellites.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index c56887f53..e80d812d7 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -63,11 +63,16 @@ std::pair PathVectorSatellites::getIndexData(size_t index) void PathVectorSatellites::setSelected(std::vector selected) { size_t counter = 0; + for (size_t h = 0; h < selected.size(); ++h) { + std::cout << selected[h] << "vec\n"; + } for (size_t i = 0; i < _satellites.size(); ++i) { for (size_t j = 0; j < _satellites[i].size(); ++j) { if(find (selected.begin(), selected.end(), counter) != selected.end()){ + std::cout << counter << "true\n"; _satellites[i][j].setSelected(true); } else { + std::cout << "false\n"; _satellites[i][j].setSelected(false); } counter++; @@ -171,6 +176,7 @@ void PathVectorSatellites::updateSatelliteType(SatelliteType satellitetype, bool void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { + return; Satellites satellites; bool found = false; //TODO evaluate fix on nodes at same position @@ -194,7 +200,6 @@ void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pa (Geom::are_near(_pathvector[k][l].initialPoint(), pathv[i][j].initialPoint()))) { pathsatellites.push_back(_satellites[k][l]); - std::cout << "dgsgdsgsdgsdgsdgsdgsdgsdgsdgsdgsd\n"; found = true; break; } -- cgit v1.2.3 From 38a1a4d45114a681408e763c3afec79f0bc21940 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 18 Jun 2016 18:53:51 +0200 Subject: fixing bug moving nodes (bzr r13645.1.162) --- src/helper/geom-pathvectorsatellites.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index e80d812d7..1f71a2e91 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -176,7 +176,6 @@ void PathVectorSatellites::updateSatelliteType(SatelliteType satellitetype, bool void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) { - return; Satellites satellites; bool found = false; //TODO evaluate fix on nodes at same position -- cgit v1.2.3 From 6820ee49d69cd419c5e8d3c9de74b0552758c842 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 19 Jun 2016 00:58:42 +0200 Subject: Fixes when moves a path (bzr r13645.1.163) --- src/helper/geom-pathvectorsatellites.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index 1f71a2e91..f72841b30 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -63,16 +63,11 @@ std::pair PathVectorSatellites::getIndexData(size_t index) void PathVectorSatellites::setSelected(std::vector selected) { size_t counter = 0; - for (size_t h = 0; h < selected.size(); ++h) { - std::cout << selected[h] << "vec\n"; - } for (size_t i = 0; i < _satellites.size(); ++i) { for (size_t j = 0; j < _satellites[i].size(); ++j) { if(find (selected.begin(), selected.end(), counter) != selected.end()){ - std::cout << counter << "true\n"; _satellites[i][j].setSelected(true); } else { - std::cout << "false\n"; _satellites[i][j].setSelected(false); } counter++; @@ -182,23 +177,14 @@ void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pa size_t number_nodes = pathv.nodes().size(); size_t previous_number_nodes = _pathvector.nodes().size(); for (size_t i = 0; i < pathv.size(); i++) { - satellites.reserve(pathv.size()); - std::vector pathsatellites; + std::vector path_satellites; for (size_t j = 0; j < pathv[i].size_closed(); j++) { - satellites[i].reserve(pathv[i].size_closed()); found = false; for (size_t k = 0; k < _pathvector.size(); k++) { for (size_t l = 0; l < _pathvector[k].size_closed(); l++) { - if ((l == _pathvector[k].size_closed() -1 && - j == pathv[i].size_closed() -1 && - Geom::are_near(_pathvector[k][l-1].finalPoint(), pathv[i][j-1].finalPoint())) || - (l == _pathvector[k].size_closed() -1 && - Geom::are_near(_pathvector[k][l-1].finalPoint(), pathv[i][j].finalPoint())) || - (j == pathv[i].size_closed() -1 && - Geom::are_near(_pathvector[k][l].finalPoint(), pathv[i][j-1].finalPoint())) || - (Geom::are_near(_pathvector[k][l].initialPoint(), pathv[i][j].initialPoint()))) + if (Geom::are_near(_pathvector[k][l].initialPoint(), pathv[i][j].initialPoint())) { - pathsatellites.push_back(_satellites[k][l]); + path_satellites.push_back(_satellites[k][l]); found = true; break; } @@ -208,11 +194,11 @@ void PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pa } } - if (found == false && previous_number_nodes < number_nodes) { - pathsatellites.push_back(S); + if (!found && previous_number_nodes < number_nodes) { + path_satellites.push_back(S); } } - satellites.push_back(pathsatellites); + satellites.push_back(path_satellites); } setPathVector(pathv); setSatellites(satellites); -- cgit v1.2.3 From 417ba16c9f42a5476045ca4f1825fff2fed518ba Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 19 Jun 2016 03:30:10 +0200 Subject: Organize doeffect function (bzr r13645.1.164) --- src/helper/geom-pathvectorsatellites.cpp | 8 ++++---- src/helper/geom-satellite.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index f72841b30..eca866978 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -65,7 +65,7 @@ void PathVectorSatellites::setSelected(std::vector selected) size_t counter = 0; for (size_t i = 0; i < _satellites.size(); ++i) { for (size_t j = 0; j < _satellites[i].size(); ++j) { - if(find (selected.begin(), selected.end(), counter) != selected.end()){ + if (find (selected.begin(), selected.end(), counter) != selected.end()) { _satellites[i][j].setSelected(true); } else { _satellites[i][j].setSelected(false); @@ -107,9 +107,9 @@ void PathVectorSatellites::updateAmount(double radius, bool apply_no_radius, boo for (size_t i = 0; i < _satellites.size(); ++i) { for (size_t j = 0; j < _satellites[i].size(); ++j) { boost::optional previous_index = boost::none; - if(j == 0 && _pathvector[i].closed()){ + if (j == 0 && _pathvector[i].closed()) { previous_index = _pathvector[i].size() - 1; - } else if(!_pathvector[i].closed() || j != 0) { + } else if (!_pathvector[i].closed() || j != 0) { previous_index = j - 1; } if (!_pathvector[i].closed() && j == 0) { @@ -128,7 +128,7 @@ void PathVectorSatellites::updateAmount(double radius, bool apply_no_radius, boo Geom::Point satellite_point = _pathvector[i].pointAt(j); if (_satellites[i][j].selected || !only_selected) { if (!use_knot_distance && !flexible) { - if(previous_index) { + if (previous_index) { _satellites[i][j].amount = _satellites[i][j].radToLen(power, _pathvector[i][*previous_index], _pathvector[i][j]); } else { _satellites[i][j].amount = 0.0; diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 1242c9aaf..8a92273d0 100644 --- a/src/helper/geom-satellite.cpp +++ b/src/helper/geom-satellite.cpp @@ -218,7 +218,7 @@ void Satellite::setSatelliteType(gchar const *A) std::map gchar_map_to_satellite_type = boost::assign::map_list_of("F", FILLET)("IF", INVERSE_FILLET)("C", CHAMFER)("IC", INVERSE_CHAMFER)("KO", INVALID_SATELLITE); std::map::iterator it = gchar_map_to_satellite_type.find(std::string(A)); - if(it != gchar_map_to_satellite_type.end()) { + if (it != gchar_map_to_satellite_type.end()) { satellite_type = it->second; } } -- cgit v1.2.3 From d1947e768272c703674129d5c583204ff2b59251 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 13 Jul 2016 13:36:19 +0200 Subject: Second part of new SPObject children list (bzr r14954.1.19) --- src/helper/pixbuf-ops.cpp | 4 ++-- src/helper/png-write.cpp | 4 ++-- src/helper/stock-items.cpp | 30 +++++++++++++++--------------- 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'src/helper') diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp index 9639096fb..fb1740fc5 100644 --- a/src/helper/pixbuf-ops.cpp +++ b/src/helper/pixbuf-ops.cpp @@ -53,8 +53,8 @@ static void hide_other_items_recursively(SPObject *o, GSList *list, unsigned dke // recurse if (!g_slist_find(list, o)) { - for ( SPObject *child = o->firstChild() ; child; child = child->getNext() ) { - hide_other_items_recursively(child, list, dkey); + for (auto& child: o->_children) { + hide_other_items_recursively(&child, list, dkey); } } } diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 9430feeff..c59db9df6 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -374,8 +374,8 @@ static void hide_other_items_recursively(SPObject *o, const std::vector // recurse if (list.end()==find(list.begin(),list.end(),o)) { - for ( SPObject *child = o->firstChild() ; child; child = child->getNext() ) { - hide_other_items_recursively(child, list, dkey); + for (auto& child: o->_children) { + hide_other_items_recursively(&child, list, dkey); } } } diff --git a/src/helper/stock-items.cpp b/src/helper/stock-items.cpp index 5a56b89ff..cf10a6c4d 100644 --- a/src/helper/stock-items.cpp +++ b/src/helper/stock-items.cpp @@ -204,37 +204,37 @@ SPObject *get_stock_item(gchar const *urn, gboolean stock) } SPObject *object = NULL; if (!strcmp(base, "marker") && !stock) { - for ( SPObject *child = defs->firstChild(); child; child = child->getNext() ) + for (auto& child: defs->_children) { - if (child->getRepr()->attribute("inkscape:stockid") && - !strcmp(name_p, child->getRepr()->attribute("inkscape:stockid")) && - SP_IS_MARKER(child)) + if (child.getRepr()->attribute("inkscape:stockid") && + !strcmp(name_p, child.getRepr()->attribute("inkscape:stockid")) && + SP_IS_MARKER(&child)) { - object = child; + object = &child; } } } else if (!strcmp(base,"pattern") && !stock) { - for ( SPObject *child = defs->firstChild() ; child; child = child->getNext() ) + for (auto& child: defs->_children) { - if (child->getRepr()->attribute("inkscape:stockid") && - !strcmp(name_p, child->getRepr()->attribute("inkscape:stockid")) && - SP_IS_PATTERN(child)) + if (child.getRepr()->attribute("inkscape:stockid") && + !strcmp(name_p, child.getRepr()->attribute("inkscape:stockid")) && + SP_IS_PATTERN(&child)) { - object = child; + object = &child; } } } else if (!strcmp(base,"gradient") && !stock) { - for ( SPObject *child = defs->firstChild(); child; child = child->getNext() ) + for (auto& child: defs->_children) { - if (child->getRepr()->attribute("inkscape:stockid") && - !strcmp(name_p, child->getRepr()->attribute("inkscape:stockid")) && - SP_IS_GRADIENT(child)) + if (child.getRepr()->attribute("inkscape:stockid") && + !strcmp(name_p, child.getRepr()->attribute("inkscape:stockid")) && + SP_IS_GRADIENT(&child)) { - object = child; + object = &child; } } -- cgit v1.2.3 From 24d3f50003ca3cec6a03a7f5267cc4fe5588c69f Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 14 Jul 2016 13:17:21 +0200 Subject: Renamed children list in SPObject (bzr r14954.1.21) --- src/helper/pixbuf-ops.cpp | 2 +- src/helper/png-write.cpp | 2 +- src/helper/stock-items.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/helper') diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp index fb1740fc5..24d2d7f1e 100644 --- a/src/helper/pixbuf-ops.cpp +++ b/src/helper/pixbuf-ops.cpp @@ -53,7 +53,7 @@ static void hide_other_items_recursively(SPObject *o, GSList *list, unsigned dke // recurse if (!g_slist_find(list, o)) { - for (auto& child: o->_children) { + for (auto& child: o->children) { hide_other_items_recursively(&child, list, dkey); } } diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index c59db9df6..2255157e2 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -374,7 +374,7 @@ static void hide_other_items_recursively(SPObject *o, const std::vector // recurse if (list.end()==find(list.begin(),list.end(),o)) { - for (auto& child: o->_children) { + for (auto& child: o->children) { hide_other_items_recursively(&child, list, dkey); } } diff --git a/src/helper/stock-items.cpp b/src/helper/stock-items.cpp index cf10a6c4d..647e42916 100644 --- a/src/helper/stock-items.cpp +++ b/src/helper/stock-items.cpp @@ -204,7 +204,7 @@ SPObject *get_stock_item(gchar const *urn, gboolean stock) } SPObject *object = NULL; if (!strcmp(base, "marker") && !stock) { - for (auto& child: defs->_children) + for (auto& child: defs->children) { if (child.getRepr()->attribute("inkscape:stockid") && !strcmp(name_p, child.getRepr()->attribute("inkscape:stockid")) && @@ -216,7 +216,7 @@ SPObject *get_stock_item(gchar const *urn, gboolean stock) } else if (!strcmp(base,"pattern") && !stock) { - for (auto& child: defs->_children) + for (auto& child: defs->children) { if (child.getRepr()->attribute("inkscape:stockid") && !strcmp(name_p, child.getRepr()->attribute("inkscape:stockid")) && @@ -228,7 +228,7 @@ SPObject *get_stock_item(gchar const *urn, gboolean stock) } else if (!strcmp(base,"gradient") && !stock) { - for (auto& child: defs->_children) + for (auto& child: defs->children) { if (child.getRepr()->attribute("inkscape:stockid") && !strcmp(name_p, child.getRepr()->attribute("inkscape:stockid")) && -- cgit v1.2.3 From f35bb1f74a0ffeb5c6477a25e3c4cde87a97bcf1 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 28 Jul 2016 12:06:06 +0200 Subject: Removed unused includes, decrease compilation time (bzr r15025) --- src/helper/action-context.cpp | 1 - src/helper/action.cpp | 2 -- src/helper/action.h | 1 + src/helper/geom-nodetype.cpp | 2 -- src/helper/geom-pathstroke.cpp | 4 ---- src/helper/geom.cpp | 7 ------- src/helper/pixbuf-ops.cpp | 6 +----- src/helper/png-write.cpp | 4 +--- 8 files changed, 3 insertions(+), 24 deletions(-) (limited to 'src/helper') diff --git a/src/helper/action-context.cpp b/src/helper/action-context.cpp index d52e43d96..1ea12776b 100644 --- a/src/helper/action-context.cpp +++ b/src/helper/action-context.cpp @@ -14,7 +14,6 @@ #include "layer-model.h" #include "selection.h" #include "helper/action-context.h" -#include "ui/view/view.h" namespace Inkscape { diff --git a/src/helper/action.cpp b/src/helper/action.cpp index 060bf317c..e37575a9c 100644 --- a/src/helper/action.cpp +++ b/src/helper/action.cpp @@ -9,8 +9,6 @@ * This code is in public domain */ -#include - #include "debug/logger.h" #include "debug/timestamp.h" #include "debug/simple-event.h" diff --git a/src/helper/action.h b/src/helper/action.h index 4b81ee7f9..9a16cdfc7 100644 --- a/src/helper/action.h +++ b/src/helper/action.h @@ -15,6 +15,7 @@ #include "helper/action-context.h" #include #include +#include #define SP_TYPE_ACTION (sp_action_get_type()) #define SP_ACTION(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_ACTION, SPAction)) diff --git a/src/helper/geom-nodetype.cpp b/src/helper/geom-nodetype.cpp index fe8e8af0e..da620b3fd 100644 --- a/src/helper/geom-nodetype.cpp +++ b/src/helper/geom-nodetype.cpp @@ -12,8 +12,6 @@ #include "helper/geom-nodetype.h" #include <2geom/curve.h> -#include <2geom/point.h> -#include namespace Geom { diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index d2e9f9a1b..10641692d 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -9,13 +9,9 @@ #include #include <2geom/path-sink.h> -#include <2geom/point.h> -#include <2geom/bezier-curve.h> -#include <2geom/elliptical-arc.h> #include <2geom/sbasis-to-bezier.h> // cubicbezierpath_from_sbasis #include <2geom/path-intersection.h> #include <2geom/circle.h> -#include #include "helper/geom-pathstroke.h" diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp index ecb330b01..42c494c00 100644 --- a/src/helper/geom.cpp +++ b/src/helper/geom.cpp @@ -12,15 +12,8 @@ #include #include "helper/geom.h" #include "helper/geom-curves.h" -#include -#include <2geom/pathvector.h> -#include <2geom/path.h> #include <2geom/curves.h> -#include <2geom/transforms.h> -#include <2geom/rect.h> -#include <2geom/coord.h> #include <2geom/sbasis-to-bezier.h> -#include // for M_PI using Geom::X; using Geom::Y; diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp index 9639096fb..8a363d736 100644 --- a/src/helper/pixbuf-ops.cpp +++ b/src/helper/pixbuf-ops.cpp @@ -12,10 +12,9 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif -#include #include #include <2geom/transforms.h> @@ -24,11 +23,8 @@ #include "display/cairo-utils.h" #include "display/drawing.h" #include "display/drawing-context.h" -#include "display/drawing-item.h" #include "document.h" -#include "sp-item.h" #include "sp-root.h" -#include "sp-use.h" #include "sp-defs.h" #include "util/units.h" diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 9430feeff..e2b7e5b8c 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -14,19 +14,17 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include #include "ui/interface.h" #include <2geom/rect.h> #include <2geom/transforms.h> -#include #include "png-write.h" #include "io/sys.h" #include "display/drawing.h" #include "display/drawing-context.h" -#include "display/drawing-item.h" #include "document.h" #include "sp-item.h" #include "sp-root.h" -- cgit v1.2.3 From 43b49e325db73cc19b1731db6c69545664ee8fbe Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 28 Jul 2016 13:26:17 +0200 Subject: Reverted changes to r15024 after many building problems (bzr r15027) --- src/helper/action-context.cpp | 1 + src/helper/action.cpp | 2 ++ src/helper/action.h | 1 - src/helper/geom-nodetype.cpp | 2 ++ src/helper/geom-pathstroke.cpp | 4 ++++ src/helper/geom.cpp | 7 +++++++ src/helper/pixbuf-ops.cpp | 6 +++++- src/helper/png-write.cpp | 4 +++- 8 files changed, 24 insertions(+), 3 deletions(-) (limited to 'src/helper') diff --git a/src/helper/action-context.cpp b/src/helper/action-context.cpp index 1ea12776b..d52e43d96 100644 --- a/src/helper/action-context.cpp +++ b/src/helper/action-context.cpp @@ -14,6 +14,7 @@ #include "layer-model.h" #include "selection.h" #include "helper/action-context.h" +#include "ui/view/view.h" namespace Inkscape { diff --git a/src/helper/action.cpp b/src/helper/action.cpp index e37575a9c..060bf317c 100644 --- a/src/helper/action.cpp +++ b/src/helper/action.cpp @@ -9,6 +9,8 @@ * This code is in public domain */ +#include + #include "debug/logger.h" #include "debug/timestamp.h" #include "debug/simple-event.h" diff --git a/src/helper/action.h b/src/helper/action.h index 9a16cdfc7..4b81ee7f9 100644 --- a/src/helper/action.h +++ b/src/helper/action.h @@ -15,7 +15,6 @@ #include "helper/action-context.h" #include #include -#include #define SP_TYPE_ACTION (sp_action_get_type()) #define SP_ACTION(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_ACTION, SPAction)) diff --git a/src/helper/geom-nodetype.cpp b/src/helper/geom-nodetype.cpp index da620b3fd..fe8e8af0e 100644 --- a/src/helper/geom-nodetype.cpp +++ b/src/helper/geom-nodetype.cpp @@ -12,6 +12,8 @@ #include "helper/geom-nodetype.h" #include <2geom/curve.h> +#include <2geom/point.h> +#include namespace Geom { diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 10641692d..d2e9f9a1b 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -9,9 +9,13 @@ #include #include <2geom/path-sink.h> +#include <2geom/point.h> +#include <2geom/bezier-curve.h> +#include <2geom/elliptical-arc.h> #include <2geom/sbasis-to-bezier.h> // cubicbezierpath_from_sbasis #include <2geom/path-intersection.h> #include <2geom/circle.h> +#include #include "helper/geom-pathstroke.h" diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp index 42c494c00..ecb330b01 100644 --- a/src/helper/geom.cpp +++ b/src/helper/geom.cpp @@ -12,8 +12,15 @@ #include #include "helper/geom.h" #include "helper/geom-curves.h" +#include +#include <2geom/pathvector.h> +#include <2geom/path.h> #include <2geom/curves.h> +#include <2geom/transforms.h> +#include <2geom/rect.h> +#include <2geom/coord.h> #include <2geom/sbasis-to-bezier.h> +#include // for M_PI using Geom::X; using Geom::Y; diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp index 8a363d736..9639096fb 100644 --- a/src/helper/pixbuf-ops.cpp +++ b/src/helper/pixbuf-ops.cpp @@ -12,9 +12,10 @@ */ #ifdef HAVE_CONFIG_H -#include +# include "config.h" #endif +#include #include #include <2geom/transforms.h> @@ -23,8 +24,11 @@ #include "display/cairo-utils.h" #include "display/drawing.h" #include "display/drawing-context.h" +#include "display/drawing-item.h" #include "document.h" +#include "sp-item.h" #include "sp-root.h" +#include "sp-use.h" #include "sp-defs.h" #include "util/units.h" diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index e2b7e5b8c..9430feeff 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -14,17 +14,19 @@ */ #ifdef HAVE_CONFIG_H -#include +# include "config.h" #endif #include #include "ui/interface.h" #include <2geom/rect.h> #include <2geom/transforms.h> +#include #include "png-write.h" #include "io/sys.h" #include "display/drawing.h" #include "display/drawing-context.h" +#include "display/drawing-item.h" #include "document.h" #include "sp-item.h" #include "sp-root.h" -- cgit v1.2.3 From 35830f456cadaecf8b8e3944e3031a1a93f6cb41 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 3 Aug 2016 15:29:38 +0200 Subject: Removed unused includes, decreased compilation time. Once again (bzr r15034) --- src/helper/action-context.cpp | 1 - src/helper/action.cpp | 2 -- src/helper/geom-nodetype.cpp | 2 -- src/helper/geom-pathstroke.cpp | 4 ---- src/helper/geom.cpp | 7 ------- src/helper/pixbuf-ops.cpp | 6 +----- src/helper/png-write.cpp | 4 +--- 7 files changed, 2 insertions(+), 24 deletions(-) (limited to 'src/helper') diff --git a/src/helper/action-context.cpp b/src/helper/action-context.cpp index d52e43d96..1ea12776b 100644 --- a/src/helper/action-context.cpp +++ b/src/helper/action-context.cpp @@ -14,7 +14,6 @@ #include "layer-model.h" #include "selection.h" #include "helper/action-context.h" -#include "ui/view/view.h" namespace Inkscape { diff --git a/src/helper/action.cpp b/src/helper/action.cpp index 060bf317c..e37575a9c 100644 --- a/src/helper/action.cpp +++ b/src/helper/action.cpp @@ -9,8 +9,6 @@ * This code is in public domain */ -#include - #include "debug/logger.h" #include "debug/timestamp.h" #include "debug/simple-event.h" diff --git a/src/helper/geom-nodetype.cpp b/src/helper/geom-nodetype.cpp index fe8e8af0e..da620b3fd 100644 --- a/src/helper/geom-nodetype.cpp +++ b/src/helper/geom-nodetype.cpp @@ -12,8 +12,6 @@ #include "helper/geom-nodetype.h" #include <2geom/curve.h> -#include <2geom/point.h> -#include namespace Geom { diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index d2e9f9a1b..10641692d 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -9,13 +9,9 @@ #include #include <2geom/path-sink.h> -#include <2geom/point.h> -#include <2geom/bezier-curve.h> -#include <2geom/elliptical-arc.h> #include <2geom/sbasis-to-bezier.h> // cubicbezierpath_from_sbasis #include <2geom/path-intersection.h> #include <2geom/circle.h> -#include #include "helper/geom-pathstroke.h" diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp index ecb330b01..42c494c00 100644 --- a/src/helper/geom.cpp +++ b/src/helper/geom.cpp @@ -12,15 +12,8 @@ #include #include "helper/geom.h" #include "helper/geom-curves.h" -#include -#include <2geom/pathvector.h> -#include <2geom/path.h> #include <2geom/curves.h> -#include <2geom/transforms.h> -#include <2geom/rect.h> -#include <2geom/coord.h> #include <2geom/sbasis-to-bezier.h> -#include // for M_PI using Geom::X; using Geom::Y; diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp index 9639096fb..8a363d736 100644 --- a/src/helper/pixbuf-ops.cpp +++ b/src/helper/pixbuf-ops.cpp @@ -12,10 +12,9 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif -#include #include #include <2geom/transforms.h> @@ -24,11 +23,8 @@ #include "display/cairo-utils.h" #include "display/drawing.h" #include "display/drawing-context.h" -#include "display/drawing-item.h" #include "document.h" -#include "sp-item.h" #include "sp-root.h" -#include "sp-use.h" #include "sp-defs.h" #include "util/units.h" diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 9430feeff..e2b7e5b8c 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -14,19 +14,17 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include #include "ui/interface.h" #include <2geom/rect.h> #include <2geom/transforms.h> -#include #include "png-write.h" #include "io/sys.h" #include "display/drawing.h" #include "display/drawing-context.h" -#include "display/drawing-item.h" #include "document.h" #include "sp-item.h" #include "sp-root.h" -- cgit v1.2.3 From e471a664f923f517b68071f2e33fbb6ce070f8b7 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Mon, 8 Aug 2016 13:56:40 +0100 Subject: Remove deprecated Autotools and btool files. Please use CMake instead (bzr r15046) --- src/helper/Makefile_insert | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 src/helper/Makefile_insert (limited to 'src/helper') diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert deleted file mode 100644 index e59fcfb70..000000000 --- a/src/helper/Makefile_insert +++ /dev/null @@ -1,45 +0,0 @@ -## Makefile.am fragment sourced by src/Makefile.am. - -helper/unit-menu.$(OBJEXT): helper/sp-marshal.h - -ink_common_sources += \ - helper/action.cpp \ - helper/action.h \ - helper/action-context.cpp \ - helper/action-context.h \ - helper/geom.cpp \ - helper/geom.h \ - helper/geom-curves.h \ - helper/geom-nodetype.cpp \ - helper/geom-nodetype.h \ - helper/geom-pathstroke.cpp \ - helper/geom-pathstroke.h \ - helper/gnome-utils.cpp \ - helper/gnome-utils.h \ - helper/mathfns.h \ - helper/png-write.cpp \ - helper/png-write.h \ - helper/sp-marshal.cpp \ - helper/sp-marshal.h \ - helper/window.cpp \ - helper/window.h \ - helper/stock-items.cpp \ - helper/stock-items.h - -# cmp exits with status 0 when there are no differences. "if" executes the commands -# after "then" when the exit status of the if command is 0 (this is crazy). -helper/sp-marshal.h: helper/sp-marshal.list - glib-genmarshal --prefix=sp_marshal --header $(srcdir)/helper/sp-marshal.list > helper/tmp.sp-marshal.h - if cmp -s helper/sp-marshal.h helper/tmp.sp-marshal.h; \ - then rm helper/tmp.sp-marshal.h; \ - else mv helper/tmp.sp-marshal.h helper/sp-marshal.h; fi - -helper/sp-marshal.cpp: helper/sp-marshal.list helper/sp-marshal.h - ( echo '#include "helper/sp-marshal.h"' && \ - glib-genmarshal --prefix=sp_marshal --body $(srcdir)/helper/sp-marshal.list ) \ - > helper/tmp.sp-marshal.cpp; \ - if cmp -s helper/sp-marshal.cpp helper/tmp.sp-marshal.cpp; \ - then rm helper/tmp.sp-marshal.cpp; \ - else mv helper/tmp.sp-marshal.cpp helper/sp-marshal.cpp; fi - -helper/sp-marshal.cpp helper/sp-marshal.h: helper/sp-marshal.list -- cgit v1.2.3 From ee2e7c9c9907008de656773b98e1239a7f1af2a9 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sun, 25 Sep 2016 23:59:45 +0200 Subject: Exposes to the user additional PNG settings: Interlacing, grayscale, bit depth, alpha, compression level, PNG pHYs dpi. Fixed bugs: - https://launchpad.net/bugs/170650 (bzr r15131) --- src/helper/png-write.cpp | 77 +++++++++++++++++++++++++++++------------------- src/helper/png-write.h | 6 ++-- 2 files changed, 50 insertions(+), 33 deletions(-) (limited to 'src/helper') diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 682aee9b2..f270dcc95 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -123,8 +123,8 @@ void PngTextList::add(gchar const* key, gchar const* text) static bool sp_png_write_rgba_striped(SPDocument *doc, gchar const *filename, unsigned long int width, unsigned long int height, double xdpi, double ydpi, - int (* get_rows)(guchar const **rows, void **to_free, int row, int num_rows, void *data), - void *data) + int (* get_rows)(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth), + void *data, bool interlace, int color_type, int bit_depth, int zlib) { g_return_val_if_fail(filename != NULL, false); g_return_val_if_fail(data != NULL, false); @@ -184,22 +184,28 @@ sp_png_write_rgba_striped(SPDocument *doc, * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED */ + + png_set_compression_level(png_ptr, zlib); + png_set_IHDR(png_ptr, info_ptr, width, height, - 8, /* bit_depth */ - PNG_COLOR_TYPE_RGB_ALPHA, - PNG_INTERLACE_NONE, + bit_depth, + color_type, + interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - /* otherwise, if we are dealing with a color image then */ - sig_bit.red = 8; - sig_bit.green = 8; - sig_bit.blue = 8; - /* if the image has an alpha channel then */ - sig_bit.alpha = 8; - png_set_sBIT(png_ptr, info_ptr, &sig_bit); + if ((color_type&2) && bit_depth == 16) { + // otherwise, if we are dealing with a color image then + sig_bit.red = 8; + sig_bit.green = 8; + sig_bit.blue = 8; + // if the image has an alpha channel then + if (color_type&4) + sig_bit.alpha = 8; + png_set_sBIT(png_ptr, info_ptr, &sig_bit); + } PngTextList textList; @@ -248,7 +254,10 @@ sp_png_write_rgba_striped(SPDocument *doc, /* other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs, */ /* note that if sRGB is present the cHRM chunk must be ignored * on read and must be written in accordance with the sRGB profile */ - png_set_pHYs(png_ptr, info_ptr, unsigned(xdpi / 0.0254 + 0.5), unsigned(ydpi / 0.0254 + 0.5), PNG_RESOLUTION_METER); + if(xdpi < 0.0254 ) xdpi = 0.0255; + if(ydpi < 0.0254 ) ydpi = 0.0255; + + png_set_pHYs(png_ptr, info_ptr, unsigned(xdpi / 0.0254 ), unsigned(ydpi / 0.0254 ), PNG_RESOLUTION_METER); /* Write the file header information. REQUIRED */ png_write_info(png_ptr, info_ptr); @@ -271,15 +280,18 @@ sp_png_write_rgba_striped(SPDocument *doc, */ png_bytep* row_pointers = new png_bytep[ebp->sheight]; - - r = 0; - while (r < static_cast(height)) { - void *to_free; - int n = get_rows((unsigned char const **) row_pointers, &to_free, r, height-r, data); - if (!n) break; - png_write_rows(png_ptr, row_pointers, n); - g_free(to_free); - r += n; + int number_of_passes = interlace ? png_set_interlace_handling(png_ptr) : 1; + + for(int i=0;i(height)) { + void *to_free; + int n = get_rows((unsigned char const **) row_pointers, &to_free, r, height-r, data, color_type, bit_depth); + if (!n) break; + png_write_rows(png_ptr, row_pointers, n); + g_free(to_free); + r += n; + } } delete[] row_pointers; @@ -308,7 +320,7 @@ sp_png_write_rgba_striped(SPDocument *doc, * */ static int -sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, void *data) +sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth) { struct SPEBP *ebp = (struct SPEBP *) data; @@ -343,14 +355,17 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v ebp->drawing->render(dc, bbox); cairo_surface_destroy(s); - *to_free = px; - // PNG stores data as unpremultiplied big-endian RGBA, which means // it's identical to the GdkPixbuf format. convert_pixels_argb32_to_pixbuf(px, ebp->width, num_rows, stride); + + *to_free = px; - for (int r = 0; r < num_rows; r++) { - rows[r] = px + r * stride; + // If a custom bit depth or color type is asked, then convert rgb to grayscale, etc. + if(color_type !=6 || bit_depth != 8){ + const guchar* new_data = pixbuf_to_png(rows, px, num_rows, ebp->width, stride, color_type, bit_depth); + *to_free = (void*) new_data; + free(px); } return num_rows; @@ -385,10 +400,10 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned int (*status) (float, void *), void *data, bool force_overwrite, - const std::vector &items_only) + const std::vector &items_only, bool interlace, int color_type, int bit_depth, int zlib) { return sp_export_png_file(doc, filename, Geom::Rect(Geom::Point(x0,y0),Geom::Point(x1,y1)), - width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only); + width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only, interlace, color_type, bit_depth, zlib); } ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, @@ -397,7 +412,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned (*status)(float, void *), void *data, bool force_overwrite, - const std::vector &items_only) + const std::vector &items_only, bool interlace, int color_type, int bit_depth, int zlib) { g_return_val_if_fail(doc != NULL, EXPORT_ERROR); g_return_val_if_fail(filename != NULL, EXPORT_ERROR); @@ -468,7 +483,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, ebp.px = g_try_new(guchar, 4 * ebp.sheight * width); if (ebp.px) { - write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp); + write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp, interlace, color_type, bit_depth, zlib); g_free(ebp.px); } diff --git a/src/helper/png-write.h b/src/helper/png-write.h index 2657fb635..e47f01743 100644 --- a/src/helper/png-write.h +++ b/src/helper/png-write.h @@ -34,12 +34,14 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, double x0, double y0, double x1, double y1, unsigned long int width, unsigned long int height, double xdpi, double ydpi, unsigned long bgcolor, - unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector &items_only = std::vector()); + unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector &items_only = std::vector(), + bool interlace = false, int color_type = 6, int bit_depth = 8, int zlib = 6); ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, Geom::Rect const &area, unsigned long int width, unsigned long int height, double xdpi, double ydpi, unsigned long bgcolor, - unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector &items_only = std::vector()); + unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector &items_only = std::vector(), + bool interlace = false, int color_type = 6, int bit_depth = 8, int zlib = 6); #endif // SEEN_SP_PNG_WRITE_H -- cgit v1.2.3 From efc66f4403df7128ef6ca2ac98893b477abff9bf Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Mon, 26 Sep 2016 00:50:43 +0200 Subject: minor fix (+ satisfy build bots (?)) (bzr r15132) --- src/helper/png-write.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/helper') diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index f270dcc95..2433e2777 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -359,14 +359,10 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v // it's identical to the GdkPixbuf format. convert_pixels_argb32_to_pixbuf(px, ebp->width, num_rows, stride); - *to_free = px; - // If a custom bit depth or color type is asked, then convert rgb to grayscale, etc. - if(color_type !=6 || bit_depth != 8){ - const guchar* new_data = pixbuf_to_png(rows, px, num_rows, ebp->width, stride, color_type, bit_depth); - *to_free = (void*) new_data; - free(px); - } + const guchar* new_data = pixbuf_to_png(rows, px, num_rows, ebp->width, stride, color_type, bit_depth); + *to_free = (void*) new_data; + free(px); return num_rows; } -- cgit v1.2.3 From 372648b362ae259e758c612512b10e543dfc9606 Mon Sep 17 00:00:00 2001 From: Alexander Brock Date: Sun, 27 Nov 2016 21:45:55 +0100 Subject: Improve precision of offset_cubic (bzr r15280.1.1) --- src/helper/geom-pathstroke.cpp | 180 ++++++++++++++++++++++++++++++++++------- 1 file changed, 149 insertions(+), 31 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 10641692d..905984a2a 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -1,6 +1,7 @@ /* Authors: * Liam P. White * Tavmjong Bah + * Alexander Brock * * Copyright (C) 2014-2015 Authors * @@ -746,33 +747,36 @@ void get_cubic_data(Geom::CubicBezier const& bez, double time, double& len, doub len = l; } -void offset_cubic(Geom::Path& p, Geom::CubicBezier const& bez, double width, double tol, size_t levels) -{ +double _offset_cubic_stable_sub( + Geom::CubicBezier const& bez, + Geom::CubicBezier& c, + const Geom::Point& start_normal, + const Geom::Point& end_normal, + const Geom::Point& start_new, + const Geom::Point& end_new, + const double start_rad, + const double end_rad, + const double start_len, + const double end_len, + const double width, + const double width_correction) { using Geom::X; using Geom::Y; - Geom::Point start_pos = bez.initialPoint(); - Geom::Point end_pos = bez.finalPoint(); - - Geom::Point start_normal = Geom::rot90(bez.unitTangentAt(0)); - Geom::Point end_normal = -Geom::rot90(Geom::unitTangentAt(Geom::reverse(bez.toSBasis()), 0.)); - - // offset the start and end control points out by the width - Geom::Point start_new = start_pos + start_normal*width; - Geom::Point end_new = end_pos + end_normal*width; - - // -------- - double start_rad, end_rad; - double start_len, end_len; // tangent lengths - get_cubic_data(bez, 0, start_len, start_rad); - get_cubic_data(bez, 1, end_len, end_rad); - double start_off = 1, end_off = 1; // correction of the lengths of the tangent to the offset if (!Geom::are_near(start_rad, 0)) - start_off += width / start_rad; + start_off += (width + width_correction) / start_rad; if (!Geom::are_near(end_rad, 0)) - end_off += width / end_rad; + end_off += (width + width_correction) / end_rad; + + // We don't change the direction of the control points + if (start_off < 0) { + start_off = 0; + } + if (end_off < 0) { + end_off = 0; + } start_off *= start_len; end_off *= end_len; // -------- @@ -783,23 +787,137 @@ void offset_cubic(Geom::Path& p, Geom::CubicBezier const& bez, double width, dou mid2_new = Geom::Point(end_new[X] - mid2_new[X]/3., end_new[Y] - mid2_new[Y]/3.); // create the estimate curve - Geom::CubicBezier c = Geom::CubicBezier(start_new, mid1_new, mid2_new, end_new); + c = Geom::CubicBezier(start_new, mid1_new, mid2_new, end_new); + + // check the tolerance for our estimate to be a parallel curve + + double worst_residual = 0; + for (size_t ii = 1; ii <= 9; ++ii) { + const double t = static_cast(ii) / 10; + const Geom::Point req = bez.pointAt(t); + const Geom::Point chk = c.pointAt(c.nearestTime(req)); + const double current_residual = (chk-req).length() - std::abs(width); + if (std::abs(current_residual) > std::abs(worst_residual)) { + worst_residual = current_residual; + } + } + return worst_residual; +} + +void offset_cubic(Geom::Path& p, Geom::CubicBezier const& bez, double width, double tol, size_t levels) +{ + using Geom::X; + using Geom::Y; + + const Geom::Point start_pos = bez.initialPoint(); + const Geom::Point end_pos = bez.finalPoint(); + + const Geom::Point start_normal = Geom::rot90(bez.unitTangentAt(0)); + const Geom::Point end_normal = -Geom::rot90(Geom::unitTangentAt(Geom::reverse(bez.toSBasis()), 0.)); + + // offset the start and end control points out by the width + const Geom::Point start_new = start_pos + start_normal*width; + const Geom::Point end_new = end_pos + end_normal*width; + + // -------- + double start_rad, end_rad; + double start_len, end_len; // tangent lengths + get_cubic_data(bez, 0, start_len, start_rad); + get_cubic_data(bez, 1, end_len, end_rad); + + + Geom::CubicBezier c; + + double best_width_correction = 0; + double best_residual = _offset_cubic_stable_sub( + bez, c, + start_normal, end_normal, + start_new, end_new, + start_rad, end_rad, + start_len, end_len, + width, best_width_correction); + double stepsize = std::abs(width)/2; + bool seen_success = false; + double stepsize_threshold = 0; + // std::cout << "Residual from " << best_residual << " "; + size_t ii = 0; + for (; ii < 100 && stepsize > stepsize_threshold; ++ii) { + bool success = false; + const double width_correction = best_width_correction - (best_residual > 0 ? 1 : -1) * stepsize; + Geom::CubicBezier current_curve; + const double residual = _offset_cubic_stable_sub( + bez, current_curve, + start_normal, end_normal, + start_new, end_new, + start_rad, end_rad, + start_len, end_len, + width, width_correction); + if (std::abs(residual) < std::abs(best_residual)) { + best_residual = residual; + best_width_correction = width_correction; + c = current_curve; + success = true; + if (std::abs(best_residual) < tol/4) { + break; + } + } + + if (success) { + if (!seen_success) { + seen_success = true; + //std::cout << "Stepsize factor: " << std::abs(width) / stepsize << std::endl; + stepsize_threshold = stepsize / 1000; + } + } + else { + stepsize /= 2; + } + if (std::abs(best_width_correction) >= std::abs(width)/2) { + //break; // Seems to prevent some numerical instabilities, not clear if useful + } + } // reached maximum recursive depth // don't bother with any more correction if (levels == 0) { - p.append(c); + try { + p.append(c); + } + catch (...) { + if ((p.finalPoint() - c.initialPoint()).length() < 1e-6) { + c.setInitial(p.finalPoint()); + } + else { + auto line = Geom::LineSegment(p.finalPoint(), c.initialPoint()); + p.append(line); + } + p.append(c); + } + return; } - // check the tolerance for our estimate to be a parallel curve - Geom::Point chk = c.pointAt(.5); - Geom::Point req = bez.pointAt(.5) + Geom::rot90(bez.unitTangentAt(.5))*width; // required accuracy - - Geom::Point const diff = req - chk; - double const err = Geom::dot(diff, diff); + // We find the point on our new curve (c) for which the distance between + // (c) and (bez) differs the most from the desired distance (width). + double worst_err = std::abs(best_residual); + double worst_time = .5; + for (size_t ii = 1; ii <= 9; ++ii) { + const double t = static_cast(ii) / 10; + const Geom::Point req = bez.pointAt(t); + // We use the exact solution with nearestTime because it is numerically + // much more stable than simply assuming that the point on (c) closest + // to bez.pointAt(t) is given by c.pointAt(t) + const Geom::Point chk = c.pointAt(c.nearestTime(req)); + + Geom::Point const diff = req - chk; + const double err = std::abs(diff.length() - std::abs(width)); + if (err > worst_err) { + worst_err = err; + worst_time = t; + } + } - if (err < tol) { + if (worst_err < tol) { if (Geom::are_near(start_new, p.finalPoint())) { p.setFinal(start_new); // if it isn't near, we throw } @@ -809,7 +927,7 @@ void offset_cubic(Geom::Path& p, Geom::CubicBezier const& bez, double width, dou return; } else { // split the curve in two - std::pair s = bez.subdivide(.5); + std::pair s = bez.subdivide(worst_time); offset_cubic(p, s.first, width, tol, levels - 1); offset_cubic(p, s.second, width, tol, levels - 1); } @@ -829,7 +947,7 @@ void offset_quadratic(Geom::Path& p, Geom::QuadraticBezier const& bez, double wi void offset_curve(Geom::Path& res, Geom::Curve const* current, double width) { - double const tolerance = 0.0025; + double const tolerance = 1.0 * (width / 100); // Tolerance is 1% of the given width. size_t levels = 8; if (current->isDegenerate()) return; // don't do anything -- cgit v1.2.3 From d06cd50952b47cd70c2ae73301c5e95c64d341f0 Mon Sep 17 00:00:00 2001 From: Alexander Brock Date: Mon, 28 Nov 2016 00:25:52 +0100 Subject: Increase tolerance to match old methods precision and improve speed (bzr r15280.1.2) --- src/helper/geom-pathstroke.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 905984a2a..51d3ee160 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -792,7 +792,7 @@ double _offset_cubic_stable_sub( // check the tolerance for our estimate to be a parallel curve double worst_residual = 0; - for (size_t ii = 1; ii <= 9; ++ii) { + for (size_t ii = 3; ii <= 7; ii+=2) { const double t = static_cast(ii) / 10; const Geom::Point req = bez.pointAt(t); const Geom::Point chk = c.pointAt(c.nearestTime(req)); @@ -947,7 +947,7 @@ void offset_quadratic(Geom::Path& p, Geom::QuadraticBezier const& bez, double wi void offset_curve(Geom::Path& res, Geom::Curve const* current, double width) { - double const tolerance = 1.0 * (width / 100); // Tolerance is 1% of the given width. + double const tolerance = 5.0 * (width / 100); // Tolerance is 5% of the given width. size_t levels = 8; if (current->isDegenerate()) return; // don't do anything -- cgit v1.2.3 From 755acba7f5543e62acd9b2fd38f8660abf972f19 Mon Sep 17 00:00:00 2001 From: Alexander Brock Date: Mon, 28 Nov 2016 00:35:43 +0100 Subject: Make tolerance of offset_curve a parameter (bzr r15280.1.3) --- src/helper/geom-pathstroke.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 51d3ee160..3a865fd48 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -945,9 +945,8 @@ void offset_quadratic(Geom::Path& p, Geom::QuadraticBezier const& bez, double wi offset_cubic(p, cub, width, tol, levels); } -void offset_curve(Geom::Path& res, Geom::Curve const* current, double width) +void offset_curve(Geom::Path& res, Geom::Curve const* current, double width, double tolerance) { - double const tolerance = 5.0 * (width / 100); // Tolerance is 5% of the given width. size_t levels = 8; if (current->isDegenerate()) return; // don't do anything @@ -973,14 +972,14 @@ void offset_curve(Geom::Path& res, Geom::Curve const* current, double width) default: { Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(current->toSBasis(), tolerance); for (size_t i = 0; i < sbasis_path.size(); ++i) - offset_curve(res, &sbasis_path[i], width); + offset_curve(res, &sbasis_path[i], width, tolerance); break; } } } else { Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(current->toSBasis(), 0.1); for (size_t i = 0; i < sbasis_path.size(); ++i) - offset_curve(res, &sbasis_path[i], width); + offset_curve(res, &sbasis_path[i], width, tolerance); } } @@ -1067,6 +1066,7 @@ Geom::PathVector outline(Geom::Path const& input, double width, double miter, Li Geom::Path half_outline(Geom::Path const& input, double width, double miter, LineJoinType join) { + double const tolerance = 5.0 * (width/100); // Tolerance is 5% Geom::Path res; if (input.size() == 0) return res; @@ -1086,7 +1086,7 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin for (size_t u = 0; u < k; u += 2) { temp.clear(); - offset_curve(temp, &input[u], width); + offset_curve(temp, &input[u], width, tolerance); // on the first run through, there isn't a join if (u == 0) { @@ -1099,7 +1099,7 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin // odd number of paths if (u < k - 1) { temp.clear(); - offset_curve(temp, &input[u+1], width); + offset_curve(temp, &input[u+1], width, tolerance); tangents(tang, input[u], input[u+1]); outline_join(res, temp, tang[0], tang[1], width, miter, join); } -- cgit v1.2.3 From 69405b64831f4e92d2ac4778430c8c048d985f3f Mon Sep 17 00:00:00 2001 From: Alexander Brock Date: Tue, 29 Nov 2016 15:01:52 +0100 Subject: Fix instability caused by degenerate paths (patch by jabiertxof) (bzr r15280.1.4) --- src/helper/geom-pathstroke.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index 3a865fd48..a60441dde 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -1081,8 +1081,9 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin res.start(start); // Do two curves at a time for efficiency, since the join function needs to know the outgoing curve as well - const size_t k = (input.back_closed().isDegenerate() && input.closed()) - ?input.size_default()-1:input.size_default(); + const Geom::Curve &closingline = input.back_closed(); + const size_t k = (are_near(closingline.initialPoint(), closingline.finalPoint()) && input.closed() ) + ?input.size_open():input.size_default(); for (size_t u = 0; u < k; u += 2) { temp.clear(); @@ -1104,7 +1105,6 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin outline_join(res, temp, tang[0], tang[1], width, miter, join); } } - if (input.closed()) { Geom::Curve const &c1 = res.back(); Geom::Curve const &c2 = res.front(); @@ -1116,7 +1116,6 @@ Geom::Path half_outline(Geom::Path const& input, double width, double miter, Lin outline_join(temp, temp2, tang[0], tang[1], width, miter, join); res.erase(res.begin()); res.erase_last(); - // res.append(temp); res.close(); } @@ -1128,9 +1127,8 @@ void outline_join(Geom::Path &res, Geom::Path const& temp, Geom::Point in_tang, { if (res.size() == 0 || temp.size() == 0) return; - Geom::Curve const& outgoing = temp.front(); - if (Geom::are_near(res.finalPoint(), outgoing.initialPoint())) { + if (Geom::are_near(res.finalPoint(), outgoing.initialPoint(), 0.01)) { // if the points are /that/ close, just ignore this one res.setFinal(temp.initialPoint()); res.append(temp); -- cgit v1.2.3 From 30cc2099eec035d794735d1742eb21c3d2401dee Mon Sep 17 00:00:00 2001 From: Alexander Brock Date: Tue, 29 Nov 2016 17:17:14 +0100 Subject: Make tolerance a parameter on every level (bzr r15280.1.5) --- src/helper/geom-pathstroke.cpp | 28 +++++++++++++++++++++++----- src/helper/geom-pathstroke.h | 17 +++++++++++++++-- 2 files changed, 38 insertions(+), 7 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index a60441dde..b39bb7f91 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -1019,13 +1019,19 @@ void peak_cap(Geom::PathBuilder& res, Geom::Path const& with_dir, Geom::Path con namespace Inkscape { -Geom::PathVector outline(Geom::Path const& input, double width, double miter, LineJoinType join, LineCapType butt) +Geom::PathVector outline( + Geom::Path const& input, + double width, + double miter, + LineJoinType join, + LineCapType butt, + double tolerance) { if (input.size() == 0) return Geom::PathVector(); // nope, don't even try Geom::PathBuilder res; - Geom::Path with_dir = half_outline(input, width/2., miter, join); - Geom::Path against_dir = half_outline(input.reversed(), width/2., miter, join); + Geom::Path with_dir = half_outline(input, width/2., miter, join, tolerance); + Geom::Path against_dir = half_outline(input.reversed(), width/2., miter, join, tolerance); res.moveTo(with_dir[0].initialPoint()); res.append(with_dir); @@ -1064,9 +1070,21 @@ Geom::PathVector outline(Geom::Path const& input, double width, double miter, Li return res.peek(); } -Geom::Path half_outline(Geom::Path const& input, double width, double miter, LineJoinType join) +Geom::Path half_outline( + Geom::Path const& input, + double width, + double miter, + LineJoinType join, + double tolerance) { - double const tolerance = 5.0 * (width/100); // Tolerance is 5% + if (tolerance <= 0) { + if (width > 0) { + tolerance = 5.0 * (std::abs(width)/100); + } + else { + tolerance = 1e-4; + } + } Geom::Path res; if (input.size() == 0) return res; diff --git a/src/helper/geom-pathstroke.h b/src/helper/geom-pathstroke.h index 6a753a6fd..4e4b8b91e 100644 --- a/src/helper/geom-pathstroke.h +++ b/src/helper/geom-pathstroke.h @@ -42,12 +42,19 @@ enum LineCapType { * @param[in] miter Miter limit. Only used when @a join is one of JOIN_MITER, JOIN_MITER_CLIP, and JOIN_EXTRAPOLATE. * @param[in] join Line join type used during offset. Member of LineJoinType enum. * @param[in] cap Line cap type used during stroking. Member of LineCapType enum. + * @param[in] tolerance Tolerance, values smaller than 0 lead to automatic tolerance depending on width. * * @return Stroked path. * If the input path is closed, the resultant vector will contain two paths. * Otherwise, there should be only one in the output. */ -Geom::PathVector outline(Geom::Path const& input, double width, double miter, LineJoinType join = JOIN_BEVEL, LineCapType cap = BUTT_FLAT); +Geom::PathVector outline( + Geom::Path const& input, + double width, + double miter, + LineJoinType join = JOIN_BEVEL, + LineCapType cap = BUTT_FLAT, + double tolerance = -1); /** * Offset the input path by @a width. @@ -57,10 +64,16 @@ Geom::PathVector outline(Geom::Path const& input, double width, double miter, Li * @param[in] width Amount to offset. * @param[in] miter Miter limit. Only used when @a join is one of JOIN_MITER, JOIN_MITER_CLIP, and JOIN_EXTRAPOLATE. * @param[in] join Line join type used during offset. Member of LineJoinType enum. + * @param[in] tolerance Tolerance, values smaller than 0 lead to automatic tolerance depending on width. * * @return Offsetted output. */ -Geom::Path half_outline(Geom::Path const& input, double width, double miter, LineJoinType join = JOIN_BEVEL); +Geom::Path half_outline( + Geom::Path const& input, + double width, + double miter, + LineJoinType join = JOIN_BEVEL, + double tolerance = -1); /** * Builds a join on the provided path. -- cgit v1.2.3 From 8ac3baab9da722813ee06a1c53670de6f0669f38 Mon Sep 17 00:00:00 2001 From: Alexander Brock Date: Tue, 29 Nov 2016 17:20:13 +0100 Subject: Handle negative width correctly in tolerance calculation (bzr r15280.1.6) --- src/helper/geom-pathstroke.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathstroke.cpp b/src/helper/geom-pathstroke.cpp index b39bb7f91..50627fd0b 100644 --- a/src/helper/geom-pathstroke.cpp +++ b/src/helper/geom-pathstroke.cpp @@ -1078,7 +1078,7 @@ Geom::Path half_outline( double tolerance) { if (tolerance <= 0) { - if (width > 0) { + if (std::abs(width) > 0) { tolerance = 5.0 * (std::abs(width)/100); } else { -- cgit v1.2.3 From b6200950a88ac9b1bb7eee4fb7f86b01e323dbcc Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 5 Jan 2017 00:08:02 +0100 Subject: antialiasing options on export (bzr r15391) --- src/helper/png-write.cpp | 18 +++++++++--------- src/helper/png-write.h | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/helper') diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 2433e2777..e06c539d3 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -123,8 +123,8 @@ void PngTextList::add(gchar const* key, gchar const* text) static bool sp_png_write_rgba_striped(SPDocument *doc, gchar const *filename, unsigned long int width, unsigned long int height, double xdpi, double ydpi, - int (* get_rows)(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth), - void *data, bool interlace, int color_type, int bit_depth, int zlib) + int (* get_rows)(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth, int antialias), + void *data, bool interlace, int color_type, int bit_depth, int zlib, int antialiasing) { g_return_val_if_fail(filename != NULL, false); g_return_val_if_fail(data != NULL, false); @@ -286,7 +286,7 @@ sp_png_write_rgba_striped(SPDocument *doc, r = 0; while (r < static_cast(height)) { void *to_free; - int n = get_rows((unsigned char const **) row_pointers, &to_free, r, height-r, data, color_type, bit_depth); + int n = get_rows((unsigned char const **) row_pointers, &to_free, r, height-r, data, color_type, bit_depth, antialiasing); if (!n) break; png_write_rows(png_ptr, row_pointers, n); g_free(to_free); @@ -320,7 +320,7 @@ sp_png_write_rgba_striped(SPDocument *doc, * */ static int -sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth) +sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, void *data, int color_type, int bit_depth, int antialiasing) { struct SPEBP *ebp = (struct SPEBP *) data; @@ -352,7 +352,7 @@ sp_export_get_rows(guchar const **rows, void **to_free, int row, int num_rows, v dc.setOperator(CAIRO_OPERATOR_OVER); /* Render */ - ebp->drawing->render(dc, bbox); + ebp->drawing->render(dc, bbox, 0, antialiasing); cairo_surface_destroy(s); // PNG stores data as unpremultiplied big-endian RGBA, which means @@ -396,10 +396,10 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned int (*status) (float, void *), void *data, bool force_overwrite, - const std::vector &items_only, bool interlace, int color_type, int bit_depth, int zlib) + const std::vector &items_only, bool interlace, int color_type, int bit_depth, int zlib, int antialiasing) { return sp_export_png_file(doc, filename, Geom::Rect(Geom::Point(x0,y0),Geom::Point(x1,y1)), - width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only, interlace, color_type, bit_depth, zlib); + width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only, interlace, color_type, bit_depth, zlib, antialiasing); } ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, @@ -408,7 +408,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long bgcolor, unsigned (*status)(float, void *), void *data, bool force_overwrite, - const std::vector &items_only, bool interlace, int color_type, int bit_depth, int zlib) + const std::vector &items_only, bool interlace, int color_type, int bit_depth, int zlib, int antialiasing) { g_return_val_if_fail(doc != NULL, EXPORT_ERROR); g_return_val_if_fail(filename != NULL, EXPORT_ERROR); @@ -479,7 +479,7 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, ebp.px = g_try_new(guchar, 4 * ebp.sheight * width); if (ebp.px) { - write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp, interlace, color_type, bit_depth, zlib); + write_status = sp_png_write_rgba_striped(doc, filename, width, height, xdpi, ydpi, sp_export_get_rows, &ebp, interlace, color_type, bit_depth, zlib, antialiasing); g_free(ebp.px); } diff --git a/src/helper/png-write.h b/src/helper/png-write.h index e47f01743..06498f46e 100644 --- a/src/helper/png-write.h +++ b/src/helper/png-write.h @@ -35,13 +35,13 @@ ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, unsigned long int width, unsigned long int height, double xdpi, double ydpi, unsigned long bgcolor, unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector &items_only = std::vector(), - bool interlace = false, int color_type = 6, int bit_depth = 8, int zlib = 6); + bool interlace = false, int color_type = 6, int bit_depth = 8, int zlib = 6, int antialiasing = 2); ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, Geom::Rect const &area, unsigned long int width, unsigned long int height, double xdpi, double ydpi, unsigned long bgcolor, unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, const std::vector &items_only = std::vector(), - bool interlace = false, int color_type = 6, int bit_depth = 8, int zlib = 6); + bool interlace = false, int color_type = 6, int bit_depth = 8, int zlib = 6, int antialiasing = 2); #endif // SEEN_SP_PNG_WRITE_H -- cgit v1.2.3 From 7bedd224ace433cf4c1a829ba38f6a3c388227e6 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 5 Jan 2017 20:03:50 +0100 Subject: Adding base (bzr r15392.1.1) --- src/helper/geom.cpp | 7 +++++++ src/helper/geom.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/helper') diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp index 42c494c00..e1f05c3ce 100644 --- a/src/helper/geom.cpp +++ b/src/helper/geom.cpp @@ -843,6 +843,13 @@ recursive_bezier4(const double x1, const double y1, recursive_bezier4(x1234, y1234, x234, y234, x34, y34, x4, y4, m_points, level + 1); } +void +swap(Geom::Point &A, Geom::Point &B){ + Geom::Point tmp = A; + A = B; + B = tmp; +} + /* Local Variables: mode:c++ diff --git a/src/helper/geom.h b/src/helper/geom.h index d49e2070c..b3d907e51 100644 --- a/src/helper/geom.h +++ b/src/helper/geom.h @@ -32,7 +32,7 @@ void recursive_bezier4(const double x1, const double y1, const double x2, const const double x3, const double y3, const double x4, const double y4, std::vector &pointlist, int level); - +void swap(Geom::Point &A, Geom::Point &B); #endif // INKSCAPE_HELPER_GEOM_H /* -- cgit v1.2.3 From d431044fc72f9b668dcfa5771f361f4d6088bdd7 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 22 Jan 2017 18:53:31 +0100 Subject: Update to new code in trunk (bzr r13645.1.166) --- src/helper/geom-pathvectorsatellites.cpp | 23 +++++++++++++++++++++++ src/helper/geom-pathvectorsatellites.h | 1 + 2 files changed, 24 insertions(+) (limited to 'src/helper') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index eca866978..79055af8d 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -15,6 +15,8 @@ */ #include +#include "util/units.h" + Geom::PathVector PathVectorSatellites::getPathVector() const { return _pathvector; @@ -141,6 +143,27 @@ void PathVectorSatellites::updateAmount(double radius, bool apply_no_radius, boo } } +void PathVectorSatellites::convertUnit(Glib::ustring in, Glib::ustring to, bool apply_no_radius, bool apply_with_radius) +{ + for (size_t i = 0; i < _satellites.size(); ++i) { + for (size_t j = 0; j < _satellites[i].size(); ++j) { + if (!_pathvector[i].closed() && j == 0) { + _satellites[i][j].amount = 0; + continue; + } + if (_pathvector[i].size() == j) { + continue; + } + if ((!apply_no_radius && _satellites[i][j].amount == 0) || + (!apply_with_radius && _satellites[i][j].amount != 0)) + { + continue; + } + _satellites[i][j].amount = Inkscape::Util::Quantity::convert(_satellites[i][j].amount, in.c_str(), to.c_str()); + } + } +} + void PathVectorSatellites::updateSatelliteType(SatelliteType satellitetype, bool apply_no_radius, bool apply_with_radius, bool only_selected) { diff --git a/src/helper/geom-pathvectorsatellites.h b/src/helper/geom-pathvectorsatellites.h index 4a020f553..d86e6cb25 100644 --- a/src/helper/geom-pathvectorsatellites.h +++ b/src/helper/geom-pathvectorsatellites.h @@ -34,6 +34,7 @@ public: void updateSteps(size_t steps, bool apply_no_radius, bool apply_with_radius, bool only_selected); void updateAmount(double radius, bool apply_no_radius, bool apply_with_radius, bool only_selected, bool use_knot_distance, bool flexible); + void convertUnit(Glib::ustring in, Glib::ustring to, bool apply_no_radius, bool apply_with_radius); void updateSatelliteType(SatelliteType satellitetype, bool apply_no_radius, bool apply_with_radius, bool only_selected); std::pair getIndexData(size_t index); void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); -- cgit v1.2.3 From 575d7a8f668987ea8395643a2c89a848ba527483 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 02:27:58 +0200 Subject: Updating code to trunk (bzr r13645.1.176) --- src/helper/Makefile_insert.THIS | 49 ----------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 src/helper/Makefile_insert.THIS (limited to 'src/helper') diff --git a/src/helper/Makefile_insert.THIS b/src/helper/Makefile_insert.THIS deleted file mode 100644 index 6ba0efbfa..000000000 --- a/src/helper/Makefile_insert.THIS +++ /dev/null @@ -1,49 +0,0 @@ -## Makefile.am fragment sourced by src/Makefile.am. - -helper/unit-menu.$(OBJEXT): helper/sp-marshal.h - -ink_common_sources += \ - helper/action.cpp \ - helper/action.h \ - helper/action-context.cpp \ - helper/action-context.h \ - helper/geom.cpp \ - helper/geom.h \ - helper/geom-curves.h \ - helper/geom-nodetype.cpp \ - helper/geom-nodetype.h \ - helper/geom-pathstroke.cpp \ - helper/geom-pathstroke.h \ - helper/geom-pathvectorsatellites.cpp \ - helper/geom-pathvectorsatellites.h \ - helper/geom-satellite.cpp \ - helper/geom-satellite.h \ - helper/gnome-utils.cpp \ - helper/gnome-utils.h \ - helper/mathfns.h \ - helper/png-write.cpp \ - helper/png-write.h \ - helper/sp-marshal.cpp \ - helper/sp-marshal.h \ - helper/window.cpp \ - helper/window.h \ - helper/stock-items.cpp \ - helper/stock-items.h - -# cmp exits with status 0 when there are no differences. "if" executes the commands -# after "then" when the exit status of the if command is 0 (this is crazy). -helper/sp-marshal.h: helper/sp-marshal.list - glib-genmarshal --prefix=sp_marshal --header $(srcdir)/helper/sp-marshal.list > helper/tmp.sp-marshal.h - if cmp -s helper/sp-marshal.h helper/tmp.sp-marshal.h; \ - then rm helper/tmp.sp-marshal.h; \ - else mv helper/tmp.sp-marshal.h helper/sp-marshal.h; fi - -helper/sp-marshal.cpp: helper/sp-marshal.list helper/sp-marshal.h - ( echo '#include "helper/sp-marshal.h"' && \ - glib-genmarshal --prefix=sp_marshal --body $(srcdir)/helper/sp-marshal.list ) \ - > helper/tmp.sp-marshal.cpp; \ - if cmp -s helper/sp-marshal.cpp helper/tmp.sp-marshal.cpp; \ - then rm helper/tmp.sp-marshal.cpp; \ - else mv helper/tmp.sp-marshal.cpp helper/sp-marshal.cpp; fi - -helper/sp-marshal.cpp helper/sp-marshal.h: helper/sp-marshal.list -- cgit v1.2.3 From 5004996c798cdbad5ff7abbaf2e7272411631cee Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 19:45:16 +0200 Subject: Pre merge fixing (bzr r13645.1.177) --- src/helper/geom-pathvectorsatellites.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index dd231d78f..e995c0a9b 100644 --- a/src/helper/geom-pathvectorsatellites.cpp +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -67,9 +67,7 @@ void PathVectorSatellites::setSelected(std::vector selected) size_t counter = 0; for (size_t i = 0; i < _satellites.size(); ++i) { for (size_t j = 0; j < _satellites[i].size(); ++j) { - std::cout << j; if (find (selected.begin(), selected.end(), counter) != selected.end()) { - _satellites[i][j].setSelected(true); } else { _satellites[i][j].setSelected(false); @@ -134,6 +132,9 @@ void PathVectorSatellites::updateAmount(double radius, bool apply_no_radius, boo if (!use_knot_distance && !flexible) { if (previous_index) { _satellites[i][j].amount = _satellites[i][j].radToLen(power, _pathvector[i][*previous_index], _pathvector[i][j]); + if (power && !_satellites[i][j].amount) { + g_warning("Seems a too high radius value"); + } } else { _satellites[i][j].amount = 0.0; } -- cgit v1.2.3 From 5b4c7fc7fbd532673473fd47b781bfc740cc5a07 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 23:00:45 +0200 Subject: Add improvement pointed in IRC by Ede_123 to allow defaultables parametes on fillet chamfer (bzr r15668) --- src/helper/geom-satellite.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/helper') diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h index a4d63d66e..b8ca2a490 100644 --- a/src/helper/geom-satellite.h +++ b/src/helper/geom-satellite.h @@ -51,15 +51,15 @@ public: { hidden = set_hidden; } - void setAmount(bool set_amount) + void setAmount(double set_amount) { amount = set_amount; } - void setAngle(bool set_angle) + void setAngle(double set_angle) { angle = set_angle; } - void setSteps(bool set_steps) + void setSteps(size_t set_steps) { steps = set_steps; } -- cgit v1.2.3 From 6e0b1cc358cadb3bfefceb39acf613ac7450b978 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 7 May 2017 22:50:07 +0200 Subject: Move gettext initialization into separate function so it can be re-used (will come in handy in inkview) (bzr r15675.1.2) --- src/helper/CMakeLists.txt | 6 ++-- src/helper/gettext.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++ src/helper/gettext.h | 44 +++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 src/helper/gettext.cpp create mode 100644 src/helper/gettext.h (limited to 'src/helper') diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt index 92709e4e9..443648c5c 100644 --- a/src/helper/CMakeLists.txt +++ b/src/helper/CMakeLists.txt @@ -10,12 +10,13 @@ set(sp_marshal_SRC set(helper_SRC action.cpp - action-context.cpp + action-context.cpp geom.cpp geom-nodetype.cpp geom-pathstroke.cpp geom-pathvectorsatellites.cpp geom-satellite.cpp + gettext.cpp gnome-utils.cpp pixbuf-ops.cpp png-write.cpp @@ -30,13 +31,14 @@ set(helper_SRC # ------- # Headers action.h - action-context.h + action-context.h geom-curves.h geom-nodetype.h geom-pathstroke.h geom-pathvectorsatellites.h geom-satellite.h geom.h + gettext.h gnome-utils.h mathfns.h pixbuf-ops.h diff --git a/src/helper/gettext.cpp b/src/helper/gettext.cpp new file mode 100644 index 000000000..4fa8df7ae --- /dev/null +++ b/src/helper/gettext.cpp @@ -0,0 +1,83 @@ +/** + * \file + * \brief helper functions for gettext + *//* + * Authors: + * Eduard Braun + * + * Copyright 2017 Authors + * + * This file is part of Inkscape. + * + * Inkscape is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Inkscape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Inkscape. If not, see . + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +namespace Inkscape { + +void initialize_gettext() { +#ifdef WIN32 + gchar *datadir = g_win32_get_package_installation_directory_of_module(NULL); + + // obtain short path to executable dir and pass it + // to bindtextdomain (it doesn't understand UTF-8) + gchar *shortdatadir = g_win32_locale_filename_from_utf8(datadir); + gchar *localepath = g_build_filename(shortdatadir, PACKAGE_LOCALE_DIR, NULL); + bindtextdomain(GETTEXT_PACKAGE, localepath); + g_free(shortdatadir); + g_free(localepath); + + g_free(datadir); + +#else +# ifdef ENABLE_BINRELOC + bindtextdomain(GETTEXT_PACKAGE, BR_LOCALEDIR("")); +# else + bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); + // needed by Python/Gettext + g_setenv("PACKAGE_LOCALE_DIR", PACKAGE_LOCALE_DIR, TRUE); +# endif +#endif + + // Allow the user to override the locale directory by setting + // the environment variable INKSCAPE_LOCALEDIR. + char const *inkscape_localedir = g_getenv("INKSCAPE_LOCALEDIR"); + if (inkscape_localedir != NULL) { + bindtextdomain(GETTEXT_PACKAGE, inkscape_localedir); + } + + // common setup + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); +} + +} + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace .0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim:filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99: \ No newline at end of file diff --git a/src/helper/gettext.h b/src/helper/gettext.h new file mode 100644 index 000000000..2a072b9e0 --- /dev/null +++ b/src/helper/gettext.h @@ -0,0 +1,44 @@ +/** + * \file + * \brief helper functions for gettext + *//* + * Authors: + * Eduard Braun + * + * Copyright 2017 Authors + * + * This file is part of Inkscape. + * + * Inkscape is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Inkscape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Inkscape. If not, see . + */ + +#ifndef SEEN_GETTEXT_HELPER_H +#define SEEN_GETTEXT_HELPER_H + +namespace Inkscape { + void initialize_gettext(); +} + +#endif // SEEN_GETTEXT_HELPER_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace .0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim:filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99: \ No newline at end of file -- cgit v1.2.3 From c91214d837562c6244053dfeaf99aa2d8b8deded Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Mon, 8 May 2017 00:11:49 +0200 Subject: Move functions for switching gettext charset to helper/gettext.h (bzr r15675.1.3) --- src/helper/gettext.cpp | 30 ++++++++++++++++++++++++++++-- src/helper/gettext.h | 2 ++ 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src/helper') diff --git a/src/helper/gettext.cpp b/src/helper/gettext.cpp index 4fa8df7ae..0972d4e19 100644 --- a/src/helper/gettext.cpp +++ b/src/helper/gettext.cpp @@ -27,11 +27,17 @@ # include "config.h" #endif -#include -#include +#ifdef WIN32 +#include +#endif + +#include +#include +#include namespace Inkscape { +/** does all required gettext initialization and takes care of the respective locale directory paths */ void initialize_gettext() { #ifdef WIN32 gchar *datadir = g_win32_get_package_installation_directory_of_module(NULL); @@ -67,6 +73,26 @@ void initialize_gettext() { bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); } + +/** set gettext codeset to UTF8 */ +void bind_textdomain_codeset_utf8() { + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); +} + +/** set gettext codeset to codeset of the console + * - on *nix this is typically the current locale, + * - on Windows it has to be determined using GetConsoleOutputCP() */ +void bind_textdomain_codeset_console() { + std::string charset; + Glib::get_charset(charset); + + // TODO: does not work properly as we spawn a child process on Windows + // (inkscape.exe is not a console application and can never print directly to console) + //unsigned int test = GetConsoleOutputCP(); + //g_message("CP%u", test); + + bind_textdomain_codeset(GETTEXT_PACKAGE, charset.c_str()); +} } diff --git a/src/helper/gettext.h b/src/helper/gettext.h index 2a072b9e0..689bddbbb 100644 --- a/src/helper/gettext.h +++ b/src/helper/gettext.h @@ -28,6 +28,8 @@ namespace Inkscape { void initialize_gettext(); + void bind_textdomain_codeset_utf8(); + void bind_textdomain_codeset_console(); } #endif // SEEN_GETTEXT_HELPER_H -- cgit v1.2.3 From e1097ab39decf853abbb6a934c47afa841445237 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Wed, 10 May 2017 02:21:03 +0200 Subject: Use UTF8 encoding for output on windows console. This avoids the misery and frustration of converting to the overly limited ANSI codepages and does not seem to cause any issues so far. (bzr r15682) --- src/helper/gettext.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/helper') diff --git a/src/helper/gettext.cpp b/src/helper/gettext.cpp index 0972d4e19..91dfdbcb8 100644 --- a/src/helper/gettext.cpp +++ b/src/helper/gettext.cpp @@ -49,9 +49,8 @@ void initialize_gettext() { bindtextdomain(GETTEXT_PACKAGE, localepath); g_free(shortdatadir); g_free(localepath); - - g_free(datadir); + g_free(datadir); #else # ifdef ENABLE_BINRELOC bindtextdomain(GETTEXT_PACKAGE, BR_LOCALEDIR("")); @@ -79,21 +78,23 @@ void bind_textdomain_codeset_utf8() { bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); } -/** set gettext codeset to codeset of the console +/** set gettext codeset to codeset of the system console * - on *nix this is typically the current locale, - * - on Windows it has to be determined using GetConsoleOutputCP() */ + * - on Windows we don't care and simply use UTF8 + * any conversion would need to happen in our console wrappers (see winconsole.cpp) anyway + * as we have no easy way of determining console encoding from inkscape/inkview.exe process; + * for now do something even easier - switch console encoding to UTF8 and be done with it! + * this also works nicely on MSYS consoles where UTF8 encoding is used by default, too */ void bind_textdomain_codeset_console() { +#ifdef WIN32 + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); +#else std::string charset; Glib::get_charset(charset); - - // TODO: does not work properly as we spawn a child process on Windows - // (inkscape.exe is not a console application and can never print directly to console) - //unsigned int test = GetConsoleOutputCP(); - //g_message("CP%u", test); - bind_textdomain_codeset(GETTEXT_PACKAGE, charset.c_str()); +#endif } - + } -- cgit v1.2.3