From eccf21e99a6de7a3c4ac1a62058f0b5b2dfee546 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 30 Mar 2024 17:45:11 +0100 Subject: [PATCH 1/3] Fix bbox cache --- src/object/sp-item.h | 2 +- src/object/sp-shape.cpp | 22 ++++++++++++++++------ src/object/sp-shape.h | 2 ++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/object/sp-item.h b/src/object/sp-item.h index 933cdafae9..caf926222f 100644 --- a/src/object/sp-item.h +++ b/src/object/sp-item.h @@ -374,7 +374,7 @@ public: * Sets item private transform (not propagated to repr), without compensating stroke widths, * gradients, patterns as sp_item_write_transform does. */ - void set_item_transform(Geom::Affine const &transform_matrix); + virtual void set_item_transform(Geom::Affine const &transform_matrix); /** * Return the arenaitem corresponding to the given item in the display diff --git a/src/object/sp-shape.cpp b/src/object/sp-shape.cpp index 0aa746f28d..39f091d03c 100644 --- a/src/object/sp-shape.cpp +++ b/src/object/sp-shape.cpp @@ -122,16 +122,25 @@ Inkscape::XML::Node* SPShape::write(Inkscape::XML::Document *xml_doc, Inkscape:: return repr; } +void SPShape::set_item_transform(Geom::Affine const &transform_matrix) +{ + // when we release the mouse still have transform as affine + // we check the affine is empty to allow recheck the bbox cache + cache_bbox_valid = !Geom::are_near(transform_matrix, Geom::Affine()); + SPItem::set_item_transform(transform_matrix); +} + void SPShape::update(SPCtx* ctx, guint flags) { // Any update can change the bounding box, // so the cached version can no longer be used. // But the idle checker usually is just moving the objects around. - bbox_vis_cache_is_valid = false; - bbox_geom_cache_is_valid = false; - + if (!cache_bbox_valid) { + bbox_vis_cache_is_valid = false; + bbox_geom_cache_is_valid = false; + } + cache_bbox_valid = false; // std::cout << "SPShape::update(): " << (getId()?getId():"null") << std::endl; SPLPEItem::update(ctx, flags); - /* This stanza checks that an object's marker style agrees with * the marker objects it has allocated. sp_shape_set_marker ensures * that the appropriate marker objects are present (or absent) to @@ -541,7 +550,8 @@ Geom::OptRect SPShape::either_bbox(Geom::Affine const &transform, SPItem::BBoxTy // Return the cache if possible. auto delta = transform_cache.inverse() * transform; if (cache_is_valid && bbox_cache && delta.isTranslation()) { - + // uncomenting cout fail some output based tests + // std::cout << "using cache bbox" << std::endl; // Don't re-adjust the cache if we haven't moved if (!delta.isNonzeroTranslation()) { return bbox_cache; @@ -549,7 +559,7 @@ Geom::OptRect SPShape::either_bbox(Geom::Affine const &transform, SPItem::BBoxTy // delta is pure translation so it's safe to use it as is return *bbox_cache * delta; } - + // std::cout << "not using cache bbox" << std::endl; if (!this->_curve || this->_curve->get_pathvector().empty()) { return bbox; } diff --git a/src/object/sp-shape.h b/src/object/sp-shape.h index 9d257290a1..5170b0a14f 100644 --- a/src/object/sp-shape.h +++ b/src/object/sp-shape.h @@ -58,6 +58,7 @@ public: int numberOfMarkers (int type) const; // bbox cache + mutable bool cache_bbox_valid = false; mutable bool bbox_geom_cache_is_valid = false; mutable bool bbox_vis_cache_is_valid = false; mutable Geom::Affine bbox_geom_cache_transform; @@ -78,6 +79,7 @@ public: void release() override; void update(SPCtx* ctx, unsigned int flags) override; void modified(unsigned int flags) override; + void set_item_transform(Geom::Affine const &transform_matrix) override; void set(SPAttr key, char const* value) override; Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override; -- GitLab From d0bffc96efb41b3f80d5622391c4a308a9dec594 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Wed, 18 Dec 2024 21:50:17 +0000 Subject: [PATCH 2/3] change cout to cerr --- src/object/sp-shape.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/object/sp-shape.cpp b/src/object/sp-shape.cpp index 39f091d03c..71ad145b38 100644 --- a/src/object/sp-shape.cpp +++ b/src/object/sp-shape.cpp @@ -550,8 +550,7 @@ Geom::OptRect SPShape::either_bbox(Geom::Affine const &transform, SPItem::BBoxTy // Return the cache if possible. auto delta = transform_cache.inverse() * transform; if (cache_is_valid && bbox_cache && delta.isTranslation()) { - // uncomenting cout fail some output based tests - // std::cout << "using cache bbox" << std::endl; + // std::cerr << "using cache bbox" << std::endl; // Don't re-adjust the cache if we haven't moved if (!delta.isNonzeroTranslation()) { return bbox_cache; @@ -559,7 +558,7 @@ Geom::OptRect SPShape::either_bbox(Geom::Affine const &transform, SPItem::BBoxTy // delta is pure translation so it's safe to use it as is return *bbox_cache * delta; } - // std::cout << "not using cache bbox" << std::endl; + // std::cerr << "not using cache bbox" << std::endl; if (!this->_curve || this->_curve->get_pathvector().empty()) { return bbox; } -- GitLab From 48b0ddfec324c37f7755b05bccc59a4db1aa1825 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Thu, 19 Dec 2024 13:58:34 +0000 Subject: [PATCH 3/3] alive cerr to compare --- src/object/sp-shape.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/object/sp-shape.cpp b/src/object/sp-shape.cpp index ab1c90e754..9807a57834 100644 --- a/src/object/sp-shape.cpp +++ b/src/object/sp-shape.cpp @@ -552,7 +552,7 @@ Geom::OptRect SPShape::either_bbox(Geom::Affine const &transform, SPItem::BBoxTy // Return the cache if possible. auto delta = transform_cache.inverse() * transform; if (cache_is_valid && bbox_cache && delta.isTranslation()) { - // std::cerr << "using cache bbox" << std::endl; + std::cerr << "using cache bbox" << std::endl; // Don't re-adjust the cache if we haven't moved if (!delta.isNonzeroTranslation()) { return bbox_cache; @@ -560,7 +560,7 @@ Geom::OptRect SPShape::either_bbox(Geom::Affine const &transform, SPItem::BBoxTy // delta is pure translation so it's safe to use it as is return *bbox_cache * delta; } - // std::cerr << "not using cache bbox" << std::endl; + std::cerr << "not using cache bbox" << std::endl; if (!this->_curve || this->_curve->get_pathvector().empty()) { return bbox; } -- GitLab