style: apply cargo fmt across workspace

This commit is contained in:
Karim Jerbi committed 2026-10-11 03:14:29 +01:00
1 parent 85710e5454
commit 9cf9ff2c5c
531 files changed
+57740 -33906

No files matched your search

+66 -61
View File
@@ -1,17 +1,20 @@
use crate::t;
use codec::entities::{BoundaryEdge, Hatch};
use glam::Vec3;
use kernel::geom2d::{
Arc as KernelArc, Curve as KernelCurve, Ellipse as KernelEllipse,
EllipseArc as KernelEllipseArc, Line as KernelLine, NurbsCurve as KernelNurbs,
Parameterization, Polyline as KernelPolyline, PolylineVertex as KernelVertex,
};
use glam::Vec3;
use crate::t;
use crate::command::EntityTransform;
use crate::entities::common::{center_grip, circle_grip, edit_angle_prop as edit_angle, edit_prop as edit, parse_f64, ro_prop as ro};
use crate::entities::common::{
center_grip, circle_grip, edit_angle_prop as edit_angle, edit_prop as edit, parse_f64,
ro_prop as ro,
};
use crate::entities::traits::{FallbackTess, Grippable, PropertyEditable, Transformable};
use crate::scene::model::object::{GripApply, GripDef, PropSection, PropValue, Property};
use crate::scene::convert::tess_util::FallbackGeometry;
use crate::scene::model::object::{GripApply, GripDef, PropSection, PropValue, Property};
use crate::scene::model::wire_model::SnapHint;
/// The area enclosed by the hatch boundary paths.
@@ -122,18 +125,14 @@ pub(crate) fn edge_curve(edge: &BoundaryEdge) -> Option<KernelCurve> {
let weights = s
.rational
.then(|| s.control_points.iter().map(|p| p.z).collect::<Vec<f64>>());
let curve = KernelNurbs::new(
s.degree.max(1) as usize,
control,
s.knots.clone(),
weights,
)
.or_else(|| {
// A fit-point boundary spline, interpolated the same way a
// SPLINE entity's is.
let fit: Vec<[f64; 2]> = s.fit_points.iter().map(|p| [p.x, p.y]).collect();
KernelNurbs::interpolate(&fit, None, None, Parameterization::Chord)
})?;
let curve =
KernelNurbs::new(s.degree.max(1) as usize, control, s.knots.clone(), weights)
.or_else(|| {
// A fit-point boundary spline, interpolated the same way a
// SPLINE entity's is.
let fit: Vec<[f64; 2]> = s.fit_points.iter().map(|p| [p.x, p.y]).collect();
KernelNurbs::interpolate(&fit, None, None, Parameterization::Chord)
})?;
KernelCurve::Nurbs(curve)
}
})
@@ -185,10 +184,7 @@ fn boundary_centroid(h: &Hatch) -> Option<(f64, f64)> {
/// Scale a catalog pattern about its intrinsic coordinate origin.
/// Pattern lines loaded from DXF/DWG are rendered prebaked, so their metadata
/// scale is not applied again by the renderer.
pub(crate) fn scale_pattern_geometry(
pattern: &mut codec::entities::HatchPattern,
factor: f64,
) {
pub(crate) fn scale_pattern_geometry(pattern: &mut codec::entities::HatchPattern, factor: f64) {
let (origin_x, origin_y) = (0.0, 0.0);
for line in pattern.lines.iter_mut() {
line.base_point.x = origin_x + (line.base_point.x - origin_x) * factor;
@@ -203,18 +199,12 @@ pub(crate) fn scale_pattern_geometry(
/// Rotate a catalog pattern about its intrinsic coordinate origin.
/// This keeps the line angle, base point and world-space offset in sync.
pub(crate) fn rotate_pattern_geometry(
pattern: &mut codec::entities::HatchPattern,
angle: f64,
) {
pub(crate) fn rotate_pattern_geometry(pattern: &mut codec::entities::HatchPattern, angle: f64) {
let (sin, cos) = angle.sin_cos();
let (origin_x, origin_y) = (0.0, 0.0);
for line in pattern.lines.iter_mut() {
line.angle += angle;
let (x, y) = (
line.base_point.x - origin_x,
line.base_point.y - origin_y,
);
let (x, y) = (line.base_point.x - origin_x, line.base_point.y - origin_y);
line.base_point.x = origin_x + x * cos - y * sin;
line.base_point.y = origin_y + x * sin + y * cos;
let (x, y) = (line.offset.x, line.offset.y);
@@ -315,11 +305,7 @@ pub fn clear_background_color(h: &mut Hatch) {
}
fn associative_property(h: &Hatch) -> Property {
if h
.paths
.iter()
.any(|path| !path.boundary_handles.is_empty())
{
if h.paths.iter().any(|path| !path.boundary_handles.is_empty()) {
Property {
label: t!("Associative").into_owned(),
field: "associative",
@@ -362,11 +348,18 @@ fn properties(h: &Hatch) -> Vec<PropSection> {
if g.enabled {
// ── Gradient fill ──────────────────────────────────────────────────
let grad_type = if g.is_single_color { "One color" } else { "Two color" };
let (kind, inverted) =
crate::scene::model::hatch_model::GradientKind::from_name(&g.name);
let grad_type = if g.is_single_color {
"One color"
} else {
"Two color"
};
let (kind, inverted) = crate::scene::model::hatch_model::GradientKind::from_name(&g.name);
let mut pattern_props = vec![
ro(t!("Type").as_ref(), "fill_kind", t!("Gradient").into_owned()),
ro(
t!("Type").as_ref(),
"fill_kind",
t!("Gradient").into_owned(),
),
Property {
label: t!("Color mode").into_owned(),
field: "fill_type",
@@ -428,8 +421,16 @@ fn properties(h: &Hatch) -> Vec<PropSection> {
title: t!("Geometry").into_owned(),
props: vec![
edit(t!("Elevation").as_ref(), "elevation", h.elevation),
ro(t!("Area").as_ref(), "area", crate::entities::common::format_area(area)),
ro(t!("Cumulative area").as_ref(), "cumulative_area", crate::entities::common::format_area(area)),
ro(
t!("Area").as_ref(),
"area",
crate::entities::common::format_area(area),
),
ro(
t!("Cumulative area").as_ref(),
"cumulative_area",
crate::entities::common::format_area(area),
),
],
},
PropSection {
@@ -450,7 +451,6 @@ fn properties(h: &Hatch) -> Vec<PropSection> {
];
}
// ── Hatch (pattern / solid) ────────────────────────────────────────────
// Show only controls used by the selected fill type.
let type_row = if h.is_solid {
@@ -537,8 +537,16 @@ fn properties(h: &Hatch) -> Vec<PropSection> {
title: t!("Geometry").into_owned(),
props: vec![
edit(t!("Elevation").as_ref(), "elevation", h.elevation),
ro(t!("Area").as_ref(), "area", crate::entities::common::format_area(area)),
ro(t!("Cumulative area").as_ref(), "cumulative_area", crate::entities::common::format_area(area)),
ro(
t!("Area").as_ref(),
"area",
crate::entities::common::format_area(area),
),
ro(
t!("Cumulative area").as_ref(),
"cumulative_area",
crate::entities::common::format_area(area),
),
],
},
];
@@ -588,11 +596,7 @@ fn apply_geom_prop(h: &mut Hatch, field: &str, value: &str) {
// update from boundary edits. Only enable it when a real
// relationship is available; disabling retains the handles so the
// user can turn it back on later.
if !requested
|| h.paths
.iter()
.any(|path| !path.boundary_handles.is_empty())
{
if !requested || h.paths.iter().any(|path| !path.boundary_handles.is_empty()) {
h.is_associative = requested;
}
return;
@@ -614,9 +618,7 @@ fn apply_geom_prop(h: &mut Hatch, field: &str, value: &str) {
h.pattern = codec::entities::HatchPattern::new("_USER");
}
HatchPatternType::Predefined => {
if let Some(entry) =
crate::scene::model::hatch_patterns::find("ANSI31")
{
if let Some(entry) = crate::scene::model::hatch_patterns::find("ANSI31") {
let mut pattern =
crate::scene::model::hatch_patterns::build_dxf_pattern(entry);
scale_pattern_geometry(&mut pattern, h.pattern_scale);
@@ -769,8 +771,7 @@ impl Grippable for Hatch {
// pattern exists). Dragging it moves the pattern tiling origin; boundary
// grips follow from the next id.
if let Some(l0) = self.pattern.lines.first() {
let (gx, gy) =
boundary_centroid(self).unwrap_or((l0.base_point.x, l0.base_point.y));
let (gx, gy) = boundary_centroid(self).unwrap_or((l0.base_point.x, l0.base_point.y));
out.push(circle_grip(id, glam::DVec3::new(gx, gy, elev)));
id += 1;
} else if self.is_associative {
@@ -982,12 +983,19 @@ impl Grippable for Hatch {
]
}
fn apply_grip_menu(&mut self, grip_id: usize, action: crate::scene::model::object::GripMenuAction) {
fn apply_grip_menu(
&mut self,
grip_id: usize,
action: crate::scene::model::object::GripMenuAction,
) {
use crate::scene::model::object::GripMenuAction as A;
if grip_id == 0 && matches!(action, A::OriginPoint) {
if let (Some((gx, gy)), Some((_ox, _oy))) = (
boundary_centroid(self),
self.pattern.lines.first().map(|line| (line.base_point.x, line.base_point.y)),
self.pattern
.lines
.first()
.map(|line| (line.base_point.x, line.base_point.y)),
) {
self.set_pattern_origin(codec::types::Vector2::new(gx, gy));
}
@@ -1054,8 +1062,7 @@ impl FallbackTess for Hatch {
let Some(curve) = edge_curve(edge) else {
continue;
};
let local = curve
.tessellate_angle(kernel::tessellation::DEFAULT_ANGLE);
let local = curve.tessellate_angle(kernel::tessellation::DEFAULT_ANGLE);
if local.len() < 2 {
continue;
}
@@ -1067,11 +1074,9 @@ impl FallbackTess for Hatch {
.map(|point| to_wcs(point[0], point[1]))
.collect();
match edge {
BoundaryEdge::Polyline(poly) => key_verts.extend(
poly.vertices
.iter()
.map(|point| to_wcs(point.x, point.y)),
),
BoundaryEdge::Polyline(poly) => {
key_verts.extend(poly.vertices.iter().map(|point| to_wcs(point.x, point.y)))
}
_ => key_verts.extend([world[0], *world.last().unwrap()]),
}
match edge {