Skip to content

Commit

Permalink
Mypy type safety: round 3
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBB committed Feb 13, 2024
1 parent 8bf414c commit 76322c9
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 107 deletions.
2 changes: 1 addition & 1 deletion splipy/curve_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def circle_segment_from_three_points(x0: Scalars, x1: Scalars, x2: Scalars) -> C
np.dot(pt2,pt2) - np.dot(pt0,pt0),
np.dot(normal,pt0),
],
dtype=float
dtype=float,
)
center = np.linalg.solve(A,b)
radius = norm(pt2-center)
Expand Down
10 changes: 5 additions & 5 deletions splipy/splineobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,12 +1062,12 @@ def mirror(self, normal: Scalars) -> Self:
raise RuntimeError('reflection undefined for geometries other than 3D')

# fixup the input normal to right form
normal = np.array(normal)
normal = normal / np.sqrt(np.dot(normal, normal)) # normalize it
normal_vec = np.asarray(normal, dtype=float)
normal_vec /= np.sqrt(np.dot(normal_vec, normal_vec)) # normalize it

# set up the reflection matrix
reflection_matrix = np.identity(dim + rat)
reflection_matrix[0:dim, 0:dim] -= 2 * np.outer(normal, normal)
reflection_matrix[0:dim, 0:dim] -= 2 * np.outer(normal_vec, normal_vec)

# wrap out the controlpoints to a matrix (down from n-D tensor)
cp = np.reshape(self.controlpoints, (n, dim + rat))
Expand Down Expand Up @@ -1565,12 +1565,12 @@ def flip_and_move_plane_geometry(self, center: Scalars = (0,0,0), normal: Scalar
Don't call unless necessary. Translate or scale operations may force
an object into 3D space.
"""
if not np.allclose(normal, np.array([0,0,1])):
if not np.allclose(np.asarray(normal), np.array([0,0,1])):
theta = np.arctan2(normal[1], normal[0])
phi = np.arctan2(np.sqrt(normal[0]**2+normal[1]**2), normal[2])
self.rotate(phi, (0,1,0))
self.rotate(theta, (0,0,1))
if not np.allclose(center, 0):
if not np.allclose(np.asarray(center), 0):
self.translate(center)
return self

Expand Down
Loading

0 comments on commit 76322c9

Please sign in to comment.