From c3fa809a145ee430198863570a5239a9867fcfcb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 18 Jul 2021 19:02:07 +0200 Subject: [PATCH] Add comparsion vector code --- src/helper/geom.cpp | 29 +++++++++++++++++++++++++++++ src/helper/geom.h | 1 + src/object/sp-ellipse.cpp | 6 +++--- src/object/sp-rect.cpp | 5 +++-- src/object/sp-spiral.cpp | 5 +++-- src/object/sp-star.cpp | 5 +++-- 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/helper/geom.cpp b/src/helper/geom.cpp index 5e8e763f5d..8ce1c29354 100644 --- a/src/helper/geom.cpp +++ b/src/helper/geom.cpp @@ -138,6 +138,35 @@ cubic_bbox (Geom::Coord x000, Geom::Coord y000, Geom::Coord x001, Geom::Coord y0 } } +bool +geom_pathv_compare(Geom::PathVector apv, Geom::PathVector bpv, double precission) +{ + size_t totala = apv.curveCount(); + size_t totalb = bpv.curveCount(); + if (totala != totalb) { + return false; + } + std::vector pos; + for (size_t i = 0; i < apv.curveCount(); i++) { + Geom::Point pointa = apv.pointAt(float(i)+0.2); + Geom::Point pointb = bpv.pointAt(float(i)+0.2); + Geom::Point pointc = apv.pointAt(float(i)+0.4); + Geom::Point pointd = bpv.pointAt(float(i)+0.4); + Geom::Point pointe = apv.pointAt(float(i)); + Geom::Point pointf = bpv.pointAt(float(i)); + if (!Geom::are_near(pointa[Geom::X], pointb[Geom::X], precission) || + !Geom::are_near(pointa[Geom::Y], pointb[Geom::Y], precission) || + !Geom::are_near(pointc[Geom::X], pointd[Geom::X], precission) || + !Geom::are_near(pointc[Geom::Y], pointd[Geom::Y], precission) || + !Geom::are_near(pointe[Geom::X], pointf[Geom::X], precission) || + !Geom::are_near(pointe[Geom::Y], pointf[Geom::Y], precission)) + { + return false; + } + } + return true; +} + Geom::OptRect bounds_fast_transformed(Geom::PathVector const & pv, Geom::Affine const & t) { diff --git a/src/helper/geom.h b/src/helper/geom.h index 58f323efee..e33a39f0b9 100644 --- a/src/helper/geom.h +++ b/src/helper/geom.h @@ -28,6 +28,7 @@ void pathv_matrix_point_bbox_wind_distance ( Geom::PathVector const & pathv, Geo size_t count_pathvector_nodes(Geom::PathVector const &pathv ); size_t count_path_nodes(Geom::Path const &path); +bool geom_path_compare(Geom::PathVector apv, Geom::PathVector bpv, double precission = 0.001); Geom::PathVector pathv_to_linear_and_cubic_beziers( Geom::PathVector const &pathv ); Geom::PathVector pathv_to_linear( Geom::PathVector const &pathv, double maxdisp ); Geom::PathVector pathv_to_cubicbezier( Geom::PathVector const &pathv); diff --git a/src/object/sp-ellipse.cpp b/src/object/sp-ellipse.cpp index ac216e1e0a..8bed6f32c5 100644 --- a/src/object/sp-ellipse.cpp +++ b/src/object/sp-ellipse.cpp @@ -21,7 +21,7 @@ #include "live_effects/effect.h" #include "live_effects/lpeobject.h" #include "live_effects/lpeobject-reference.h" - +#include "helper/geom.h" #include <2geom/angle.h> #include <2geom/circle.h> #include <2geom/ellipse.h> @@ -476,9 +476,9 @@ void SPGenericEllipse::set_shape() /* Reset the shape's curve to the "original_curve" * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ auto const before = this->curveBeforeLPE(); - if (before && before->get_pathvector() != c->get_pathvector()) { + if (before && !geom_pathv_compare(before->get_pathvector(), c->get_pathvector(), 0.01)) { setCurveBeforeLPE(std::move(c)); - sp_lpe_item_update_patheffect(this, true, false); + sp_lpe_item_update_patheffect(this, false, false); return; } diff --git a/src/object/sp-rect.cpp b/src/object/sp-rect.cpp index 641c3069d1..a03cb4a236 100644 --- a/src/object/sp-rect.cpp +++ b/src/object/sp-rect.cpp @@ -22,6 +22,7 @@ #include "sp-guide.h" #include "preferences.h" #include "svg/svg.h" +#include "helper/geom.h" #include #define noRECT_VERBOSE @@ -287,9 +288,9 @@ void SPRect::set_shape() { * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ auto const before = this->curveBeforeLPE(); - if (before && before->get_pathvector() != c->get_pathvector()) { + if (before && !geom_pathv_compare(before->get_pathvector(), c->get_pathvector(), 0.01)) { setCurveBeforeLPE(std::move(c)); - sp_lpe_item_update_patheffect(this, true, false); + sp_lpe_item_update_patheffect(this, false, false); return; } if (this->hasPathEffectOnClipOrMaskRecursive(this)) { diff --git a/src/object/sp-spiral.cpp b/src/object/sp-spiral.cpp index 1087205704..78082859a7 100644 --- a/src/object/sp-spiral.cpp +++ b/src/object/sp-spiral.cpp @@ -23,6 +23,7 @@ #include "display/curve.h" #include #include "xml/repr.h" +#include "helper/geom.h" #include "document.h" #include "sp-spiral.h" @@ -345,9 +346,9 @@ void SPSpiral::set_shape() { * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ auto const before = this->curveBeforeLPE(); - if (before && before->get_pathvector() != c->get_pathvector()) { + if (before && !geom_pathv_compare(before->get_pathvector(), c->get_pathvector(), 0.01)) { setCurveBeforeLPE(std::move(c)); - sp_lpe_item_update_patheffect(this, true, false); + sp_lpe_item_update_patheffect(this, false, false); return; } diff --git a/src/object/sp-star.cpp b/src/object/sp-star.cpp index 0fa820cca0..df8c790ba4 100644 --- a/src/object/sp-star.cpp +++ b/src/object/sp-star.cpp @@ -26,6 +26,7 @@ #include "document.h" #include "sp-star.h" +#include "helper/geom.h" #include SPStar::SPStar() : SPShape() , @@ -427,9 +428,9 @@ void SPStar::set_shape() { * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ auto const before = this->curveBeforeLPE(); - if (before && before->get_pathvector() != c->get_pathvector()) { + if (before && !geom_pathv_compare(before->get_pathvector(), c->get_pathvector(), 0.01)) { setCurveBeforeLPE(std::move(c)); - sp_lpe_item_update_patheffect(this, true, false); + sp_lpe_item_update_patheffect(this, false, false); return; } -- GitLab