Package horizons :: Package world :: Package buildability :: Module binarycache :: Class BinaryBuildabilityCache
[hide private]
[frames] | no frames]

Class BinaryBuildabilityCache

source code

A cache that knows where rectangles can be placed such that they are entirely inside the area.

This cache can be used to keep track of building buildability in case the buildability depends on the building being entirely within a certain area. The binary part of the name refers to the fact that a node either is or isn't part of the area that the instance is about.

A query of the form (x, y) in instance.cache[(width, height)] is a very cheap way of finding out whether a rectangle of size (width, height) can be placed on origin (x, y) such that it is entirely within the given area.

All elements of instance.cache[(width, height)] can be iterated to get a complete list of all such coordinates.

Instance Methods [hide private]
 
__init__(self, terrain_cache) source code
 
_reset_lazy_sets(self) source code
 
add_area(self, new_coords_list)
Add a list of new coordinates to the area.
source code
 
remove_area(self, removed_coords_list)
Remove a list of existing coordinates from the area.
source code
Class Methods [hide private]
 
_extend_set(cls, cur_set, prev_set, prev_set_additions, dx, dy) source code
 
_reduce_set(cls, cur_set, prev_set_removals, dx, dy) source code
Method Details [hide private]

add_area(self, new_coords_list)

source code 

Add a list of new coordinates to the area.

This function quickly updates the information about the changed coordinates. For example when (x, y) is added to the area then it will update the information showing whether the 2x1 rectangles with the origin on (x - 1, y) and (x, y) are now completely part of the area. Similar the things are done for the larger sizes.