Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.20
rev: v0.16.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v22.1.5
rev: v22.1.8
hooks:
- id: clang-format
types_or: [c, c++]
Expand All @@ -48,7 +48,7 @@ repos:
- id: cmake-format

- repo: https://github.com/codespell-project/codespell
rev: v2.4.2
rev: v2.4.3
hooks:
- id: codespell
args: [-w]
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"icon_links": [
{
"name": "GitHub",
"url": "https://github.com/tataratat/splinepy",
"url": "https://github.com/isosuite/splinepy",
"icon": "fa-brands fa-square-github",
},
{
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ lint.ignore = [
[tool.ruff.lint.per-file-ignores]
"setup.py" = ["T201"]
"examples/*.py" = ["T201"]
"tests/**" = ["PLR0917"]
"tests/common.py" = ["T201"]
"splinepy/cli.py" = ["T201"]
"splinepy/io/**" = ["A001"]


[tool.codespell]
ignore-words-list = "connec,tye,ned"
skip="./docs/source/_generated/**,./docs/build/*,./build/*,./third_party/*,./tests/data/*.svg,*.html,*.js"
Expand Down
5 changes: 4 additions & 1 deletion splinepy/helpme/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def extruded(spline, extrusion_vector=None):


def revolved(
spline, axis=None, center=None, angle=None, n_knot_spans=None, degree=True
spline, *, axis=None, center=None, angle=None, n_knot_spans=None, degree=True
):
"""Revolve spline around an axis and extend its parametric dimension.

Expand Down Expand Up @@ -284,6 +284,7 @@ def revolved(
def swept(
cross_section,
trajectory,
*,
cross_section_normal=None,
anchor="auto",
set_on_trajectory=False,
Expand Down Expand Up @@ -1153,6 +1154,7 @@ def disk(
def torus(
torus_radius,
section_outer_radius,
*,
section_inner_radius=None,
torus_angle=None,
section_angle=None,
Expand Down Expand Up @@ -1310,6 +1312,7 @@ def surface_circle(outer_radius):
def cone(
outer_radius,
height,
*,
inner_radius=None,
volumetric=True,
angle=360.0,
Expand Down
38 changes: 13 additions & 25 deletions splinepy/helpme/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def parametrize_to_line(reorganized_queries, axis, centripetal):
reorganized = fitting_points[mi._raveled_indices]
parametric_coordinates = []
for k in range(len(size)):
parametric_coordinates.append(
parametrize_to_line(reorganized, k, centripetal)
)
parametric_coordinates.append(parametrize_to_line(reorganized, k, centripetal))

return parametric_coordinates

Expand Down Expand Up @@ -133,9 +131,9 @@ def compute_knot_vector(degree, n_control_points, u_k, n_fitting_points):
for j in range(1, n_control_points - degree):
i = int(j * d)
alpha = (j * d) - i
knot_vector[j + degree] = (1 - alpha) * u_k_flat[
i - 1
] + alpha * u_k_flat[i]
knot_vector[j + degree] = (1 - alpha) * u_k_flat[i - 1] + alpha * u_k_flat[
i
]
return knot_vector


Expand Down Expand Up @@ -181,8 +179,7 @@ def solve_for_control_points(
if fitting_spline.control_points.shape[0] == 2:
# control points equal to endpoints (straight line)
residual = _np.linalg.norm(
coefficient_matrix @ fitting_spline.control_points
- fitting_points
coefficient_matrix @ fitting_spline.control_points - fitting_points
)
elif _has_scipy:
# move known values to RHS
Expand Down Expand Up @@ -236,9 +233,7 @@ def _validate_specifications(n_query, degree, n_control_points, knot_vector):
if degree is not None and knot_vector is not None:
expected_ncps = len(knot_vector) - degree - 1
if n_control_points is not None and n_control_points != expected_ncps:
_log.error(
f"n_control_points should be {expected_ncps}. Overwriting."
)
_log.error(f"n_control_points should be {expected_ncps}. Overwriting.")

n_control_points = expected_ncps

Expand All @@ -251,9 +246,7 @@ def _validate_specifications(n_query, degree, n_control_points, knot_vector):

# we need degree
if degree is None:
raise ValueError(
"Not enough input to determine degree. Please set degree."
)
raise ValueError("Not enough input to determine degree. Please set degree.")

# no n_control point -> same as query and this will be interpolation
if n_control_points is None:
Expand All @@ -277,7 +270,7 @@ def _validate_specifications(n_query, degree, n_control_points, knot_vector):
return degree, n_control_points


def _prepare_default_bspline1pd(
def _prepare_default_bspline1pd( # noqa: PLR0917
n_queries, dim, degree, n_control_points, knot_vector, u_k
):
# validate values. may raise if there's conflict.
Expand All @@ -304,6 +297,7 @@ def _prepare_default_bspline1pd(

def curve(
fitting_points,
*,
degree=None,
n_control_points=None,
knot_vector=None,
Expand Down Expand Up @@ -368,9 +362,7 @@ def curve(
if fitting_spline is not None:
# spline dimension check
if fitting_spline.para_dim != 1:
raise ValueError(
"parametric dimension of fitting_spline must be 1!"
)
raise ValueError("parametric dimension of fitting_spline must be 1!")

# some values maybe ignored.
_log.debug(
Expand Down Expand Up @@ -411,6 +403,7 @@ def curve(
def surface(
fitting_points,
size,
*,
degrees=None,
n_control_points=None,
knot_vectors=None,
Expand Down Expand Up @@ -465,10 +458,7 @@ def surface(
knot_vectors is not None or fitting_spline is not None
):
# check dimensions of queries
if (
associated_queries[0].shape[1] != 1
or associated_queries[1].shape[1] != 1
):
if associated_queries[0].shape[1] != 1 or associated_queries[1].shape[1] != 1:
raise ValueError(
"Associated queries in each direction must have dimension 1!"
)
Expand Down Expand Up @@ -548,9 +538,7 @@ def surface(
interpolate_endpoints=interpolate_endpoints,
)
# cps in u direction (later fitted in v direction)
interim_control_points[mi_interim_cps[:, v]] = (
fitted_spline_u.control_points
)
interim_control_points[mi_interim_cps[:, v]] = fitted_spline_u.control_points

# loop second dim
# curve fit for every k in n_control_points_u
Expand Down
43 changes: 11 additions & 32 deletions splinepy/io/cats.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,20 @@ def load(fname):
def _read_spline(xml_element):
spline_dict = {}
if not xml_element.tag.startswith(CATS_XML_KEY_WORDS["patch"]):
_debug(
f"Found unexpected keyword {xml_element.tag}, which will be "
f"ignored"
)
_debug(f"Found unexpected keyword {xml_element.tag}, which will be ignored")
# Read required information from Header in xml element

dim = int(xml_element.attrib.get(CATS_XML_KEY_WORDS["dim"], -1))
para_dim = int(
xml_element.attrib.get(CATS_XML_KEY_WORDS["para_dim"], -1)
)
ctps_dim = int(
xml_element.attrib.get(CATS_XML_KEY_WORDS["field_dim"], -1)
)
para_dim = int(xml_element.attrib.get(CATS_XML_KEY_WORDS["para_dim"], -1))
ctps_dim = int(xml_element.attrib.get(CATS_XML_KEY_WORDS["field_dim"], -1))
n_ctps = int(xml_element.attrib.get(CATS_XML_KEY_WORDS["n_ctps"], -1))
periodic_keys = xml_element.attrib.get(
CATS_XML_KEY_WORDS["periodic"], ""
).split()
any_is_periodic = any(int(key) == 1 for key in periodic_keys)
if -1 in [dim, para_dim, ctps_dim, n_ctps]:
raise ValueError(
f"Not enough information provided for xml-element "
f"{xml_element}"
f"Not enough information provided for xml-element {xml_element}"
)
if ctps_dim > dim:
_debug(
Expand Down Expand Up @@ -129,9 +121,7 @@ def _read_spline(xml_element):
if CATS_XML_KEY_WORDS["knot_vector"] not in child_info.tag:
_debug("Redundant item in knot_vectors block of xml")
spline_dict["knot_vectors"].append(
_np.fromstring(
child_info.text.replace("\n", " "), sep=" "
)
_np.fromstring(child_info.text.replace("\n", " "), sep=" ")
)

# All other keywords will be ignored for the moment
Expand All @@ -148,8 +138,7 @@ def _read_spline(xml_element):
if root.tag.startswith(CATS_XML_KEY_WORDS["spline_list"]):
if root.attrib.get(CATS_XML_KEY_WORDS["spline_type"], "1") != "1":
raise ValueError(
f"Unknown SplineType "
f"{root.attrib[CATS_XML_KEY_WORDS['spline_type']]}"
f"Unknown SplineType {root.attrib[CATS_XML_KEY_WORDS['spline_type']]}"
)
n_patches = int(root.attrib.get(CATS_XML_KEY_WORDS["n_patches"], 0))
for patch_element in root:
Expand All @@ -158,7 +147,7 @@ def _read_spline(xml_element):
_debug(f"Unused xml-keyword {root.tag}")
return []

_debug(f"Found a total of {len(list_of_splines)} " f"BSplines and NURBS")
_debug(f"Found a total of {len(list_of_splines)} BSplines and NURBS")
if len(list_of_splines) != n_patches:
raise ValueError(
f"Found {len(list_of_splines)} splines, but expected to find "
Expand Down Expand Up @@ -204,9 +193,7 @@ def export(fname, spline_list, indent=True, make_rational=True):
spline_list = spline_list.patches

if not isinstance(spline_list, list):
raise ValueError(
"export Function expects list for multipatch argument"
)
raise ValueError("export Function expects list for multipatch argument")

# Start a list of a list of patches
spline_list_element = _ET.Element(
Expand All @@ -218,21 +205,15 @@ def export(fname, spline_list, indent=True, make_rational=True):
# licked it so its ours
spline_list_element.insert(
1,
_ET.Comment(
"generated by splinepy https://github.com/tataratat/splinepy"
),
_ET.Comment("generated by splinepy https://github.com/isosuite/splinepy"),
)

new_line_char = "\n" if indent else " "

# All Splines (patches) are written into the spline list as entries
for spline in spline_list:
# Convert to non-bezier type (might make unnecessary copy)
patch = (
spline.nurbs
if spline.is_rational or make_rational
else spline.bspline
)
patch = spline.nurbs if spline.is_rational or make_rational else spline.bspline

# Write spline header
patch_element = _ET.SubElement(
Expand Down Expand Up @@ -281,9 +262,7 @@ def export(fname, spline_list, indent=True, make_rational=True):
patch_element,
CATS_XML_KEY_WORDS["degrees"],
)
degrees_elements.text = new_line_char.join(
str(deg) for deg in patch.degrees
)
degrees_elements.text = new_line_char.join(str(deg) for deg in patch.degrees)

# knot-vectors
knot_vectors_elements = _ET.SubElement(
Expand Down
Loading
Loading