Open OberGue opened 3 months ago
Nice, can you post some screenshots?
Nice, can you post some screenshots?
Sure! Be aware that work is still in progress.
The recent updates introduce a new example script for creating and visualizing swept surfaces and solids using spline representations in the splinepy
library. Enhancements to the swept
function allow for improved control over the sweeping process. The changes also involve the addition of various cross-section shapes and their visualization, along with new test cases to ensure functionality.
Files | Change Summaries |
---|---|
examples/show_swept.py |
Added functionality to demonstrate the creation and visualization of swept surfaces and solids, including various cross-section shapes. |
splinepy/helpme/create.py |
Expanded the swept function to enhance control over rotation and placement options for sweeping cross-sections along trajectories. |
tests/helpme/test_create.py |
Introduced test functions to validate swept spline functionality and compare with extruded surfaces. |
splinepy/bspline.py |
Minor code cleanup in the remove_knots method by removing unnecessary whitespace. |
sequenceDiagram
participant User
participant ExampleScript as show_swept.py
participant SplinePy as splinepy.create.py
participant Visualizer as gustaf
User->>ExampleScript: Run script
ExampleScript->>SplinePy: Call swept(cross_section, trajectory)
SplinePy-->>ExampleScript: Return swept_surface
ExampleScript->>Visualizer: Visualize trajectory, cross-section, and swept_surface
ExampleScript->>User: Display result
In the world of splines, a tale unfolds,
With trajectories swept, new wonders are told.
From cross-sections fine, surfaces arise,
Visualized with care, they dazzle the eyes.
Through math so advanced, they weave and entwine,
Splines of beauty, intricate by design.
🎨✨
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
@coderabbitai generate pytest-file for the sweeping routine
[!TIP] For best results, initiate chat on the files or code changes.
@OberGue, here is the pytest file for the swept
function in splinepy/helpme/create.py
:
import pytest
import numpy as np
from splinepy import BSpline, NURBS
from splinepy.helpme.create import swept
def test_swept_basic_functionality():
cross_section = BSpline(
degrees=[2],
control_points=[[0, 0], [0.5, 1], [1, 0]],
knot_vectors=[[0, 0, 0, 1, 1, 1]]
)
trajectory = BSpline(
degrees=[3],
control_points=[[0, 0], [1, 2], [2, 3], [3, 3]],
knot_vectors=[[0, 0, 0, 0, 1, 1, 1, 1]]
)
result = 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 = BSpline(
degrees=[2],
control_points=[[0, 0], [0.5, 1], [1, 0]],
knot_vectors=[[0, 0, 0, 1, 1, 1]]
)
trajectory = 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 = swept(cross_section, trajectory, cross_section_normal=custom_normal)
assert result is not None
def test_swept_invalid_inputs():
cross_section = 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):
swept(cross_section, invalid_trajectory)
invalid_cross_section = "invalid_cross_section"
trajectory = 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):
swept(invalid_cross_section, trajectory)
def test_swept_rational_splines():
cross_section = 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 = 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 = swept(cross_section, trajectory)
assert result is not None
assert result.is_rational
This test suite includes:
Feel free to run these tests and let me know if any adjustments are needed!
@coderabbitai update the sequence diagram
[!TIP] For best results, initiate chat on the files or code changes.
@OberGue, here is the updated sequence diagram for the swept
function:
sequenceDiagram
participant User
participant SweptFunction as swept()
participant Spline as Spline
participant Numpy as np
participant Log as log
User->>SweptFunction: Call swept(cross_section, trajectory, ...)
SweptFunction->>Spline: Validate cross_section and trajectory
SweptFunction->>Numpy: Set default cross_section_normal if None
SweptFunction->>SweptFunction: Initialize transformation matrices
SweptFunction->>Spline: Calculate tangent vectors and B-vectors
SweptFunction->>SweptFunction: Calculate rotation matrix for cross_section
SweptFunction->>SweptFunction: Perform sweeping process
SweptFunction->>Spline: Handle rational splines if applicable
SweptFunction->>User: Return swept_spline
This diagram captures the key steps and interactions within the swept
function. Let me know if any further adjustments are needed!
Tip
For best results, initiate chat on the files or code changes.
@OberGue, here is the updated sequence diagram for the
swept
function:sequenceDiagram participant User participant SweptFunction as swept() participant Spline as Spline participant Numpy as np participant Log as log User->>SweptFunction: Call swept(cross_section, trajectory, ...) SweptFunction->>Spline: Validate cross_section and trajectory SweptFunction->>Numpy: Set default cross_section_normal if None SweptFunction->>SweptFunction: Initialize transformation matrices SweptFunction->>Spline: Calculate tangent vectors and B-vectors SweptFunction->>SweptFunction: Calculate rotation matrix for cross_section SweptFunction->>SweptFunction: Perform sweeping process SweptFunction->>Spline: Handle rational splines if applicable SweptFunction->>User: Return swept_spline
This diagram captures the key steps and interactions within the
swept
function. Let me know if any further adjustments are needed! Analysis chain Scripts executed
@coderabbitai Please be more superficial. Additionally, I only want the columns "user", "show_swept" and "create-file"
[!TIP] For best results, initiate chat on the files or code changes.
@OberGue, I've simplified the sequence diagram as requested, focusing only on the interactions between the "user", "show_swept", and "create-file" columns:
sequenceDiagram
participant User
participant ShowSwept as show_swept.py
participant CreateFile as create.py
User->>ShowSwept: Call show_swept.py
ShowSwept->>CreateFile: Call swept() from create.py
CreateFile->>ShowSwept: Return swept_spline
ShowSwept->>User: Display results
This diagram now captures the key interactions between the user, the show_swept.py
file, and the create.py
file where the swept
function is defined. Let me know if any further adjustments are needed!
Good progress! If you are done with comments, can you please resolve the conversations? Feel free to leave a note if needed
Overview
swept
is a tool within thesplinepy.helpme.create
environment to provide sweeping a cross section along a trajectory.Addressed issues
Showcase
In order to create a spline patch of a spaghetti pasta, we can pass a circular cross-section and an arbitrary trajectory. The result can be both a 3-dimensional volume spline or a 2-dimensional shell spline, depending on the dimension of your cross-section.
Checklists
Summary by CodeRabbit
New Features
Tests