Skip to content

Commit

Permalink
New rectangle function, deprecate slit
Browse files Browse the repository at this point in the history
  • Loading branch information
andykee committed Jan 3, 2024
1 parent 0f003e4 commit 72f8df2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/ref/util.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Shapes

lentil.circle
lentil.hexagon
lentil.slit
lentil.rectangle

Array manipulation
------------------
Expand Down
2 changes: 1 addition & 1 deletion lentil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from lentil.shape import (
circle,
hexagon,
slit
rectangle
)

from lentil import util
Expand Down
36 changes: 21 additions & 15 deletions lentil/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,37 @@ def hexagon(shape, radius, shift=(0, 0), rotate=False, antialias=True):
return mask


def slit(shape, width, length=None):
"""Draw a rectangular slit
def rectangle(shape, width, height, shift=(0,0), antialias=True):
"""Draw a rectangle
Parameters
----------
shape : array_like
Size of output in pixels (nrows, ncols)
width : float
Slit width in pixels
length : float, optional
Slit length in pixels. If not specified, the slit spans
the entire column shape (default).
Width of rectangle in pixels
height : float
Height of rectangle in pixels
shift : tuple of floats, optional
How far to shift center in (rows, cols). Default is (0, 0).
antialias : bool, optional
If True (default), the shape edges are antialiased.
Returns
-------
ndarray
"""
rr, cc = lentil.helper.mesh(shape)
slit = np.ones(shape)
shape = np.broadcast_to(shape, (2,))
rr, cc = lentil.helper.mesh(shape, shift)
rect = np.ones(shape)

width_clip = np.clip(0.5 + (width/2) - np.abs(cc), 0, 1)
height_clip = np.clip(0.5 + (height/2) - np.abs(rr), 0, 1)

length = shape[1] if length is None else length
width_clip = np.clip(0.5 + (width/2) - np.abs(rr), 0, 1)
length_clip = np.clip(0.5 + (length/2) - np.abs(cc), 0, 1)
rect = np.minimum(np.minimum(rect, width_clip), height_clip)

slit = np.minimum(np.minimum(slit, width_clip), length_clip)
if not antialias:
rect[rect > 0] = 1

return slit
return rect

0 comments on commit 72f8df2

Please sign in to comment.