diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-04-01 15:54:35 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-04-01 15:54:35 +0000 |
| commit | f3965759e52107c1cdcd8b7e248e5538fdaa11b6 (patch) | |
| tree | efa7e5eb155b812903d14e76244e462dd84f47d8 /src/helper | |
| parent | add documentation (diff) | |
| download | inkscape-f3965759e52107c1cdcd8b7e248e5538fdaa11b6.tar.gz inkscape-f3965759e52107c1cdcd8b7e248e5538fdaa11b6.zip | |
Added documentation and fix to coding style.
(bzr r13645.1.66)
Diffstat (limited to 'src/helper')
| -rw-r--r-- | src/helper/geom-pathinfo.cpp | 119 | ||||
| -rw-r--r-- | src/helper/geom-pathinfo.h | 52 | ||||
| -rw-r--r-- | src/helper/geom-pointwise.cpp | 185 | ||||
| -rw-r--r-- | src/helper/geom-pointwise.h | 55 | ||||
| -rw-r--r-- | src/helper/geom-satellite-enum.h | 22 | ||||
| -rw-r--r-- | src/helper/geom-satellite.cpp | 153 | ||||
| -rw-r--r-- | src/helper/geom-satellite.h | 47 |
7 files changed, 326 insertions, 307 deletions
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<jabier.arraiza@marker.es> - * - * This code is in public domain - */ + */ /* + * 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> @@ -17,131 +17,120 @@ namespace Geom { * @brief Pathinfo store the data of a pathvector and allow get info about it * */ -Pathinfo::Pathinfo(Piecewise<D2<SBasis> > pwd2) - : _pwd2(pwd2) +Pathinfo::Pathinfo(Piecewise<D2<SBasis> > pwd2) : _pwd2(pwd2) { - setPathInfo(); -}; + _setPathInfo(); +} +; -Pathinfo::~Pathinfo(){}; +Pathinfo::~Pathinfo() {} +; -void -Pathinfo::setPwd2(Piecewise<D2<SBasis> > pwd2_in) +void Pathinfo::setPwd2(Piecewise<D2<SBasis> > pwd2_in) { _pwd2 = pwd2_in; - setPathInfo(); + _setPathInfo(); } /** Store the base path data */ -void -Pathinfo::setPathInfo() +void Pathinfo::_setPathInfo() { - _pathInfo.clear(); - std::vector<Geom::Path> path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + data.clear(); + std::vector<Geom::Path> 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<size_t> -Pathinfo::getPrevious(size_t index) const +boost::optional<size_t> 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<size_t> -Pathinfo::getNext(size_t index) const +boost::optional<size_t> 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<std::pair<size_t, bool> > -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<jabier.arraiza@marker.es> - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es> + * + * 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<D2<SBasis> > pwd2); - virtual ~Pathinfo(); - void setPwd2(Piecewise<D2<SBasis> > 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<size_t> getPrevious(size_t index) const; - boost::optional<size_t> getNext(size_t index) const; - bool getIsClosed(size_t index) const; - std::vector<std::pair<size_t, bool> > getPathInfo() const; - - private: - void setPathInfo(); - Piecewise<D2<SBasis> > _pwd2; - std::vector<std::pair<size_t, bool> > _pathInfo; +class Pathinfo { +public: + Pathinfo(Piecewise<D2<SBasis> > pwd2); + virtual ~Pathinfo(); + void setPwd2(Piecewise<D2<SBasis> > 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<size_t> previous(size_t index) const; + boost::optional<size_t> next(size_t index) const; + bool isClosed(size_t index) const; + std::vector<std::pair<size_t, bool> > pathInfo() const; + std::vector<std::pair<size_t, bool> > data; + +private: + void _setPathInfo(); + Piecewise<D2<SBasis> > _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<jabier.arraiza@marker.es> - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es> + * + * This code is in public domain + */ #include <helper/geom-pointwise.h> - 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<D2<SBasis> > pwd2, std::vector<Satellite> satellites) - : _pwd2(pwd2), _satellites(satellites), _pathInfo(pwd2) +Pointwise::Pointwise(Piecewise<D2<SBasis> > pwd2, + std::vector<Satellite> satellites) + : _pwd2(pwd2), _satellites(satellites), _path_info(pwd2) { setStart(); -}; +} +; -Pointwise::~Pointwise(){}; +Pointwise::~Pointwise() {} +; -Piecewise<D2<SBasis> > -Pointwise::getPwd2() const +Piecewise<D2<SBasis> > Pointwise::getPwd2() const { return _pwd2; } -void -Pointwise::setPwd2(Piecewise<D2<SBasis> > pwd2_in) +void Pointwise::setPwd2(Piecewise<D2<SBasis> > pwd2_in) { _pwd2 = pwd2_in; - _pathInfo.setPwd2(_pwd2); + _path_info.setPwd2(_pwd2); } -std::vector<Satellite> -Pointwise::getSatellites() const +std::vector<Satellite> Pointwise::getSatellites() const { return _satellites; } -void -Pointwise::setSatellites(std::vector<Satellite> sats) +void Pointwise::setSatellites(std::vector<Satellite> sats) { _satellites = sats; setStart(); @@ -62,14 +60,13 @@ Pointwise::setSatellites(std::vector<Satellite> sats) /** Update the start satellite on ope/closed paths. */ -void -Pointwise::setStart() +void Pointwise::setStart() { - std::vector<std::pair<size_t, bool> > 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<std::pair<size_t, bool> > 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<D2<SBasis> > A) +void Pointwise::recalculateForNewPwd2(Piecewise<D2<SBasis> > 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<D2<SBasis> > A) +void Pointwise::pwd2Sustract(Piecewise<D2<SBasis> > A) { size_t counter = 0; std::vector<Satellite> sats; Piecewise<D2<SBasis> > 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<D2<SBasis> > A) /** Append nodes/subpaths to current pointwise */ -void -Pointwise::pwd2_append(Piecewise<D2<SBasis> > A) +void Pointwise::pwd2Append(Piecewise<D2<SBasis> > A) { size_t counter = 0; std::vector<Satellite> 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<Geom::Path> 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<Geom::Path> path_in = + path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001); + size_t subpath_counter = 0; size_t counter = 0; std::vector<Geom::Path> 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<Geom::Path> path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + std::vector<Geom::Path> 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<Geom::Path> 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<jabier.arraiza@marker.es> - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es> + * + * 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<D2<SBasis> > pwd2, std::vector<Satellite> satellites); - virtual ~Pointwise(); +class Pointwise { +public: + Pointwise(Piecewise<D2<SBasis> > pwd2, std::vector<Satellite> satellites); + virtual ~Pointwise(); - Piecewise<D2<SBasis> > getPwd2() const; - void setPwd2(Piecewise<D2<SBasis> > pwd2_in); + Piecewise<D2<SBasis> > getPwd2() const; + void setPwd2(Piecewise<D2<SBasis> > pwd2_in); - std::vector<Satellite> getSatellites() const; - void setSatellites(std::vector<Satellite> sats); + std::vector<Satellite> getSatellites() const; + void setSatellites(std::vector<Satellite> sats); - void setStart(); + void setStart(); - void recalculate_for_new_pwd2(Piecewise<D2<SBasis> > A); - void pwd2_sustract(Piecewise<D2<SBasis> > A); - void pwd2_append(Piecewise<D2<SBasis> > A); - void subpath_to_back(size_t subpath); - void subpath_reverse(size_t start,size_t end); + void recalculateForNewPwd2(Piecewise<D2<SBasis> > A); + void pwd2Sustract(Piecewise<D2<SBasis> > A); + void pwd2Append(Piecewise<D2<SBasis> > A); + void subpathToBack(size_t subpath); + void subpathReverse(size_t start, size_t end); - private: - Piecewise<D2<SBasis> > _pwd2; - std::vector<Satellite> _satellites; - Pathinfo _pathInfo; +private: + Piecewise<D2<SBasis> > _pwd2; + std::vector<Satellite> _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<jabier.arraiza@marker.es> - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es> + * + * 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<jabier.arraiza@marker.es> - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es> + * + * This code is in public domain + */ #include <helper/geom-satellite.h> #include <2geom/curve.h> @@ -17,26 +17,31 @@ #include <2geom/ray.h> #include <boost/optional.hpp> - 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<Geom::SBasis> d2_in) const +double Satellite::toTime(double A, Geom::D2<Geom::SBasis> 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<Geom::SBasis> d2_in) const /** * Calculate the size in d2_in with a point at A */ -double -Satellite::toSize(double A,Geom::D2<Geom::SBasis> d2_in) const +double Satellite::toSize(double A, Geom::D2<Geom::SBasis> 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<Geom::SBasis> d2_in) const /** * Calculate the lenght of a satellite from a radious A input. */ -double -Satellite::rad_to_len(double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in, Geom::D2<Geom::SBasis> d2_out, boost::optional<Geom::Satellite> previousSatellite) const +double Satellite::radToLen( + double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in, + Geom::D2<Geom::SBasis> d2_out, + boost::optional<Geom::Satellite> previousSatellite) const { double len = 0; - if(d2_in && previousSatellite){ - Piecewise<D2<SBasis> > offset_curve0 = Piecewise<D2<SBasis> >(*d2_in)+rot90(unitVector(derivative(*d2_in)))*(A); - Piecewise<D2<SBasis> > offset_curve1 = Piecewise<D2<SBasis> >(d2_out)+rot90(unitVector(derivative(d2_out)))*(A); + if (d2_in && previousSatellite) { + Piecewise<D2<SBasis> > offset_curve0 = + Piecewise<D2<SBasis> >(*d2_in) + + rot90(unitVector(derivative(*d2_in))) * (A); + Piecewise<D2<SBasis> > offset_curve1 = + Piecewise<D2<SBasis> >(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<Geom::D2<Geom::SBasis> > d2_in, Geom::D2<Geom::SBasis> d2_out, boost::optional<Geom::Satellite> previousSatellite) const +/** +* Calculate the radious of a satellite from a lenght A input. +*/ +double Satellite::lenToRad( + double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in, + Geom::D2<Geom::SBasis> d2_out, + boost::optional<Geom::Satellite> 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<D2<SBasis> > 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<D2<SBasis> > 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<Geom::CubicBezier const *>(&*knotCurve1); + Geom::CubicBezier const *cubic1 = + dynamic_cast<Geom::CubicBezier const *>(&*knotCurve1); Ray ray1(startArcPoint, (*d2_in).valueAt(1)); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } - Geom::CubicBezier const *cubic2 = dynamic_cast<Geom::CubicBezier const *>(&*knotCurve2); + Geom::CubicBezier const *cubic2 = + dynamic_cast<Geom::CubicBezier const *>(&*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<Geom::D2<Geom::SBasis> > d2_in, /** * Get the time position of the satellite in d2_in */ -double -Satellite::getTime(Geom::D2<Geom::SBasis> d2_in) const +double Satellite::time(Geom::D2<Geom::SBasis> 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<Geom::SBasis> 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<Geom::SBasis> d2_in) const +double Satellite::time(double A, bool I, + Geom::D2<Geom::SBasis> 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<Geom::SBasis> d2_in) const /** * Get the lenght of the satellite in d2_in */ -double -Satellite::getSize(Geom::D2<Geom::SBasis> d2_in) const +double Satellite::size(Geom::D2<Geom::SBasis> 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<Geom::SBasis> d2_in) const /** * Get the point position of the satellite */ -Geom::Point -Satellite::getPosition(Geom::D2<Geom::SBasis> d2_in) const +Geom::Point Satellite::getPosition(Geom::D2<Geom::SBasis> 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<Geom::SBasis> d2_in) +void Satellite::setPosition(Geom::Point p, Geom::D2<Geom::SBasis> 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<Geom::SBasis> d2_in) /** * Map a satellite type with gchar */ -void -Satellite::setSatelliteType(gchar const * A) +void Satellite::setSatelliteType(gchar const *A) { - std::map<std::string,SatelliteType> GcharMapToSatelliteType = boost::assign::map_list_of("F", F)("IF", IF)("C",C)("IC",IC)("KO",KO); + std::map<std::string, SatelliteType> 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<SatelliteType,gchar const *> SatelliteTypeToGcharMap = boost::assign::map_list_of(F, "F")(IF, "IF")(C,"C")(IC,"IC")(KO,"KO"); + std::map<SatelliteType, gchar const *> 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<jabier.arraiza@marker.es> - * - * This code is in public domain - */ + */ /* + * Authors: + * 2015 Jabier Arraiza Cenoz<jabier.arraiza@marker.es> + * + * 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<Geom::SBasis> d2_in) const; - double toTime(double A,Geom::D2<Geom::SBasis> d2_in) const; - double len_to_rad(double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in, Geom::D2<Geom::SBasis> d2_out, boost::optional<Geom::Satellite> previousSatellite) const; - double rad_to_len(double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in, Geom::D2<Geom::SBasis> d2_out, boost::optional<Geom::Satellite> previousSatellite) const; + double toSize(double A, Geom::D2<Geom::SBasis> d2_in) const; + double toTime(double A, Geom::D2<Geom::SBasis> d2_in) const; + double lenToRad(double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in, + Geom::D2<Geom::SBasis> d2_out, + boost::optional<Geom::Satellite> previousSatellite) const; + double radToLen(double A, boost::optional<Geom::D2<Geom::SBasis> > d2_in, + Geom::D2<Geom::SBasis> d2_out, + boost::optional<Geom::Satellite> previousSatellite) const; - double getTime(Geom::D2<Geom::SBasis> d2_in) const; - double getTime(double A, bool I, Geom::D2<Geom::SBasis> d2_in) const; - double getSize(Geom::D2<Geom::SBasis> d2_in) const; + double time(Geom::D2<Geom::SBasis> d2_in) const; + double time(double A, bool I, Geom::D2<Geom::SBasis> d2_in) const; + double size(Geom::D2<Geom::SBasis> d2_in) const; void setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in); Geom::Point getPosition(Geom::D2<Geom::SBasis> 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 +// : |
