From e2257981c509ed9c933427baf021baae9167b5c3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 24 Mar 2024 10:27:40 +0100 Subject: [PATCH] [Corners LPE 2] Recalculate corners on changes --- src/helper/geom-pathvector_nodesatellites.cpp | 61 +++++++------------ src/helper/geom-pathvector_nodesatellites.h | 5 +- src/live_effects/lpe-fillet-chamfer.cpp | 16 +++-- 3 files changed, 37 insertions(+), 45 deletions(-) diff --git a/src/helper/geom-pathvector_nodesatellites.cpp b/src/helper/geom-pathvector_nodesatellites.cpp index ce6b18ade6..22647654c5 100644 --- a/src/helper/geom-pathvector_nodesatellites.cpp +++ b/src/helper/geom-pathvector_nodesatellites.cpp @@ -197,51 +197,36 @@ void PathVectorNodeSatellites::updateNodeSatelliteType(NodeSatelliteType nodesat } } -void PathVectorNodeSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, NodeSatellite const S) +std::optional PathVectorNodeSatellites::findNearSatelite(Geom::Point point, double precission) { - // pathv && _pathvector came here: - // * with different number of nodes - // * without empty subpats - // * _pathvector and nodesatellites (old data) are paired - NodeSatellites nodesatellites; + size_t npaths = _pathvector.size(); + for (size_t i = 0; i < npaths; ++i) { + size_t count = count_path_nodes(_pathvector[i]); + for (size_t j = 0; j < count; ++j) { + if (i < _nodesatellites.size() && j < _nodesatellites[i].size()) { + if (Geom::are_near(point, _pathvector[i][j].initialPoint(), precission)) { + return std::make_optional(_nodesatellites[i][j]); + } + } + } + } + return std::nullopt; +} - // TODO evaluate fix on nodes at same position - // size_t number_nodes = count_pathvector_nodes(pathv); - // size_t previous_number_nodes = getTotalNodeSatellites(); +void PathVectorNodeSatellites::adjustForNewPath(Geom::PathVector const pathv, double precission) +{ + NodeSatellites nodesatellites; + // TODO issue for nodes in same place size_t npaths = pathv.size(); + NodeSatellite ns = _nodesatellite; + if (_nodesatellites.size() && _nodesatellites[0].size()) { + ns.setNodeSatellitesType(_nodesatellites[0][0].getNodeSatellitesTypeGchar()); + } for (size_t i = 0; i < npaths; ++i) { std::vector path_nodesatellites; size_t count = count_path_nodes(pathv[i]); for (size_t j = 0; j < count; ++j) { - bool found = false; - for (size_t k = 0; k < _pathvector.size(); ++k) { - size_t countnodes = count_path_nodes(_pathvector[k]); - size_t countcurves = count_path_curves(_pathvector[k]); - if (!_nodesatellites.empty() && !_nodesatellites[k].empty()) { - assert(countnodes == _nodesatellites[k].size()); - for (size_t l = 0; l < countcurves; ++l) { - if (Geom::are_near(_pathvector[k][l].initialPoint(), pathv[i][j].initialPoint(), 0.001)) { // epsilon is not enought big - path_nodesatellites.push_back(_nodesatellites[k][l]); - found = true; - break; - } - } - } - if (found) { - break; - } - } - if (!found) { - if (_pathvector.empty()) { - if (i < _nodesatellites.size() && j < _nodesatellites[i].size()) { - path_nodesatellites.push_back(_nodesatellites[i][j]); - } else { - path_nodesatellites.push_back(S); - } - } else { - path_nodesatellites.push_back(S); - } - } + path_nodesatellites.push_back(findNearSatelite(pathv[i][j].initialPoint()).value_or(ns)); } nodesatellites.push_back(path_nodesatellites); } diff --git a/src/helper/geom-pathvector_nodesatellites.h b/src/helper/geom-pathvector_nodesatellites.h index 4631b320dc..64b1990e0d 100644 --- a/src/helper/geom-pathvector_nodesatellites.h +++ b/src/helper/geom-pathvector_nodesatellites.h @@ -34,6 +34,7 @@ public: void setNodeSatellites(NodeSatellites nodesatellites); size_t getTotalNodeSatellites(); void setSelected(std::vector selected); + void setDefaultNodeSatellite(NodeSatellite nodesatellite) { _nodesatellite = nodesatellite; }; void updateSteps(size_t steps, bool apply_no_radius, bool apply_with_radius, bool only_selected); void updateAmount(double radius, bool apply_no_radius, bool apply_with_radius, bool only_selected, bool use_knot_distance, bool flexible); @@ -41,11 +42,13 @@ public: void updateNodeSatelliteType(NodeSatelliteType nodesatellitetype, bool apply_no_radius, bool apply_with_radius, bool only_selected); std::pair getIndexData(size_t index); - void recalculateForNewPathVector(Geom::PathVector const pathv, NodeSatellite const S); + std::optional findNearSatelite(Geom::Point point, double precission = 0.01); + void adjustForNewPath(Geom::PathVector const pathv, double precission = 0.01); private: Geom::PathVector _pathvector; NodeSatellites _nodesatellites; + NodeSatellite _nodesatellite; }; #endif //SEEN_PATHVECTORSATELLITES_H diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 2d1e0d0a04..42969f68a6 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -65,9 +65,11 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) _pathvector_nodesatellites(nullptr) { // fix legacy < 1.2: - const gchar * satellites_param = getLPEObj()->getAttribute("satellites_param"); - if (satellites_param){ - getLPEObj()->setAttribute("nodesatellites_param", satellites_param); + if (const gchar * satellites_param = getLPEObj()->getAttribute("satellites_param")){ + if (!(getLPEObj()->getAttribute("nodesatellites_param"))) { + getLPEObj()->setAttribute("nodesatellites_param", satellites_param); + } + getLPEObj()->removeAttribute("satellites_param"); }; registerParameter(&nodesatellites_param); registerParameter(&radius); @@ -152,7 +154,8 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) nodesatellite.setIsTime(flexible); nodesatellite.setHasMirror(true); nodesatellite.setHidden(hide_knots); - _pathvector_nodesatellites->recalculateForNewPathVector(pathv, nodesatellite); + _pathvector_nodesatellites->setDefaultNodeSatellite(nodesatellite); + _pathvector_nodesatellites->adjustForNewPath(pathv); nodesatellites_param.setPathVectorNodeSatellites(_pathvector_nodesatellites); } @@ -341,7 +344,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if (!_pathvector_nodesatellites) { _pathvector_nodesatellites = new PathVectorNodeSatellites(); } - if (is_load || _adjust_path) { + if (_adjust_path) { double power = radius; if (!flexible) { power = Inkscape::Util::Quantity::convert(power, unit.get_abbreviation(), "px") / getSPDoc()->getDocumentScale()[Geom::X]; @@ -362,7 +365,8 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) nodesatellite.setHasMirror(true); nodesatellite.setHidden(hide_knots); _pathvector_nodesatellites->setNodeSatellites(nodesatellites); - _pathvector_nodesatellites->recalculateForNewPathVector(pathv, nodesatellite); + _pathvector_nodesatellites->setDefaultNodeSatellite(nodesatellite); + _pathvector_nodesatellites->adjustForNewPath(pathv); nodesatellites_param.setPathVectorNodeSatellites(_pathvector_nodesatellites, true); nodesatellites_param.reloadKnots(); } else { -- GitLab