Skip to content

Commit

Permalink
made Array2D ensure width and heigth are ints.
Browse files Browse the repository at this point in the history
  • Loading branch information
pokepetter committed Oct 27, 2024
1 parent 85dc7ec commit 21b965a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ursina/array_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ def __init__(self, width:int=None, height:int=None, default_value=0, data:List[L

if data is not None: # initialize with provided data
self.width = len(data)
self.height = len(data[0]) if self.width > 0 else 0
self.height = len(data[0])
if self.width == 0 or self.height == 0:
raise ValueError("width and height must be >= 1.")

if any(len(row) != self.height for row in data):
raise ValueError("All rows in the data must have the same length.")
raise ValueError("all rows in the data must have the same length.")

super().__init__(data)

else: # Initialize with default values
if width is None or height is None:
raise ValueError("Width and height must be provided if no data is given.")
raise ValueError("width and height must be provided if no data is given.")

self.width = width
self.height = height
self.width = int(width)
self.height = int(height)
super().__init__([[self.default_value for _ in range(self.height)] for _ in range(self.width)])

def to_string(self):
Expand Down
6 changes: 6 additions & 0 deletions ursina/vec3.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ def Y(self):
@property
def Z(self):
return int(self.z)
@property
def XY(self):
return (self.X, self.Y)
@property
def XZ(self):
return (self.X, self.Z)


def __mul__(self, value):
Expand Down

0 comments on commit 21b965a

Please sign in to comment.