Skip to content

Feature: RegionShapes#385

Open
jplauzie wants to merge 2 commits intomumax:3.11.2from
jplauzie:RegionShapes
Open

Feature: RegionShapes#385
jplauzie wants to merge 2 commits intomumax:3.11.2from
jplauzie:RegionShapes

Conversation

@jplauzie
Copy link

This PR adds a function AllRegionShapes which 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?

JonathanMaes and others added 2 commits March 12, 2026 15:12
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
@JonathanMaes JonathanMaes changed the base branch from master to 3.11.2 March 18, 2026 15:27
)

func init() {
DeclFunc("AllRegionShapes", AllRegionShapes, "Returns a function that gives the shape of each region.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants