str2d.boundary

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

Create a mask where func is True and False. 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. The mask being returned is a proxy for each of the cells. The truth of each cell is determined by whether func is True for at least one of the corners of the cell while also being False for at least one of the corners of the cell. That implies that the function crosses from being True to False or False to True within the cell and thus a boundary.

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

region

Create a mask where func is True.

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 = boundary(func, height, width, x_range, y_range)

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