Skip to content

Commit ce80640

Browse files
claudejf---
authored andcommitted
fix CI: ruff compliance, dep versions, remove rdp
- ruff format entire codebase - fix percent format strings to f-strings - networkx>=3.2, scipy>=1.10, pyclipper>=1.3 for py3.9 compat - remove rdp dep, use CGAL only for polyline simplification
1 parent 08fc0c3 commit ce80640

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+840
-840
lines changed

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ dependencies = [
3535
"networkx>=3.2",
3636
"numpy>=2.0",
3737
"progressbar2>=4.5",
38-
"pyclipper>=1.4",
39-
"rdp>=0.8",
40-
"scipy>=1.16",
38+
"pyclipper>=1.3",
39+
"scipy>=1.10",
4140
"tomli>=2.0; python_version < '3.11'",
4241
]
4342

src/compas_slicer/__main__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import compas_slicer
55

6-
if __name__ == '__main__':
7-
logger.info(f'COMPAS: {compas.__version__}')
8-
logger.info(f'COMPAS Slicer: {compas_slicer.__version__}')
9-
logger.info('Awesome! Your installation worked! :)')
6+
if __name__ == "__main__":
7+
logger.info(f"COMPAS: {compas.__version__}")
8+
logger.info(f"COMPAS Slicer: {compas_slicer.__version__}")
9+
logger.info("Awesome! Your installation worked! :)")

src/compas_slicer/_numpy_ops.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ def face_gradient_from_scalar_field(
143143
cross2 = np.cross(v1 - v0, face_normals) # (F, 3)
144144

145145
# Compute gradient
146-
grad = (
147-
(u1 - u0)[:, np.newaxis] * cross1 + (u2 - u0)[:, np.newaxis] * cross2
148-
) / (2 * face_areas[:, np.newaxis])
146+
grad = ((u1 - u0)[:, np.newaxis] * cross1 + (u2 - u0)[:, np.newaxis] * cross2) / (2 * face_areas[:, np.newaxis])
149147

150148
return grad
151149

@@ -187,9 +185,9 @@ def per_vertex_divergence(
187185
e2 = v0 - v1 # edge opposite to v2
188186

189187
# Compute dot products with gradient
190-
dot0 = np.einsum('ij,ij->i', X, e0) # (F,)
191-
dot1 = np.einsum('ij,ij->i', X, e1) # (F,)
192-
dot2 = np.einsum('ij,ij->i', X, e2) # (F,)
188+
dot0 = np.einsum("ij,ij->i", X, e0) # (F,)
189+
dot1 = np.einsum("ij,ij->i", X, e1) # (F,)
190+
dot2 = np.einsum("ij,ij->i", X, e2) # (F,)
193191

194192
# Cotangent contributions (cotans[f, i] is cotan of angle at vertex i)
195193
# For vertex i: contrib = cotan[k] * dot(X, e_i) + cotan[j] * dot(X, -e_k)

src/compas_slicer/config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,14 @@ class InterpolationConfig(Data):
182182
default_factory=lambda: _interpolation_defaults().get("vertical_layers_max_centroid_dist", 25.0)
183183
)
184184
target_low_geodesics_method: GeodesicsMethod = field(
185-
default_factory=lambda: GeodesicsMethod(_interpolation_defaults().get("target_low_geodesics_method", "heat_igl"))
185+
default_factory=lambda: GeodesicsMethod(
186+
_interpolation_defaults().get("target_low_geodesics_method", "heat_igl")
187+
)
186188
)
187189
target_high_geodesics_method: GeodesicsMethod = field(
188-
default_factory=lambda: GeodesicsMethod(_interpolation_defaults().get("target_high_geodesics_method", "heat_igl"))
190+
default_factory=lambda: GeodesicsMethod(
191+
_interpolation_defaults().get("target_high_geodesics_method", "heat_igl")
192+
)
189193
)
190194
target_high_union_method: UnionMethod = field(
191195
default_factory=lambda: UnionMethod(_interpolation_defaults().get("target_high_union_method", "min"))

src/compas_slicer/geometry/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
from .print_point import * # noqa: F401 E402 F403
66
from .printpoints_collection import * # noqa: F401 E402 F403
77

8-
__all__ = [name for name in dir() if not name.startswith('_')]
8+
__all__ = [name for name in dir() if not name.startswith("_")]

src/compas_slicer/geometry/path.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ def __from_data__(cls, data: dict[str, Any]) -> Path:
4949
points_data = data["points"]
5050
# Handle both list format and legacy dict format
5151
if isinstance(points_data, dict):
52-
pts = [
53-
Point.__from_data__(points_data[key])
54-
for key in sorted(points_data.keys(), key=lambda x: int(x))
55-
]
52+
pts = [Point.__from_data__(points_data[key]) for key in sorted(points_data.keys(), key=lambda x: int(x))]
5653
else:
5754
pts = [Point.__from_data__(p) for p in points_data]
5855
return cls(points=pts, is_closed=data["is_closed"])

src/compas_slicer/post_processing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
from .unify_paths_orientation import * # noqa: F401 E402 F403
2222
from .zig_zag_open_paths import * # noqa: F401 E402 F403
2323

24-
__all__ = [name for name in dir() if not name.startswith('_')]
24+
__all__ = [name for name in dir() if not name.startswith("_")]

src/compas_slicer/post_processing/generate_brim.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
try:
1515
from compas_cgal.straight_skeleton_2 import offset_polygon as _cgal_offset
1616
from compas_cgal.straight_skeleton_2 import offset_polygon_with_holes as _cgal_offset_with_holes
17+
1718
_USE_CGAL = True
1819
except ImportError:
1920
_cgal_offset = None
@@ -23,7 +24,7 @@
2324
from compas_slicer.slicers import BaseSlicer
2425

2526

26-
__all__ = ['generate_brim', 'offset_polygon', 'offset_polygon_with_holes']
27+
__all__ = ["generate_brim", "offset_polygon", "offset_polygon_with_holes"]
2728

2829

2930
def _offset_polygon_cgal(points: list[Point], offset: float, z: float) -> list[Point]:
@@ -83,16 +84,12 @@ def _offset_polygon_pyclipper(points: list[Point], offset: float, z: float) -> l
8384
import pyclipper
8485
from pyclipper import scale_from_clipper, scale_to_clipper
8586

86-
SCALING_FACTOR = 2 ** 32
87+
SCALING_FACTOR = 2**32
8788

8889
xy_coords = [[p[0], p[1]] for p in points]
8990

9091
pco = pyclipper.PyclipperOffset()
91-
pco.AddPath(
92-
scale_to_clipper(xy_coords, SCALING_FACTOR),
93-
pyclipper.JT_MITER,
94-
pyclipper.ET_CLOSEDPOLYGON
95-
)
92+
pco.AddPath(scale_to_clipper(xy_coords, SCALING_FACTOR), pyclipper.JT_MITER, pyclipper.ET_CLOSEDPOLYGON)
9693

9794
result = scale_from_clipper(pco.Execute(offset * SCALING_FACTOR), SCALING_FACTOR)
9895

@@ -132,10 +129,7 @@ def offset_polygon(points: list[Point], offset: float, z: float) -> list[Point]:
132129

133130

134131
def offset_polygon_with_holes(
135-
outer: list[Point],
136-
holes: list[list[Point]],
137-
offset: float,
138-
z: float
132+
outer: list[Point], holes: list[list[Point]], offset: float, z: float
139133
) -> list[tuple[list[Point], list[list[Point]]]]:
140134
"""Offset a polygon with holes using CGAL straight skeleton.
141135
@@ -224,7 +218,7 @@ def generate_brim(slicer: BaseSlicer, layer_width: float, number_of_brim_offsets
224218
has_vertical_layers = False
225219

226220
if len(paths_to_offset) == 0:
227-
raise ValueError('Brim generator did not find any path on the base. Please check the paths of your slicer.')
221+
raise ValueError("Brim generator did not find any path on the base. Please check the paths of your slicer.")
228222

229223
# (2) --- create new empty brim_layer
230224
brim_layer = Layer(paths=[])

src/compas_slicer/post_processing/generate_raft.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
import compas_slicer
77
from compas_slicer.geometry import Layer, Path
88

9-
__all__ = ['generate_raft']
9+
__all__ = ["generate_raft"]
1010

1111

12-
def generate_raft(slicer,
13-
raft_offset=10,
14-
distance_between_paths=10,
15-
direction="xy_diagonal",
16-
raft_layers=1,
17-
raft_layer_height=None):
12+
def generate_raft(
13+
slicer, raft_offset=10, distance_between_paths=10, direction="xy_diagonal", raft_layers=1, raft_layer_height=None
14+
):
1815
"""Creates a raft.
1916
2017
Parameters
@@ -76,7 +73,7 @@ def generate_raft(slicer,
7673

7774
# create starting line for diagonal direction
7875
if direction == "xy_diagonal":
79-
c = math.sqrt(2*(distance_between_paths**2))
76+
c = math.sqrt(2 * (distance_between_paths**2))
8077

8178
pt1 = Point(raft_start_pt[0] + c, raft_start_pt[1], raft_start_pt[2])
8279
pt2 = Point(pt1[0] - y_range, pt1[1] + y_range, pt1[2])
@@ -86,10 +83,9 @@ def generate_raft(slicer,
8683
for i, layer in enumerate(slicer.layers):
8784
for j, path in enumerate(layer.paths):
8885
for k, pt in enumerate(path.points):
89-
slicer.layers[i].paths[j].points[k] = Point(pt[0], pt[1], pt[2] + (raft_layers)*raft_layer_height)
86+
slicer.layers[i].paths[j].points[k] = Point(pt[0], pt[1], pt[2] + (raft_layers) * raft_layer_height)
9087

9188
for i in range(raft_layers):
92-
9389
iter = 0
9490
raft_points = []
9591

@@ -99,8 +95,16 @@ def generate_raft(slicer,
9995
# VERTICAL RAFT
10096
# ===============
10197
if direction == "y_axis":
102-
raft_pt1 = Point(raft_start_pt[0] + iter*distance_between_paths, raft_start_pt[1], raft_start_pt[2] + i*raft_layer_height)
103-
raft_pt2 = Point(raft_start_pt[0] + iter*distance_between_paths, raft_start_pt[1] + y_range, raft_start_pt[2] + i*raft_layer_height)
98+
raft_pt1 = Point(
99+
raft_start_pt[0] + iter * distance_between_paths,
100+
raft_start_pt[1],
101+
raft_start_pt[2] + i * raft_layer_height,
102+
)
103+
raft_pt2 = Point(
104+
raft_start_pt[0] + iter * distance_between_paths,
105+
raft_start_pt[1] + y_range,
106+
raft_start_pt[2] + i * raft_layer_height,
107+
)
104108

105109
if raft_pt2[0] > bb_max_x_right or raft_pt1[0] > bb_max_x_right:
106110
break
@@ -109,8 +113,16 @@ def generate_raft(slicer,
109113
# HORIZONTAL RAFT
110114
# ===============
111115
elif direction == "x_axis":
112-
raft_pt1 = Point(raft_start_pt[0], raft_start_pt[1] + iter*distance_between_paths, raft_start_pt[2] + i*raft_layer_height)
113-
raft_pt2 = Point(raft_start_pt[0] + x_range, raft_start_pt[1] + iter*distance_between_paths, raft_start_pt[2] + i*raft_layer_height)
116+
raft_pt1 = Point(
117+
raft_start_pt[0],
118+
raft_start_pt[1] + iter * distance_between_paths,
119+
raft_start_pt[2] + i * raft_layer_height,
120+
)
121+
raft_pt2 = Point(
122+
raft_start_pt[0] + x_range,
123+
raft_start_pt[1] + iter * distance_between_paths,
124+
raft_start_pt[2] + i * raft_layer_height,
125+
)
114126

115127
if raft_pt2[1] > bb_max_y_top or raft_pt1[1] > bb_max_y_top:
116128
break
@@ -120,21 +132,21 @@ def generate_raft(slicer,
120132
# ===============
121133
elif direction == "xy_diagonal":
122134
# create offset of the initial diagonal line
123-
offset_l = offset_line(line, iter*distance_between_paths, Vector(0, 0, -1))
135+
offset_l = offset_line(line, iter * distance_between_paths, Vector(0, 0, -1))
124136

125137
# get intersections for the initial diagonal line with the left and bottom of the bb
126138
int_left = intersection_line_line(offset_l, [bb_xy_offset[0], bb_xy_offset[3]])
127139
int_bottom = intersection_line_line(offset_l, [bb_xy_offset[0], bb_xy_offset[1]])
128140

129141
# get the points at the intersections
130-
raft_pt1 = Point(int_left[0][0], int_left[0][1], int_left[0][2] + i*raft_layer_height)
131-
raft_pt2 = Point(int_bottom[0][0], int_bottom[0][1], int_bottom[0][2] + i*raft_layer_height)
142+
raft_pt1 = Point(int_left[0][0], int_left[0][1], int_left[0][2] + i * raft_layer_height)
143+
raft_pt2 = Point(int_bottom[0][0], int_bottom[0][1], int_bottom[0][2] + i * raft_layer_height)
132144

133145
# if the intersection goes beyond the height of the left side of the bounding box:
134146
if int_left[0][1] > bb_max_y_top:
135147
# create intersection with the top side
136148
int_top = intersection_line_line(offset_l, [bb_xy_offset[3], bb_xy_offset[2]])
137-
raft_pt1 = Point(int_top[0][0], int_top[0][1], int_top[0][2] + i*raft_layer_height)
149+
raft_pt1 = Point(int_top[0][0], int_top[0][1], int_top[0][2] + i * raft_layer_height)
138150

139151
# if intersection goes beyond the length of the top side, break
140152
if raft_pt1[0] > bb_max_x_right:
@@ -144,7 +156,7 @@ def generate_raft(slicer,
144156
if int_bottom[0][0] > bb_max_x_right:
145157
# create intersection with the right side
146158
int_right = intersection_line_line(offset_l, [bb_xy_offset[1], bb_xy_offset[2]])
147-
raft_pt2 = Point(int_right[0][0], int_right[0][1], int_right[0][2] + i*raft_layer_height)
159+
raft_pt2 = Point(int_right[0][0], int_right[0][1], int_right[0][2] + i * raft_layer_height)
148160

149161
# if intersection goes beyond the height of the right side, break
150162
if raft_pt2[1] > bb_xy_offset[2][1]:

src/compas_slicer/post_processing/infill/medial_axis_infill.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Medial axis based infill generation using CGAL straight skeleton."""
2+
23
from __future__ import annotations
34

45
from typing import TYPE_CHECKING
@@ -64,9 +65,7 @@ def generate_medial_axis_infill(
6465
continue
6566

6667
# Extract skeleton edges as paths
67-
skeleton_paths = _skeleton_to_paths(
68-
graph, z_height, min_length, include_bisectors
69-
)
68+
skeleton_paths = _skeleton_to_paths(graph, z_height, min_length, include_bisectors)
7069
infill_paths.extend(skeleton_paths)
7170

7271
# Add infill paths to layer

0 commit comments

Comments
 (0)