On 2-9-2011 0:35, Krzysztof Kosiński wrote:
W dniu 30 sierpnia 2011 21:51 użytkownik Johan Engelen <jbc.engelen@...2592...> napisał:
To me it sounds pretty straightforward to cache the bbox value for items. Perhaps we could make a struct of cached values for items that are invalidated upon (relevant) changes? I have no experience with this, perhaps someone knows how this can be implemented in a straightforward and easily usable way? For LPE, it is also be desirable to cache intermediate results, so something like this would be awesome: SPItem::addItemToCache(string key, any value) optional value SPItem::retrieveFromCache(string key)
- There is a complication that the bbox depends on the transformation
supplied to the bounds() method. We could cache document and desktop bounds though.
I think the transformation in usually only a scale/translate transform. With some work, the result could still be cached and reused then, right?
- I don't think the caching mechanism should be explicit.
What do you mean exactly?
- The SPItem should contain an OptRect for document bounds. It should
not be a list external to the SP tree. I assume that even after we allow any desktop transforms, they will be limited to zooming (e.g. only translation& uniform scale, no rotations), so storing a separate rect for desktop coords is unnecessary.
So we would modify documentVisualBounds to something like that: if (bbox_valid) return bbox; bbox = call virtual bbox method; bbox_valid = true; return bbox;
The update() method of SPItem would set bbox_valid to false when appropriate.
That is basically what is proposed with this caching method, but then in a more general way that allows one to do this for more than just the bbox, without too much coding (and having 'cache'-like code all over the place).
-Johan