Skip to content

Commit

Permalink
Updated cython class files
Browse files Browse the repository at this point in the history
  • Loading branch information
WaterNewt committed Mar 23, 2024
1 parent fe04a5f commit 397b78a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
19 changes: 13 additions & 6 deletions ray.pyx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import math

cdef class Ray:
cdef tuple start
cdef tuple end
cdef list intersecting_walls

class Ray:
def __init__(self, start, end) -> None:
def __cinit__(self, start, end):
"""
Initialize the ray line
:param start: The start position of the ray line
Expand All @@ -12,14 +15,18 @@ class Ray:
self.end = end
self.intersecting_walls = []

def cast(self, walls) -> tuple[float, float] | None:
cpdef cast(self, walls):
"""
Cast the rays to the walls and check for intersection
:param walls: The walls for the ray to cast
:return: Returns position of the closest intersection. Returns None, if no intersection
"""
record = float('inf')
closest = None
cdef float record = float('inf')
cdef tuple closest = None

cdef float x1, y1, x2, y2, x3, y3, x4, y4
cdef float den, t, u, px, py, d
cdef bint intersecting

for wall in walls:
wall.intersecting = False
Expand Down Expand Up @@ -52,7 +59,7 @@ class Ray:

return closest

def point_dist(self, px, py) -> float:
cpdef point_dist(self, float px, float py):
"""
Distance between two points
:param px: The x point
Expand Down
11 changes: 7 additions & 4 deletions walls.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class Wall:
def __init__(self, start, end) -> None:
cdef class Wall:
cdef tuple start
cdef tuple end
cdef bint intersecting

def __cinit__(self, start, end):
"""
Initialize a wall line
:param start: The start position of the wall line
Expand All @@ -9,10 +13,9 @@ class Wall:
self.end = end
self.intersecting = False

def __repr__(self) -> str:
def __repr__(self):
"""
Representation magic method
:return: Returns the representation string
"""
return "{}(start={}, end={}, intersecting={})".format(self.__class__.__name__, str(self.start), str(self.end), str(self.intersecting)).encode('utf-8')

0 comments on commit 397b78a

Please sign in to comment.