diff --git a/src/object/sp-item.h b/src/object/sp-item.h index 2db03b477bdd6bc15d4f394ee859476df568c285..d913f18f5b49fd8602c2f7d7e23507332770d845 100644 --- a/src/object/sp-item.h +++ b/src/object/sp-item.h @@ -380,7 +380,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 68317e1979e3e6824813922be58d9b34e94847c7..9807a5783457419df5665109262e1dbb5465704a 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 @@ -543,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; // Don't re-adjust the cache if we haven't moved if (!delta.isNonzeroTranslation()) { return bbox_cache; @@ -551,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; 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 9d257290a1499ec6af39232218ab5181440c6e75..5170b0a14fd804d4a3d2f01e6535e2a1ced965ad 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;