Cache mesh bounding boxes correctly#5180
Conversation
connorjward
left a comment
There was a problem hiding this comment.
The really nice way to do this is:
def cached_property_until(cond: Callable[[Self], bool]):
def decorator(func):
def wrapper(self):
if cond(self):
return self._cache[some key]
else:
return self._cache.setdefault(some key, func(self))
cached_property_until_coords_change = cached_property_until(lambda self: self._saved_coords_dat_version == self.coordinates.dat.dat_version)so you can have
@cached_property_until_coords_change
def bounding_box_coords(self):
...|
@achanbour this is very relevant to your work, and you have already probably done something similar. Any comments? |
2fe3ae2 to
534b1fd
Compare
|
I currently have an attribute that keeps track of the mesh's topology In both regimes (coordinates change OR topology changes), the |
After changing mesh coordinates, accessing
mesh.bounding_box_coordswill now recalculate the bounding boxes.Added a
mesh._check_coordinate_dat_versionhelper because this sort of thing happens in a few places (bounding boxes, rtree, soon to be distributed rtree)