diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2016-05-10 21:16:49 +0000 |
|---|---|---|
| committer | jabiertxof <info@marker.es> | 2016-05-10 21:16:49 +0000 |
| commit | 07717a370b8efe6ddbb0c69d115bb063a2e7686a (patch) | |
| tree | df507f7bc83681ce315137c5828ce6c8b24cdf76 /src/helper | |
| parent | update to trunk (diff) | |
| download | inkscape-07717a370b8efe6ddbb0c69d115bb063a2e7686a.tar.gz inkscape-07717a370b8efe6ddbb0c69d115bb063a2e7686a.zip | |
Working with path updates
(bzr r13645.1.130)
Diffstat (limited to 'src/helper')
| -rw-r--r-- | src/helper/geom-pointwise.cpp | 63 | ||||
| -rw-r--r-- | src/helper/geom-pointwise.h | 12 | ||||
| -rw-r--r-- | src/helper/geom-satellite.cpp | 22 |
3 files changed, 49 insertions, 48 deletions
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 <helper/geom-pointwise.h> - 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<satellite> 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<satellite> subpath_satellites; - for (size_t k = 0; k < new_pathv[i].size(); k++) { + std::vector<Satellite> 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<Satellite> 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<Geom::D2<Geom::SBasis> > PwD2SBasisasis; -typedef std::vector< Satelites > Satelites; +typedef Geom::Piecewise<Geom::D2<Geom::SBasis> > PwD2SBasis; +typedef std::vector<std::vector<Satellite> > 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<Geom::cubic_bezier const *>(&*knot_curve1); - Geom::Ray ray1(startArcPoint, curve_in.pointAt(1)); + Geom::CubicBezier const *cubic1 = dynamic_cast<Geom::CubicBezier const *>(&*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<Geom::cubic_bezier const *>(&*knot_curve2); - Geom::Ray ray2(curve_out.pointAt(0), endArcPoint); + Geom::CubicBezier const *cubic2 = dynamic_cast<Geom::CubicBezier const *>(&*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; } |
