diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2016-05-08 20:57:37 +0000 |
|---|---|---|
| committer | jabiertxof <info@marker.es> | 2016-05-08 20:57:37 +0000 |
| commit | 97bd182d6a2113eab1dd5faf51402ebd5382791c (patch) | |
| tree | 272e95fb4951a821dbd5f416cd19250dcc278819 /src/helper | |
| parent | update to trunk (diff) | |
| download | inkscape-97bd182d6a2113eab1dd5faf51402ebd5382791c.tar.gz inkscape-97bd182d6a2113eab1dd5faf51402ebd5382791c.zip | |
First attempt to make fixed tweenk review
(bzr r13645.1.128)
Diffstat (limited to 'src/helper')
| -rw-r--r-- | src/helper/geom-pointwise.cpp | 277 | ||||
| -rw-r--r-- | src/helper/geom-pointwise.h | 49 | ||||
| -rw-r--r-- | src/helper/geom-satellite.cpp | 60 | ||||
| -rw-r--r-- | src/helper/geom-satellite.h | 16 |
4 files changed, 131 insertions, 271 deletions
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 <helper/geom-pointwise.h> -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<Satellite> 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<Satellite> 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<Satellite> 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<Satellite> 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<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); + 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<satellite> 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<Geom::D2<Geom::SBasis> > pwd2sb; +typedef Geom::Piecewise<Geom::D2<Geom::SBasis> > 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<Satellite> getSatellites(); - void setSatellites(std::vector<Satellite> 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<Satellite> _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<Geom::SBasis> 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<double> 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<Geom::SBasis> 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<Geom::SBasis> d2_in = curve_in.toSBasis(); Geom::D2<Geom::SBasis> d2_out = curve_out.toSBasis(); - Geom::Piecewise<Geom::D2<Geom::SBasis> > offset_curve0 = + Geom::Piecewise<Geom::D2<Geom::SBasis> > offset_curve0 = Geom::Piecewise<Geom::D2<Geom::SBasis> >(d2_in) + rot90(unitVector(derivative(d2_in))) * (A); Geom::Piecewise<Geom::D2<Geom::SBasis> > 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<Geom::CubicBezier const *>(&*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<Geom::cubic_bezier const *>(&*knot_curve1); Geom::Ray ray1(startArcPoint, curve_in.pointAt(1)); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } - Geom::CubicBezier const *cubic2 = - dynamic_cast<Geom::CubicBezier const *>(&*knotCurve2); + Geom::cubic_bezier const *cubic2 = dynamic_cast<Geom::cubic_bezier const *>(&*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<Geom::Curve *>(&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; |
