Skip to content

Commit 9c1bd98

Browse files
committed
Fix: moved parameter validiation
1 parent fca8752 commit 9c1bd98

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

splinepy/helpme/create.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,27 +390,41 @@ def swept(
390390
)
391391
if not trajectory.para_dim == 1:
392392
raise ValueError("trajectory must have a parametric dimension of 1")
393+
393394
if cross_section.para_dim > 2:
394395
raise ValueError(
395396
"cross_section must have a parametric dimension of at most 2"
396397
)
397398

398399
if not isinstance(set_on_trajectory, bool):
399400
raise TypeError("set_on_trajectory must be a boolean")
400-
if not isinstance(anchor, str):
401-
raise TypeError("anchor must be a string")
401+
402+
if rotation_adaption is not None:
403+
try:
404+
rotation_adaption = float(rotation_adaption)
405+
except TypeError:
406+
raise TypeError(
407+
"rotation_adaption must be a number (float, int) or None"
408+
)
402409

403410
if cross_section_normal is None:
404411
cross_section_normal = _np.array([0, 0, 1])
405412
# add debug message
406413
_log.debug("No cross_section_normal given. Defaulting to [0, 0, 1].")
407414
else:
408-
cross_section_normal = _np.asarray(cross_section_normal).ravel()
415+
try:
416+
cross_section_normal = _np.asarray(cross_section_normal).ravel()
417+
except (TypeError, ValueError):
418+
raise TypeError(
419+
"cross_section_normal must be array-like and a 3D vector"
420+
)
409421
if cross_section_normal.shape != (3,):
410422
raise ValueError(
411423
"cross_section_normal must be array-like and a 3D vector"
412424
)
413425

426+
if not isinstance(anchor, str):
427+
raise TypeError("anchor must be a string")
414428
anchor = anchor.lower()
415429
if anchor == "auto":
416430
anchor = (
@@ -596,13 +610,6 @@ def swept(
596610

597611
# rotate cross-section around trajectory tangent vector (e1) if wanted
598612
if rotation_adaption is not None:
599-
try:
600-
rotation_adaption = float(rotation_adaption)
601-
except TypeError:
602-
raise TypeError(
603-
"rotation_adaption must be a number (float, int) or None"
604-
)
605-
606613
R = _np.matmul(
607614
_arr.rotation_matrix_around_axis(
608615
axis=[1, 0, 0], rotation=rotation_adaption, degree=False
@@ -625,7 +632,7 @@ def swept(
625632
cs_min = cross_section.control_points.min(axis=0)
626633
cs_max = cross_section.control_points.max(axis=0)
627634
cs_center = 0.5 * (cs_min + cs_max)
628-
else:
635+
else: # geometry_box
629636
if cross_section.para_dim == 1:
630637
sample_resolution = max(
631638
101, 4 * cross_section.control_points.shape[0]

0 commit comments

Comments
 (0)