forked from 1b-agent/opencadstudio-upstream
refactor(hatch): collapse repeated reflect_xy_point calls
The Hatch boundary-mirror transform called `crate::scene::transform::reflect_xy_point(&mut x.x, &mut x.y, p1, p2)` nine times with rustfmt expanding each long-path call into a six-line block. Total: ~55 lines for nine reflects. Add a local `use crate::scene::transform::reflect_xy_point as reflect;` at the top of the closure so each reflect collapses to a single line. -19 lines, no behavior change. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
e66905e9b1
commit
2e8d7ba878
1 file changed
+8
-27
+8
-27
@@ -93,6 +93,7 @@ fn apply_geom_prop(h: &mut Hatch, field: &str, value: &str) {
|
||||
}
|
||||
|
||||
fn apply_transform(h: &mut Hatch, t: &EntityTransform) {
|
||||
use crate::scene::transform::reflect_xy_point as reflect;
|
||||
crate::scene::transform::apply_standard_entity_transform(h, t, |entity, p1, p2| {
|
||||
let dx = (p2.x - p1.x) as f64;
|
||||
let dy = (p2.y - p1.y) as f64;
|
||||
@@ -105,37 +106,17 @@ fn apply_transform(h: &mut Hatch, t: &EntityTransform) {
|
||||
for edge in &mut path.edges {
|
||||
match edge {
|
||||
BoundaryEdge::Line(l) => {
|
||||
crate::scene::transform::reflect_xy_point(
|
||||
&mut l.start.x,
|
||||
&mut l.start.y,
|
||||
p1,
|
||||
p2,
|
||||
);
|
||||
crate::scene::transform::reflect_xy_point(
|
||||
&mut l.end.x,
|
||||
&mut l.end.y,
|
||||
p1,
|
||||
p2,
|
||||
);
|
||||
reflect(&mut l.start.x, &mut l.start.y, p1, p2);
|
||||
reflect(&mut l.end.x, &mut l.end.y, p1, p2);
|
||||
}
|
||||
BoundaryEdge::CircularArc(a) => {
|
||||
crate::scene::transform::reflect_xy_point(
|
||||
&mut a.center.x,
|
||||
&mut a.center.y,
|
||||
p1,
|
||||
p2,
|
||||
);
|
||||
reflect(&mut a.center.x, &mut a.center.y, p1, p2);
|
||||
let tmp = a.start_angle;
|
||||
a.start_angle = 2.0 * line_angle - a.end_angle;
|
||||
a.end_angle = 2.0 * line_angle - tmp;
|
||||
}
|
||||
BoundaryEdge::EllipticArc(e) => {
|
||||
crate::scene::transform::reflect_xy_point(
|
||||
&mut e.center.x,
|
||||
&mut e.center.y,
|
||||
p1,
|
||||
p2,
|
||||
);
|
||||
reflect(&mut e.center.x, &mut e.center.y, p1, p2);
|
||||
let ax = dx;
|
||||
let ay = dy;
|
||||
let rx = e.major_axis_endpoint.x;
|
||||
@@ -149,15 +130,15 @@ fn apply_transform(h: &mut Hatch, t: &EntityTransform) {
|
||||
}
|
||||
BoundaryEdge::Spline(s) => {
|
||||
for cp in &mut s.control_points {
|
||||
crate::scene::transform::reflect_xy_point(&mut cp.x, &mut cp.y, p1, p2);
|
||||
reflect(&mut cp.x, &mut cp.y, p1, p2);
|
||||
}
|
||||
for fp in &mut s.fit_points {
|
||||
crate::scene::transform::reflect_xy_point(&mut fp.x, &mut fp.y, p1, p2);
|
||||
reflect(&mut fp.x, &mut fp.y, p1, p2);
|
||||
}
|
||||
}
|
||||
BoundaryEdge::Polyline(p) => {
|
||||
for v in &mut p.vertices {
|
||||
crate::scene::transform::reflect_xy_point(&mut v.x, &mut v.y, p1, p2);
|
||||
reflect(&mut v.x, &mut v.y, p1, p2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user