summaryrefslogtreecommitdiffstats
path: root/src/object/sp-shape.cpp
diff options
context:
space:
mode:
authoroctycs <2087987-octycs@users.noreply.gitlab.com>2019-06-01 14:50:20 +0000
committeroctycs <2087987-octycs@users.noreply.gitlab.com>2019-06-01 14:58:22 +0000
commite00088acaec9f2a7587e215d6771eadf8a216b3c (patch)
tree07996b8007355aa345d6dd813f943c28e0b46f4b /src/object/sp-shape.cpp
parentWork around `xgettext --its` crash for old gettext versions (diff)
downloadinkscape-e00088acaec9f2a7587e215d6771eadf8a216b3c.tar.gz
inkscape-e00088acaec9f2a7587e215d6771eadf8a216b3c.zip
Cache bounding box of shapes
Diffstat (limited to '')
-rw-r--r--src/object/sp-shape.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/object/sp-shape.cpp b/src/object/sp-shape.cpp
index d615980c0..eb4c01e54 100644
--- a/src/object/sp-shape.cpp
+++ b/src/object/sp-shape.cpp
@@ -121,6 +121,10 @@ void SPShape::update(SPCtx* ctx, guint flags) {
// std::cout << "SPShape::update(): " << (getId()?getId():"null") << std::endl;
SPLPEItem::update(ctx, flags);
+ // Any update can change the bounding box,
+ // so the cached version can no longer be used.
+ bbox_cache_is_valid = false;
+
/* 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
@@ -456,6 +460,13 @@ void SPShape::modified(unsigned int flags) {
}
Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype) const {
+ // If the object is clipped, the update funcation that invalidates
+ // the cache doesn't get called if the object is moved, so we need
+ // to compare the transformations as well.
+ if (bbox_cache_is_valid && transform == bbox_transform_cache) {
+ return bbox_cache;
+ }
+
Geom::OptRect bbox;
if (!this->_curve || this->_curve->get_pathvector().empty()) {
@@ -641,6 +652,10 @@ Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox
}
}
+ bbox_transform_cache = transform;
+ bbox_cache = bbox;
+ bbox_cache_is_valid = true;
+
return bbox;
}