Skip to content

Commit 42976f4

Browse files
committed
autoformat
1 parent 2e0333e commit 42976f4

3 files changed

Lines changed: 57 additions & 40 deletions

File tree

rayforge/image/lightburn/importer.py

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ def _parse_xform(text: str) -> Matrix:
6868
except ValueError:
6969
logger.warning("Invalid XForm values: %s, using identity", text)
7070
return Matrix()
71-
return Matrix([
72-
[a, c, tx],
73-
[b, d, ty],
74-
[0, 0, 1],
75-
])
71+
return Matrix(
72+
[
73+
[a, c, tx],
74+
[b, d, ty],
75+
[0, 0, 1],
76+
]
77+
)
7678

7779

7880
def _parse_verts(text: str) -> List[Dict[str, float]]:
@@ -114,9 +116,7 @@ def _apply_xform_to_geo(geo: Geometry, xform: Matrix) -> Geometry:
114116
return geo
115117

116118

117-
def _build_rect(
118-
w: float, h: float, cr: float
119-
) -> Geometry:
119+
def _build_rect(w: float, h: float, cr: float) -> Geometry:
120120
geo = Geometry()
121121
if w <= 0 or h <= 0:
122122
return geo
@@ -223,8 +223,12 @@ def _build_path_from_verts_and_prims(
223223
c0y = sv.get("c0y")
224224
c1x = ev.get("c1x")
225225
c1y = ev.get("c1y")
226-
if (c0x is not None and c0y is not None
227-
and c1x is not None and c1y is not None):
226+
if (
227+
c0x is not None
228+
and c0y is not None
229+
and c1x is not None
230+
and c1y is not None
231+
):
228232
geo.bezier_to(ex, ey, c0x, c0y, c1x, c1y)
229233
else:
230234
geo.line_to(ex, ey)
@@ -303,9 +307,7 @@ def _shape_to_geometry(
303307
else ""
304308
)
305309
prims = _parse_prims(prim_list_raw)
306-
geo = _build_path_from_verts_and_prims(
307-
verts, prims, prim_list_raw
308-
)
310+
geo = _build_path_from_verts_and_prims(verts, prims, prim_list_raw)
309311

310312
elif shape_type == "Text":
311313
has_backup = shape_elem.get("HasBackupPath", "0") == "1"
@@ -317,9 +319,7 @@ def _shape_to_geometry(
317319
if children_elem is not None:
318320
combined = Geometry()
319321
for child in children_elem.findall("Shape"):
320-
child_result = _shape_to_geometry(
321-
child, cut_settings, bitmaps
322-
)
322+
child_result = _shape_to_geometry(child, cut_settings, bitmaps)
323323
if child_result is not None:
324324
child_cut_idx, child_geo = child_result
325325
child_geo = _apply_xform_to_geo(child_geo, xform)
@@ -339,13 +339,15 @@ def _shape_to_geometry(
339339
logger.warning("Failed to decode Bitmap data")
340340
return None
341341
if bitmaps is not None:
342-
bitmaps.append(BitmapInfo(
343-
cut_index=cut_index,
344-
xform=xform,
345-
width=w,
346-
height=h,
347-
png_data=png_bytes,
348-
))
342+
bitmaps.append(
343+
BitmapInfo(
344+
cut_index=cut_index,
345+
xform=xform,
346+
width=w,
347+
height=h,
348+
png_data=png_bytes,
349+
)
350+
)
349351
geo = _build_rect(w, h, cr=0)
350352
else:
351353
return None
@@ -414,9 +416,8 @@ def _parse_cut_settings(
414416
self, project: ET.Element
415417
) -> Dict[int, Dict[str, Any]]:
416418
cut_settings: Dict[int, Dict[str, Any]] = {}
417-
for cs_elem in (
418-
list(project.findall("CutSetting"))
419-
+ list(project.findall("CutSetting_Img"))
419+
for cs_elem in list(project.findall("CutSetting")) + list(
420+
project.findall("CutSetting_Img")
420421
):
421422
index_el = cs_elem.find("index")
422423
if index_el is None:
@@ -452,9 +453,12 @@ def _render_bitmaps_to_svg(self) -> Optional[bytes]:
452453
for bm in self._bitmaps:
453454
hw, hh = bm.width / 2.0, bm.height / 2.0
454455
a, b, c, d, tx, ty = (
455-
bm.xform.m[0, 0], bm.xform.m[1, 0],
456-
bm.xform.m[0, 1], bm.xform.m[1, 1],
457-
bm.xform.m[0, 2], bm.xform.m[1, 2],
456+
bm.xform.m[0, 0],
457+
bm.xform.m[1, 0],
458+
bm.xform.m[0, 1],
459+
bm.xform.m[1, 1],
460+
bm.xform.m[0, 2],
461+
bm.xform.m[1, 2],
458462
)
459463
data_url = "data:image/png;base64," + base64.b64encode(
460464
bm.png_data
@@ -608,9 +612,9 @@ def vectorize(
608612
merged_geo.extend(geo)
609613

610614
if split_layers:
611-
final_geometries: Dict[Optional[str], Geometry] = (
612-
geometries or {None: merged_geo}
613-
)
615+
final_geometries: Dict[Optional[str], Geometry] = geometries or {
616+
None: merged_geo
617+
}
614618
else:
615619
final_geometries = {None: merged_geo}
616620

rayforge/image/lightburn/renderer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ def render_base_image(
7171

7272
boundaries = kwargs.get("boundaries")
7373
if not boundaries or boundaries.is_empty():
74-
logger.warning(
75-
"LightBurnRenderer: No boundaries or SVG data."
76-
)
74+
logger.warning("LightBurnRenderer: No boundaries or SVG data.")
7775
return None
7876

7977
surface = OPS_RENDERER._render_to_cairo_surface(

tests/image/lightburn/test_lightburn_importer.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,31 @@ def test_single_vert_lineclosed(self):
204204

205205
def test_bezier(self):
206206
verts: List[Dict[str, float]] = [
207-
{"x": 0.0, "y": 0.0, "c0x": 10.0, "c0y": 0.0,
208-
"c1x": 10.0, "c1y": 0.0},
209-
{"x": 20.0, "y": 0.0, "c1x": 20.0, "c1y": 10.0,
210-
"c0x": 20.0, "c0y": 10.0},
207+
{
208+
"x": 0.0,
209+
"y": 0.0,
210+
"c0x": 10.0,
211+
"c0y": 0.0,
212+
"c1x": 10.0,
213+
"c1y": 0.0,
214+
},
215+
{
216+
"x": 20.0,
217+
"y": 0.0,
218+
"c1x": 20.0,
219+
"c1y": 10.0,
220+
"c0x": 20.0,
221+
"c0y": 10.0,
222+
},
211223
]
212224
prims = [("B", 0, 1)]
213225
geo = _build_path_from_verts_and_prims(verts, prims, "B 0 1")
214226
assert not geo.is_empty()
215227

216228
def test_bezier_missing_controls_falls_back_to_line(self):
217229
verts: List[Dict[str, float]] = [
218-
{"x": 0.0, "y": 0.0}, {"x": 10.0, "y": 10.0}
230+
{"x": 0.0, "y": 0.0},
231+
{"x": 10.0, "y": 10.0},
219232
]
220233
prims = [("B", 0, 1)]
221234
geo = _build_path_from_verts_and_prims(verts, prims, "B 0 1")
@@ -295,6 +308,7 @@ def test_vectorize_returns_vectorization_result(self):
295308
parse_result = importer.parse()
296309
assert parse_result is not None
297310
from rayforge.core.vectorization_spec import PassthroughSpec
311+
298312
vec_result = importer.vectorize(parse_result, PassthroughSpec())
299313
assert isinstance(vec_result, VectorizationResult)
300314
assert len(vec_result.geometries_by_layer) > 0
@@ -339,6 +353,7 @@ def test_group_shape(self):
339353

340354
def test_extension_registration(self):
341355
from rayforge.image.registry import importer_registry
356+
342357
importer_cls = importer_registry.get_by_extension(".lbrn2")
343358
assert importer_cls is not None
344359
assert importer_cls is LightBurnImporter

0 commit comments

Comments
 (0)