From 51400471ba7c5bc9fa1a90ab59d1dd0b0da5c153 Mon Sep 17 00:00:00 2001 From: Timotej Bernat Date: Thu, 25 Apr 2024 20:32:43 -0600 Subject: [PATCH] Replaced generic __class__.__init__() call with Coordinates.__init__() call to avoid inheritance issues when using "as_coords=True" flag --- polymerist/maths/lattices/coordinates.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/polymerist/maths/lattices/coordinates.py b/polymerist/maths/lattices/coordinates.py index 0cc6f38..4e4f9ec 100644 --- a/polymerist/maths/lattices/coordinates.py +++ b/polymerist/maths/lattices/coordinates.py @@ -131,7 +131,8 @@ def linear_transformation(self, matrix : np.ndarray[Shape[N,N], float], as_coord transformed_points = self.points @ matrix.T # NOTE: need to right-multiply and transpose, since ROWS of self.points need to be tranformed if as_coords: - return self.__class__(transformed_points) + # return self.__class__(transformed_points) # TOSELF: this form is more general, but doesn't play nicely with inheritance + return Coordinates(transformed_points) return transformed_points def affine_transformation(self, matrix : np.ndarray[Shape[N,N], float], as_coords : bool=False) -> Union[np.ndarray[Shape[M, N], float], 'Coordinates']: # TOSELF: typehint on input matrix should be of shape N+1, N+1 @@ -142,7 +143,8 @@ def affine_transformation(self, matrix : np.ndarray[Shape[N,N], float], as_coord transformed_points = aug_transformed[: , :self.n_dims] / aug_transformed[:, self.n_dims, None] # downcast augmented transformed points from homogeneous coordinates, normalizing by projective part if as_coords: - return self.__class__(transformed_points) + # return self.__class__(transformed_points) # TOSELF: this form is more general, but doesn't play nicely with inheritance + return Coordinates(transformed_points) return transformed_points @@ -151,7 +153,7 @@ class BoundingBox(Coordinates): def __init__(self, coords : Union[Coordinates, np.ndarray[Shape[M, N], Num]]) -> None: if isinstance(coords, np.ndarray): coords = Coordinates(coords) # allow passing of Coordinates-like classes - points = np.array([vertex for vertex in cartesian_product(*self.extrema.T)]) + points = np.array([vertex for vertex in cartesian_product(*coords.extrema.T)]) super().__init__(points)