str2d.region

str2d.region(func, height, width, x_range, y_range)[source]

Create a mask where func is True. Imagine a 2D space that is subdivided into height rows and width columns. The edges of the space are defined by x_range and y_range. This function returns a mask where func is True for the center of each cell.

Parameters:
  • func (Callable[[np.ndarray, np.ndarray], np.ndarray]) – The function that returns True if the point is in the region.

  • height (int) – The number of rows.

  • width (int) – The number of columns.

  • x_range (Tuple[float, float]) – The range of the x values.

  • y_range (Tuple[float, float]) – The range of the y values.

Returns:

A mask where func is True for the center of each cell.

Return type:

np.ndarray

See also

boundary

Create a mask where func is True and False.

Examples

Let’s imagine height=10 and width=20 and x_range=[0, 1] and y_range=[0, 1].

Now we’ll assume a simple function that returns True if the 1 less the x coordinate is less than the y coordinate.

… testinput:

height = 10
width = 20
x_range = [0, 1]
y_range = [0, 1]

def func(x, y):
    return 1 - x < y

mask = region(func, height, width, x_range, y_range)

Str2D(mask, char='*')
*******************
  *****************
    ***************
      *************
        ***********
          *********
            *******
              *****
                ***
                  *