diff options
| author | octycs <2087987-octycs@users.noreply.gitlab.com> | 2019-06-01 14:50:20 +0000 |
|---|---|---|
| committer | octycs <2087987-octycs@users.noreply.gitlab.com> | 2019-06-01 14:58:22 +0000 |
| commit | e00088acaec9f2a7587e215d6771eadf8a216b3c (patch) | |
| tree | 07996b8007355aa345d6dd813f943c28e0b46f4b | |
| parent | Work around `xgettext --its` crash for old gettext versions (diff) | |
| download | inkscape-e00088acaec9f2a7587e215d6771eadf8a216b3c.tar.gz inkscape-e00088acaec9f2a7587e215d6771eadf8a216b3c.zip | |
Cache bounding box of shapes
| -rw-r--r-- | src/object/sp-shape.cpp | 15 | ||||
| -rw-r--r-- | src/object/sp-shape.h | 5 |
2 files changed, 20 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; } diff --git a/src/object/sp-shape.h b/src/object/sp-shape.h index 6289be079..10d719648 100644 --- a/src/object/sp-shape.h +++ b/src/object/sp-shape.h @@ -49,6 +49,11 @@ public: int hasMarkers () const; int numberOfMarkers (int type) const; + // bbox cache + mutable bool bbox_cache_is_valid = false; + mutable Geom::Affine bbox_transform_cache; + mutable Geom::OptRect bbox_cache; + public: // temporarily public, until SPPath is properly classed, etc. SPCurve *_curve_before_lpe; |
