From 397b78afd3f938cdd9903cd6a09e95695930890e Mon Sep 17 00:00:00 2001 From: WaterNewt <134024849+WaterNewt@users.noreply.github.com> Date: Sat, 23 Mar 2024 08:24:44 +0500 Subject: [PATCH] Updated cython class files --- ray.pyx | 19 +++++++++++++------ walls.pyx | 11 +++++++---- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ray.pyx b/ray.pyx index 569e377..da1b0af 100644 --- a/ray.pyx +++ b/ray.pyx @@ -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 @@ -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 @@ -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 diff --git a/walls.pyx b/walls.pyx index d7c0bce..79a0e4d 100644 --- a/walls.pyx +++ b/walls.pyx @@ -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 @@ -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') -