Conversation
AddsAllregionshape functions. Allows users to given a region (int), return a corresponding Shape generate shapes for all regions, which can be accessed as: allregions:= AllRegionShapes() allregions(i) where i=0...255
| ) | ||
|
|
||
| func init() { | ||
| DeclFunc("AllRegionShapes", AllRegionShapes, "Returns a function that gives the shape of each region.") |
There was a problem hiding this comment.
I think in the current state, where this feature doesn't work with shifting, this should probably be considered an extension (i.e., exposed as ext_AllRegionShapes) since we can't guarantee expected behavior in all cases.
This could be fixed if the Shape would adapt to changes in the regions array, but such mutability might not be desirable since it wouldn't allow one to save an old region configuration.
A short description of the possible caveats could be included in the description here to warn users.
| DeclFunc("AllRegionShapes", AllRegionShapes, "Returns a function that gives the shape of each region.") | ||
| } | ||
|
|
||
| func AllRegionShapes() func(int) Shape { |
There was a problem hiding this comment.
The double parentheses syntax due to returning a func(int) could indeed be confusing, but I think this is ok for performance reasons and is not unprecedented (FunctionFromDataFile does so too).
The sentence in the API documentation is already pretty clear, but I would still include an adaptation of your example in the test directory to make its usage absolutely clear to users.
This PR adds a function
AllRegionShapeswhich for a given region value, will return a Shape with all cells in that region. Can be easily looped over all 256 regions. This is intended mainly if one wants to make Shapes of say, Voronoi grains, to be used with Masked().An example file is including showing how each shape can be accessed after AllRegionShapes is called (there is some slightly unusual syntax, it uses 2 sets of parantheses), and also how they can be added together in a simple loop, is attached here: regionshape_example.txt
does not yet work with shift/moving frame stuff. I am not sure if it could, or should?