diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/helper/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/helper/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/helper/geom-pathinfo.cpp | 176 | ||||
| -rw-r--r-- | src/helper/geom-pathinfo.h | 55 | ||||
| -rw-r--r-- | src/helper/geom-pointwise.cpp | 124 | ||||
| -rw-r--r-- | src/helper/geom-pointwise.h | 24 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.cpp | 57 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.h | 1 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.cpp | 2 | ||||
| -rw-r--r-- | src/live_effects/parameter/satellitearray.cpp | 81 | ||||
| -rw-r--r-- | src/live_effects/parameter/satellitearray.h | 1 |
11 files changed, 164 insertions, 363 deletions
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<jabier.arraiza@marker.es> - * - * This code is in public domain - */ - -#include <helper/geom-pathinfo.h> -#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<Geom::D2<Geom::SBasis> > 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<size_t> 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<size_t> 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<jabier.arraiza@marker.es> - * - * This code is in public domain - */ - -#ifndef SEEN_PATHINFO_H -#define SEEN_PATHINFO_H - -#include <2geom/path.h> -#include <boost/optional.hpp> - -/** - * @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<Geom::D2<Geom::SBasis> > pwd2); - void set(Geom::PathVector path_vector, bool skip_degenerate = false); - std::vector<std::pair<size_t, bool> > 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<size_t> previous(size_t index) const; - boost::optional<size_t> next(size_t index) const; - bool closed(size_t index) const; - -private: - std::vector<std::pair<size_t, bool> > _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<Geom::D2<Geom::SBasis> > Pointwise::getPwd2() const +pwd2sb Pointwise::getPwd2() const { return _pwd2; } -void Pointwise::setPwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > 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<Satellite> Pointwise::getSatellites() const @@ -56,7 +45,7 @@ std::vector<Satellite> Pointwise::getSatellites() const return _satellites; } -void Pointwise::setSatellites(std::vector<Satellite> const sats) +void Pointwise::setSatellites(std::vector<Satellite> const &sats) { _satellites = sats; } @@ -65,26 +54,39 @@ void Pointwise::setSatellites(std::vector<Satellite> const sats) */ void Pointwise::setStart() { - std::vector<std::pair<size_t, bool> > 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<Geom::D2<Geom::SBasis> > 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<Geom::D2<Geom::SBasis> > c /** Some nodes/subpaths are removed. */ -void Pointwise::pwd2Sustract(Geom::Piecewise<Geom::D2<Geom::SBasis> > const A) +void Pointwise::pwd2Subtract(pwd2sb const &A) { size_t counter = 0; std::vector<Satellite> sats; - Geom::Piecewise<Geom::D2<Geom::SBasis> > 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<Geom::D2<Geom::SBasis> > const A) /** Append nodes/subpaths to current pointwise */ -void Pointwise::pwd2Append(Geom::Piecewise<Geom::D2<Geom::SBasis> > const A, Satellite const S) +void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S) { size_t counter = 0; std::vector<Satellite> 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<Geom::D2<Geom::SBasis> > 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<Geom::D2<Geom::SBasis } } - _path_info.set(A); setPwd2(A); } diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h index d83b54b79..6a8ea8881 100644 --- a/src/helper/geom-pointwise.h +++ b/src/helper/geom-pointwise.h @@ -18,7 +18,6 @@ #define SEEN_POINTWISE_H #include <helper/geom-satellite.h> -#include <helper/geom-pathinfo.h> #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<Geom::D2<Geom::SBasis> > pwd2sb; class Pointwise { public: - Pointwise(); - virtual ~Pointwise(); - - Geom::Piecewise<Geom::D2<Geom::SBasis> > getPwd2() const; - void setPwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > const pwd2_in); + pwd2sb getPwd2() const; + void setPwd2(pwd2sb const &pwd2_in); std::vector<Satellite> getSatellites() const; - void setSatellites(std::vector<Satellite> const sats); - void setPathInfo(Geom::PathVector const pv); + void setSatellites(std::vector<Satellite> const &sats); void setStart(); - void recalculateForNewPwd2(Geom::Piecewise<Geom::D2<Geom::SBasis> > const A, Geom::PathVector const B, Satellite const S); - void pwd2Sustract(Geom::Piecewise<Geom::D2<Geom::SBasis> > const A); - void pwd2Append(Geom::Piecewise<Geom::D2<Geom::SBasis> > 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<Geom::D2<Geom::SBasis> > const A, Geom::PathVector const B, Satellite const S); + void insertDegenerateSatellites(pwd2sb const &A, Geom::PathVector const &B, Satellite const &S); private: - Geom::Piecewise<Geom::D2<Geom::SBasis> > _pwd2; + pwd2sb _pwd2; std::vector<Satellite> _satellites; - Pathinfo _path_info; }; #endif //SEEN_POINTWISE_H diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index eb9f82918..7871ccc1e 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -13,7 +13,6 @@ #include "display/curve.h" #include "helper/geom-curves.h" #include "helper/geom-satellite.h" -#include "helper/geom-pathinfo.h" #include <2geom/elliptical-arc.h> #include "knotholder.h" #include <boost/optional.hpp> @@ -81,8 +80,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) helper_size.param_set_digits(0); } -LPEFilletChamfer::~LPEFilletChamfer() {} - void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) { SPLPEItem *splpeitem = const_cast<SPLPEItem *>(lpeItem); @@ -101,20 +98,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } 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(); - // the closing line segment is always of type - // LineSegment. - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - // closingline.isDegenerate() did not work, because it only checks for - // *exact* zero length, which goes wrong for relative coordinates and - // rounding errors... - // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); - } - } - Geom::Path::const_iterator curve_end = curve_endit; - --curve_end; int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { @@ -142,7 +125,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) pointwise = new Pointwise(); pointwise->setPwd2(pwd2_in); pointwise->setSatellites(satellites); - pointwise->setPathInfo(original_pathv); pointwise->setStart(); satellites_param.setPointwise(pointwise); } else { @@ -281,14 +263,13 @@ void LPEFilletChamfer::updateAmount() } std::vector<Satellite> satellites = pointwise->getSatellites(); Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); for (std::vector<Satellite>::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if (!path_info->closed(it - satellites.begin()) && - path_info->first(it - satellites.begin()) == - (unsigned)(it - satellites.begin())) + Geom::Path sat_path = pathvector_before_effect.pathAt(it - satellites.begin()); + size_t sat_curve_time = Geom::nearest_time(pathvector_before_effect.curveAt(it - satellites.begin()).initialPoint() , pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (!sat_path.closed() && sat_curve_time == first) { it->amount = 0; continue; @@ -296,8 +277,13 @@ void LPEFilletChamfer::updateAmount() if (ignore_radius_0 && it->amount == 0) { continue; } - boost::optional<size_t> previous = - path_info->previous(it - satellites.begin()); + boost::optional<size_t> previous = boost::none; + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + previous = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + previous = sat_curve_time - 1; + } if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { @@ -425,13 +411,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) it->hidden = hide_knots; ++it; } - Pathinfo* path_info = new Pathinfo(); - path_info->set(original_pathv); - size_t number_curves = path_info->size(); + size_t number_curves = original_pathv.curveCount(); //if are diferent sizes call to poinwise recalculate - //TODO: fire a reverse satellites on reverse path. Maybe a new method + //todo: fire a reverse satellites on reverse path. Maybe a new method //like "are_similar" to avoid precission issues on reverse a pointwise - // and after convert to Pathvector + //and after convert to Pathvector if (pointwise && number_curves != sats.size()) { Satellite sat(sats[0].satellite_type); sat.setIsTime(sats[0].is_time); @@ -447,7 +431,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise->setPwd2(pwd2_in); pointwise->setSatellites(sats); } - pointwise->setPathInfo(original_pathv); pointwise->setStart(); satellites_param.setPointwise(pointwise); refreshKnots(); @@ -488,18 +471,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) path_out.push_back(tmp_path); continue; } - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); - // the closing line segment is always of type - // Geom::LineSegment. - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - // closingline.isDegenerate() did not work, because it only checks for - // *exact* zero length, which goes wrong for relative coordinates and - // rounding errors... - // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); - } - } size_t counter_curves = 0; size_t first = counter; double time0 = 0; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index d7549d070..804709342 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -30,7 +30,6 @@ enum FilletMethod { class LPEFilletChamfer : public Effect { public: LPEFilletChamfer(LivePathEffectObject *lpeobject); - virtual ~LPEFilletChamfer(); virtual void doBeforeEffect(SPLPEItem const *lpeItem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 9b326fe32..0abcd4b9b 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -20,7 +20,7 @@ sp_svg_satellite_read_d(gchar const *str, Satellite *sat){ return 0; } gchar ** strarray = g_strsplit(str, ",", 8); - if(strarray[7] && !strarray[8]){ + if(strlen(str) > 0 && strarray[7] && !strarray[8]){ sat->setSatelliteType(g_strstrip(strarray[0])); sat->is_time = strncmp(strarray[1],"1",1) == 0; sat->active = strncmp(strarray[2],"1",1) == 0; diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 46c7396d0..b7d403a91 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -37,8 +37,6 @@ SatelliteArrayParam::SatelliteArrayParam(const Glib::ustring &label, _last_pointwise = NULL; } -SatelliteArrayParam::~SatelliteArrayParam() {} - void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) @@ -76,8 +74,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) return; } Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = _last_pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (mirror == true) { _hp.clear(); } @@ -97,7 +94,17 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i].arcDistance(pwd2[i]); double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); double lenght_in = 0; - boost::optional<size_t> d2_prev_index = path_info->previous(i); + + Geom::Path sat_path = pointwise_pv.pathAt(i); + boost::optional<size_t> d2_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(i).initialPoint() , pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + d2_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + d2_prev_index = sat_curve_time - 1; + } if (d2_prev_index) { lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); } @@ -285,10 +292,18 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); - if (_pparam->_vector.size() <= _index) { - boost::optional<size_t> d2_prev_index = path_info->previous(index); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + if (_index >= _pparam->_vector.size() ) { + Geom::Path sat_path = pointwise_pv.pathAt(index); + boost::optional<size_t> d2_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + d2_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + d2_prev_index = sat_curve_time - 1; + } if (d2_prev_index) { Geom::D2<Geom::SBasis> d2_in = pwd2[*d2_prev_index]; double mirror_time = Geom::nearest_time(s, d2_in); @@ -334,15 +349,23 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (pwd2.size() <= index) { return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); if (_index >= _pparam->_vector.size()) { tmp_point = satellite.getPosition(pwd2[index]); - boost::optional<size_t> d2_prev_index = path_info->previous(index); + Geom::Path sat_path = pointwise_pv.pathAt(index); + boost::optional<size_t> d2_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + d2_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + d2_prev_index = sat_curve_time - 1; + } if (d2_prev_index) { Geom::D2<Geom::SBasis> d2_in = pwd2[*d2_prev_index]; double s = satellite.arcDistance(pwd2[index]); @@ -425,20 +448,28 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } else if (state & GDK_SHIFT_MASK) { Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = _pparam->_last_pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); double amount = _pparam->_vector.at(index).amount; + Geom::Path sat_path = pointwise_pv.pathAt(index); + boost::optional<size_t> d2_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + d2_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + d2_prev_index = sat_curve_time - 1; + } + if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { - boost::optional<size_t> prev = path_info->previous(index); - if (prev) { - amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*prev], pwd2[index],_pparam->_vector.at(*prev)); + if (d2_prev_index) { + amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*d2_prev_index], pwd2[index],_pparam->_vector.at(*d2_prev_index)); } else { amount = 0.0; } } bool aprox = false; Geom::D2<Geom::SBasis> d2_out = _pparam->_last_pointwise->getPwd2()[index]; - boost::optional<size_t> d2_prev_index = path_info->previous(index); if (d2_prev_index) { Geom::D2<Geom::SBasis> d2_in = _pparam->_last_pointwise->getPwd2()[*d2_prev_index]; @@ -468,9 +499,17 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = _pparam->_last_pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); - boost::optional<size_t> prev = path_info->previous(index); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::Path sat_path = pointwise_pv.pathAt(index); + boost::optional<size_t> prev = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + prev = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + prev = sat_curve_time - 1; + } if (prev) { amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index]); } else { diff --git a/src/live_effects/parameter/satellitearray.h b/src/live_effects/parameter/satellitearray.h index cc09e7589..bb8bf27c8 100644 --- a/src/live_effects/parameter/satellitearray.h +++ b/src/live_effects/parameter/satellitearray.h @@ -35,7 +35,6 @@ public: SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect); - virtual ~SatelliteArrayParam(); virtual Gtk::Widget *param_newWidget() { |
