Skip to content

Commit

Permalink
Add SizeRequirements.check (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Nov 18, 2023
1 parent f7bfd9a commit 35dae6f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/spandrel/__helpers/model_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,29 @@ class SizeRequirements:
def none(self) -> bool:
"""
Returns True if no size requirements are specified.
If True, then `check` is guaranteed to always return True.
"""
return self.minimum is None and self.multiple_of is None and not self.square

def check(self, width: int, height: int) -> bool:
"""
Checks if the given width and height satisfy the size requirements.
"""
if self.minimum is not None:
if width < self.minimum or height < self.minimum:
return False

if self.multiple_of is not None:
if width % self.multiple_of != 0 or height % self.multiple_of != 0:
return False

if self.square:
if width != height:
return False

return True


class ModelBase(ABC, Generic[T]):
def __init__(
Expand Down

0 comments on commit 35dae6f

Please sign in to comment.