Skip to content

Commit

Permalink
Add: test functions in create-test-file
Browse files Browse the repository at this point in the history
  • Loading branch information
OberGue committed Jul 2, 2024
1 parent 045a493 commit 3262829
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion splinepy/helpme/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ def swept(
raise NotImplementedError("Sweep only works for splines")
if not trajectory.para_dim == 1:
raise NotImplementedError("Trajectory must be 1D")
if not len(cross_section_normal) == 3:

if cross_section_normal is not None and not len(cross_section_normal) == 3:
raise ValueError("Cross section normal must be 3D")
if not isinstance(auto_refinement, bool):
raise ValueError("auto_refinement must be a boolean")
Expand Down
76 changes: 76 additions & 0 deletions tests/helpme/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,79 @@ def test_determinant_spline(
det_spl.evaluate(queries=rnd_queries).ravel(),
np.linalg.det(sp_i.jacobian(queries=rnd_queries)),
), f"{sp_i.whatami} at index {idx} failed determinant spline"


def test_swept_basic_functionality():
cross_section = splinepy.BSpline(
degrees=[2],
control_points=[[0, 0], [0.5, 1], [1, 0]],
knot_vectors=[[0, 0, 0, 1, 1, 1]],
)
trajectory = splinepy.BSpline(
degrees=[3],
control_points=[[0, 0], [1, 2], [2, 3], [3, 3]],
knot_vectors=[[0, 0, 0, 0, 1, 1, 1, 1]],
)
result = splinepy.helpme.create.swept(cross_section, trajectory)
assert result is not None
assert (
result.control_points.shape[0]
== cross_section.control_points.shape[0]
* trajectory.control_points.shape[0]
)


def test_swept_with_custom_normal():
cross_section = splinepy.BSpline(
degrees=[2],
control_points=[[0, 0], [0.5, 1], [1, 0]],
knot_vectors=[[0, 0, 0, 1, 1, 1]],
)
trajectory = splinepy.BSpline(
degrees=[3],
control_points=[[0, 0], [1, 2], [2, 3], [3, 3]],
knot_vectors=[[0, 0, 0, 0, 1, 1, 1, 1]],
)
custom_normal = np.array([0, 1, 0])
result = splinepy.helpme.create.swept(
cross_section, trajectory, cross_section_normal=custom_normal
)
assert result is not None


def test_swept_invalid_inputs():
cross_section = splinepy.BSpline(
degrees=[2],
control_points=[[0, 0], [0.5, 1], [1, 0]],
knot_vectors=[[0, 0, 0, 1, 1, 1]],
)
invalid_trajectory = "invalid_trajectory"
with pytest.raises(NotImplementedError):
splinepy.helpme.create.swept(cross_section, invalid_trajectory)

invalid_cross_section = "invalid_cross_section"
trajectory = splinepy.BSpline(
degrees=[3],
control_points=[[0, 0], [1, 2], [2, 3], [3, 3]],
knot_vectors=[[0, 0, 0, 0, 1, 1, 1, 1]],
)
with pytest.raises(NotImplementedError):
splinepy.helpme.create.swept(invalid_cross_section, trajectory)


def test_swept_rational_splines():
cross_section = splinepy.NURBS(
degrees=[2],
control_points=[[0, 0], [0.5, 1], [1, 0]],
weights=[1, 0.5, 1],
knot_vectors=[[0, 0, 0, 1, 1, 1]],
)
trajectory = splinepy.NURBS(
degrees=[3],
control_points=[[0, 0], [1, 2], [2, 3], [3, 3]],
weights=[1, 0.5, 0.5, 1],
knot_vectors=[[0, 0, 0, 0, 1, 1, 1, 1]],
)
result = splinepy.helpme.create.swept(cross_section, trajectory)
assert result is not None
assert result.is_rational

0 comments on commit 3262829

Please sign in to comment.