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

+3 -6
View File
@@ -2,8 +2,8 @@
//!
//! Analytic surfaces remain analytic instead of becoming facets.
use kernel::acis::append;
use codec::entities::acis::{SabReader, SabWriter, SatDocument};
use kernel::acis::append;
use kernel::brep::Body;
/// Returns `None` when the body contains an unsupported record form.
@@ -48,11 +48,8 @@ mod tests {
#[test]
fn a_curved_loft_round_trips_through_text_and_binary_acis() {
let body = kernel::brep::loft(&[
circle_section(0.0, 5.0),
circle_section(10.0, 2.0),
])
.unwrap();
let body =
kernel::brep::loft(&[circle_section(0.0, 5.0), circle_section(10.0, 2.0)]).unwrap();
assert!(body.validate().is_empty());
let mut document = SatDocument::new();
+6 -10
View File
@@ -8,8 +8,8 @@
//!
//! Lift and tessellation failures are reported as an incomplete result.
use kernel::acis::lift;
use codec::entities::acis::SatDocument;
use kernel::acis::lift;
use kernel::brep;
use crate::scene::convert::solid3d_tess::{body_transform, finalize_mesh};
@@ -67,8 +67,7 @@ pub fn tessellate_sat(
.filter_map(|record| {
let owner = record.token_pointer(2)?.0;
let handle = record.token(3)?.as_integer()?;
(owner >= 0 && handle > 0)
.then(|| (owner, codec::Handle::new(handle as u64)))
(owner >= 0 && handle > 0).then(|| (owner, codec::Handle::new(handle as u64)))
})
.collect();
let face_colors: std::collections::HashMap<i32, [f32; 4]> = document
@@ -106,12 +105,10 @@ pub fn tessellate_sat(
DEFAULT_FIT_TOLERANCE
};
for (body, placement_scale) in &bodies {
let mut tolerance = brep::mesh::TessellationTolerance::new(
max_angle,
source_fit * placement_scale,
)
.with_uv_isolines(isolines[0], isolines[1])
.with_planar_isolines(planar_isolines);
let mut tolerance =
brep::mesh::TessellationTolerance::new(max_angle, source_fit * placement_scale)
.with_uv_isolines(isolines[0], isolines[1])
.with_planar_isolines(planar_isolines);
if let Some(deflection) = chordal_deflection {
tolerance = tolerance.with_chordal_deflection(deflection);
}
@@ -252,5 +249,4 @@ mod tests {
let moved = placed([0.0, 0.0, 0.0], quarter_turn());
assert_eq!(moved, [10.0, 20.0, 30.0]);
}
}
+9 -6
View File
@@ -76,8 +76,7 @@ fn walk(doc: &CadDocument, h: Handle, out: &mut Vec<DgnSymbol>, seen: &mut HashS
/// and gaps negative. Empty when the component has no usable stroke lengths.
fn stroke_dashes(doc: &CadDocument, h: Handle) -> Vec<f64> {
use codec::objects::{DgnLineStyleData, DgnLsComponentData, ObjectType};
let Some(ObjectType::DgnLineStyle(style)) = doc.objects.get(&h)
else {
let Some(ObjectType::DgnLineStyle(style)) = doc.objects.get(&h) else {
return Vec::new();
};
let DgnLineStyleData::Component {
@@ -92,8 +91,11 @@ fn stroke_dashes(doc: &CadDocument, h: Handle) -> Vec<f64> {
.iter()
.filter_map(|stroke| {
let length = stroke.length.abs();
(length.is_finite() && length > 0.0)
.then_some(if stroke.is_dash { length } else { -length })
(length.is_finite() && length > 0.0).then_some(if stroke.is_dash {
length
} else {
-length
})
})
.collect()
}
@@ -161,8 +163,9 @@ pub fn symbol_radius(doc: &CadDocument, block: Handle, scale: f64) -> f64 {
distance(circle.center.x, circle.center.y) + circle.radius
}
EntityType::Arc(arc) => distance(arc.center.x, arc.center.y) + arc.radius,
EntityType::Line(line) => distance(line.start.x, line.start.y)
.max(distance(line.end.x, line.end.y)),
EntityType::Line(line) => {
distance(line.start.x, line.start.y).max(distance(line.end.x, line.end.y))
}
_ => crate::scene::convert::tess::entity_world_aabb_f64(&placed)
.map(|[min_x, min_y, max_x, max_y]| {
[
+3 -3
View File
@@ -2,8 +2,8 @@ pub mod acad_to_render;
pub mod acis_export;
pub mod acis_kernel;
pub mod dgn_linestyle;
pub mod tessellate;
pub(crate) mod tess;
pub mod proxy_graphics;
pub mod tess_util;
pub mod solid3d_tess;
pub(crate) mod tess;
pub mod tess_util;
pub mod tessellate;
+19 -8
View File
@@ -100,7 +100,8 @@ fn apply(m: &Xform, p: [f64; 3]) -> [f64; 3] {
}
fn u32_at(b: &[u8], o: usize) -> Option<u32> {
b.get(o..o + 4).map(|s| u32::from_le_bytes([s[0], s[1], s[2], s[3]]))
b.get(o..o + 4)
.map(|s| u32::from_le_bytes([s[0], s[1], s[2], s[3]]))
}
fn f64_at(b: &[u8], o: usize) -> Option<f64> {
@@ -110,7 +111,9 @@ fn f64_at(b: &[u8], o: usize) -> Option<f64> {
fn pt3_at(b: &[u8], o: usize) -> Option<[f64; 3]> {
let p = [f64_at(b, o)?, f64_at(b, o + 8)?, f64_at(b, o + 16)?];
p.iter().all(|v| v.is_finite() && v.abs() < 1e12).then_some(p)
p.iter()
.all(|v| v.is_finite() && v.abs() < 1e12)
.then_some(p)
}
fn color_from_aci(v: i32) -> ProxyColor {
@@ -154,9 +157,13 @@ pub fn decode(blob: &[u8]) -> Decoded {
let mut xform = IDENTITY;
for _ in 0..count {
let Some(rsize) = u32_at(blob, pos) else { break };
let Some(rsize) = u32_at(blob, pos) else {
break;
};
let rsize = rsize as usize;
let Some(rtype) = u32_at(blob, pos + 4) else { break };
let Some(rtype) = u32_at(blob, pos + 4) else {
break;
};
if rsize < 8 || pos + rsize > total {
break;
}
@@ -179,9 +186,7 @@ pub fn decode(blob: &[u8]) -> Decoded {
REC_TRANSFORM => {
// 4×4 row-major; keep the top 3 rows (local→world).
let mut m = IDENTITY;
if (0..12).all(|k| {
f64_at(blob, pos + 8 + 8 * k).map(|v| m[k] = v).is_some()
}) {
if (0..12).all(|k| f64_at(blob, pos + 8 + 8 * k).map(|v| m[k] = v).is_some()) {
xform = m;
}
}
@@ -216,7 +221,13 @@ pub fn decode(blob: &[u8]) -> Decoded {
}
/// Transform a run of local points to world and push it as one poly-line.
fn push_line(out: &mut Decoded, local: Vec<[f64; 3]>, color: ProxyColor, lineweight: i16, xform: &Xform) {
fn push_line(
out: &mut Decoded,
local: Vec<[f64; 3]>,
color: ProxyColor,
lineweight: i16,
xform: &Xform,
) {
if local.len() >= 2 {
out.polylines.push(ProxyPolyline {
points: local.iter().map(|&p| apply(xform, p)).collect(),
+3 -12
View File
@@ -59,9 +59,7 @@ pub(crate) fn body_transform(
}
}
}
(values.len() >= 13
&& values[..13].iter().all(|value| value.is_finite())
&& values[12] > 0.0)
(values.len() >= 13 && values[..13].iter().all(|value| value.is_finite()) && values[12] > 0.0)
.then(|| {
(
[
@@ -170,11 +168,7 @@ pub fn kernel_surface_body(surface: &Surface) -> Option<KernelBody> {
}
pub(crate) fn kernel_acis_body(acis: &codec::entities::AcisData) -> Option<KernelBody> {
let sat = parse_acis(
|| acis.parse(),
acis.is_binary,
&acis.sab_data,
)?;
let sat = parse_acis(|| acis.parse(), acis.is_binary, &acis.sab_data)?;
let (mut bodies, loss) = kernel::acis::lift(&sat);
if !loss.is_empty() || bodies.len() != 1 {
return None;
@@ -183,10 +177,7 @@ pub(crate) fn kernel_acis_body(acis: &codec::entities::AcisData) -> Option<Kerne
bodies.pop()
}
fn remap_acis_material_bindings(
set: &mut MeshLodSet,
acis: &codec::entities::AcisData,
) {
fn remap_acis_material_bindings(set: &mut MeshLodSet, acis: &codec::entities::AcisData) {
for lod in &mut set.lods {
for handle in lod.triangle_material_handles.iter_mut().flatten() {
let reference = handle.value() as i32;
+147 -150
View File
@@ -51,11 +51,8 @@ fn block_object_style(
let entity = EntityType::Insert(insert.clone());
let (color, pattern_length, pattern, line_weight_px, aci) =
view::render::render_style_for_viewport(document, &entity, active_viewport);
let mut layer = view::render::layer_render_style_viewport(
document,
&insert.common.layer,
active_viewport,
);
let mut layer =
view::render::layer_render_style_viewport(document, &insert.common.layer, active_viewport);
layer.color = view::render::adapt_to_bg(layer.color, bg_color);
let layer_aci = document
.layers
@@ -159,11 +156,8 @@ pub(crate) fn expand_block_object(
pick::xclip::clip_wires(&mut wires, &polygon);
for wire in &mut wires {
if let Some(mut instance) = wire.render_instance {
instance.source_id = cache.clip_source_id(
instance.source_id,
&polygon,
instance.translation,
);
instance.source_id =
cache.clip_source_id(instance.source_id, &polygon, instance.translation);
wire.render_instance = Some(instance);
}
}
@@ -658,7 +652,11 @@ fn tessellate_entity_inner(
// footprint doesn't drift when the camera
// crosses the LOD threshold. See #19.
let (entity_color, _, _, _, aci_idx) =
view::render::render_style_for_viewport(document, e, active_viewport);
view::render::render_style_for_viewport(
document,
e,
active_viewport,
);
let entity_color = view::render::adapt_to_bg(entity_color, bg_color);
let entity_color = fade_if_locked(document, e, entity_color, bg_color);
if is_3d_entity {
@@ -777,108 +775,108 @@ fn tessellate_entity_inner(
_ => None,
};
if let Some(blob) = proxy_blob {
let dec = convert::proxy_graphics::decode(blob.as_ref());
if !dec.polylines.is_empty() || !dec.texts.is_empty() {
use crate::scene::convert::proxy_graphics::ProxyColor;
use std::collections::BTreeMap;
let nan = [f64::NAN; 3];
// A specific ACI / RGB overrides the entity colour; ByLayer /
// ByBlock inherit it.
let resolve = |pc: ProxyColor| -> ([f32; 4], u8) {
match pc {
ProxyColor::Aci(a) => (
view::render::adapt_to_bg(
convert::tess_util::aci_to_rgba(&codec::types::Color::Index(a)),
bg_color,
),
a,
let dec = convert::proxy_graphics::decode(blob.as_ref());
if !dec.polylines.is_empty() || !dec.texts.is_empty() {
use crate::scene::convert::proxy_graphics::ProxyColor;
use std::collections::BTreeMap;
let nan = [f64::NAN; 3];
// A specific ACI / RGB overrides the entity colour; ByLayer /
// ByBlock inherit it.
let resolve = |pc: ProxyColor| -> ([f32; 4], u8) {
match pc {
ProxyColor::Aci(a) => (
view::render::adapt_to_bg(
convert::tess_util::aci_to_rgba(&codec::types::Color::Index(a)),
bg_color,
),
ProxyColor::Rgb(r, g, b) => (
{
let [r, g, b] = convert::tess_util::authored_rgb([
r as f32 / 255.0,
g as f32 / 255.0,
b as f32 / 255.0,
]);
[r, g, b, 1.0]
},
0,
),
ProxyColor::Inherit => (entity_color, aci),
}
};
let mut wires = Vec::new();
// Lines / shells: group by (colour, lineweight), one wire each.
let mut groups: BTreeMap<(ProxyColor, i16), Vec<[f64; 3]>> = BTreeMap::new();
for poly in &dec.polylines {
let buf = groups.entry((poly.color, poly.lineweight)).or_default();
if !buf.is_empty() {
buf.push(nan);
}
buf.extend_from_slice(&poly.points);
a,
),
ProxyColor::Rgb(r, g, b) => (
{
let [r, g, b] = convert::tess_util::authored_rgb([
r as f32 / 255.0,
g as f32 / 255.0,
b as f32 / 255.0,
]);
[r, g, b, 1.0]
},
0,
),
ProxyColor::Inherit => (entity_color, aci),
}
for ((pcolor, plw), pts64) in groups {
let (col, w_aci) = resolve(pcolor);
let lw_px = if plw >= 0 {
view::render::lineweight_to_px(&codec::types::LineWeight::Value(plw))
} else {
line_weight_px
};
};
let mut wires = Vec::new();
// Lines / shells: group by (colour, lineweight), one wire each.
let mut groups: BTreeMap<(ProxyColor, i16), Vec<[f64; 3]>> = BTreeMap::new();
for poly in &dec.polylines {
let buf = groups.entry((poly.color, poly.lineweight)).or_default();
if !buf.is_empty() {
buf.push(nan);
}
buf.extend_from_slice(&poly.points);
}
for ((pcolor, plw), pts64) in groups {
let (col, w_aci) = resolve(pcolor);
let lw_px = if plw >= 0 {
view::render::lineweight_to_px(&codec::types::LineWeight::Value(plw))
} else {
line_weight_px
};
let (pts, pts_low) = convert::tessellate::points_to_ds(pts64);
let mut w = WireModel::solid(h.value().to_string(), pts, col, sel);
w.points_low = pts_low;
w.line_weight_px = lw_px;
w.aci = w_aci;
wires.push(w);
}
// Text labels: draw the glyph strokes (simplex.shx etc. are
// single-stroke fonts, so the outline is the character).
for t in &dec.texts {
let font = t
.font
.trim()
.trim_end_matches(".shx")
.trim_end_matches(".SHX");
let font = if font.is_empty() { "standard" } else { font };
let (strokes, _) = crate::scene::text::lff::tessellate_text_ex(
[0.0, 0.0],
t.height as f32,
t.rotation as f32,
1.0,
0.0,
font,
&t.text,
);
let mut pts64: Vec<[f64; 3]> = Vec::new();
for stroke in &strokes {
if stroke.len() < 2 {
continue;
}
if !pts64.is_empty() {
pts64.push(nan);
}
for &[x, y] in stroke {
pts64.push([
t.position[0] + x as f64,
t.position[1] + y as f64,
t.position[2],
]);
}
}
if pts64.len() >= 2 {
let (col, w_aci) = resolve(t.color);
let (pts, pts_low) = convert::tessellate::points_to_ds(pts64);
let mut w = WireModel::solid(h.value().to_string(), pts, col, sel);
w.points_low = pts_low;
w.line_weight_px = lw_px;
w.line_weight_px = line_weight_px;
w.aci = w_aci;
wires.push(w);
}
// Text labels: draw the glyph strokes (simplex.shx etc. are
// single-stroke fonts, so the outline is the character).
for t in &dec.texts {
let font = t
.font
.trim()
.trim_end_matches(".shx")
.trim_end_matches(".SHX");
let font = if font.is_empty() { "standard" } else { font };
let (strokes, _) = crate::scene::text::lff::tessellate_text_ex(
[0.0, 0.0],
t.height as f32,
t.rotation as f32,
1.0,
0.0,
font,
&t.text,
);
let mut pts64: Vec<[f64; 3]> = Vec::new();
for stroke in &strokes {
if stroke.len() < 2 {
continue;
}
if !pts64.is_empty() {
pts64.push(nan);
}
for &[x, y] in stroke {
pts64.push([
t.position[0] + x as f64,
t.position[1] + y as f64,
t.position[2],
]);
}
}
if pts64.len() >= 2 {
let (col, w_aci) = resolve(t.color);
let (pts, pts_low) = convert::tessellate::points_to_ds(pts64);
let mut w = WireModel::solid(h.value().to_string(), pts, col, sel);
w.points_low = pts_low;
w.line_weight_px = line_weight_px;
w.aci = w_aci;
wires.push(w);
}
}
if !wires.is_empty() {
return wires;
}
}
if !wires.is_empty() {
return wires;
}
}
}
// ── Section symbol (AcDbSectionSymbol): draw the "A-A" cut mark ──────────
@@ -961,21 +959,18 @@ fn tessellate_entity_inner(
plinegen: true,
fill_tris: vec![],
fill_tris_low: Vec::new(),
..Default::default()
}];
}];
}
// Render non-annotative dimensions from their stored picture block.
// Rebuild geometry only when no usable block exists.
if matches!(e, EntityType::Dimension(_)) {
if let Some(block_use) = crate::scene::render_graph::entity_render_block_uses(
document,
e,
anno_scale,
)
.into_iter()
.find(|block_use| block_use.active)
if let Some(block_use) =
crate::scene::render_graph::entity_render_block_uses(document, e, anno_scale)
.into_iter()
.find(|block_use| block_use.active)
{
let mut wires = expand_block_object(
document,
@@ -1077,16 +1072,14 @@ fn tessellate_entity_inner(
// When the block exists we render it directly. Same pattern as
// Dimension's `block_name`.
if let EntityType::Table(table) = e {
if let Some(block_use) = crate::scene::render_graph::entity_render_block_uses(
document,
e,
anno_scale,
)
.into_iter()
.find(|block_use| {
block_use.active
&& block_use.role == crate::scene::render_graph::BlockRole::TablePicture
}) {
if let Some(block_use) =
crate::scene::render_graph::entity_render_block_uses(document, e, anno_scale)
.into_iter()
.find(|block_use| {
block_use.active
&& block_use.role == crate::scene::render_graph::BlockRole::TablePicture
})
{
let mut wires = expand_block_object(
document,
&block_use.insert,
@@ -1126,15 +1119,13 @@ fn tessellate_entity_inner(
line_weight_px,
table_anno,
);
for block_use in crate::scene::render_graph::entity_render_block_uses(
document,
e,
table_anno,
)
.into_iter()
.filter(|block_use| {
block_use.role == crate::scene::render_graph::BlockRole::TableCell
}) {
for block_use in
crate::scene::render_graph::entity_render_block_uses(document, e, table_anno)
.into_iter()
.filter(|block_use| {
block_use.role == crate::scene::render_graph::BlockRole::TableCell
})
{
wires.extend(
expand_block_object(
document,
@@ -1209,9 +1200,9 @@ fn tessellate_entity_inner(
plinegen: true,
fill_tris: vec![],
fill_tris_low: Vec::new(),
..Default::default()
};
};
let expanded = expand_block_object(
document,
@@ -1277,8 +1268,8 @@ fn tessellate_entity_inner(
bg_color,
false,
);
let frame_mode = crate::scene::frame::entity_kind(e)
.map(|kind| crate::scene::frame::mode(document, kind));
let frame_mode =
crate::scene::frame::entity_kind(e).map(|kind| crate::scene::frame::mode(document, kind));
for b in &mut bases {
b.aci = aci;
// SDF text wires carry a glyph-bounds AABB (the true text extent) set
@@ -1309,12 +1300,13 @@ fn tessellate_entity_inner(
// Snaps find it; a click on the page does not select the underlay.
wire.snap_only = true;
if let Some((center, radius)) = piece.circle {
wire.tangent_geoms = vec![crate::scene::model::wire_model::TangentGeom::PlanarCircle {
center,
axis_x: [1.0, 0.0, 0.0],
axis_y: [0.0, 1.0, 0.0],
radius,
}];
wire.tangent_geoms =
vec![crate::scene::model::wire_model::TangentGeom::PlanarCircle {
center,
axis_x: [1.0, 0.0, 0.0],
axis_y: [0.0, 1.0, 0.0],
radius,
}];
wire.snap_pts = vec![(
glam::DVec3::from(center),
crate::scene::model::wire_model::SnapHint::Center,
@@ -1327,7 +1319,12 @@ fn tessellate_entity_inner(
}
// DWF / DGN content: vector wires, sharp at every zoom.
if let Some(def) = crate::entities::underlay::definition(underlay, document) {
bases.extend(crate::scene::model::underlay_vector::display_wires(underlay, def, &h.value().to_string(), bg_color));
bases.extend(crate::scene::model::underlay_vector::display_wires(
underlay,
def,
&h.value().to_string(),
bg_color,
));
}
}
@@ -1596,9 +1593,9 @@ fn lod_stub_wire(
plinegen: true,
fill_tris: vec![],
fill_tris_low: Vec::new(),
..Default::default()
}
}
}
/// Sub-pixel LOD stub for 3D entities. Emits the entity's 3D AABB as a
@@ -1693,9 +1690,9 @@ fn lod_stub_wire_3d(
plinegen: true,
fill_tris: vec![],
fill_tris_low: Vec::new(),
..Default::default()
}
}
}
/// Tessellate each visible AttributeEntity attached to an Insert and append
@@ -1798,9 +1795,9 @@ pub(crate) fn entity_bounds(e: &codec::EntityType) -> ([f64; 3], [f64; 3]) {
}
}
if let codec::EntityType::Line(line) = e {
if let Some(association) = codec::entities::CenterMarkAssociation::read(
&line.common.extended_data,
) {
if let Some(association) =
codec::entities::CenterMarkAssociation::read(&line.common.extended_data)
{
return crate::scene::centermark::mark_bounds(&association);
}
}
File diff suppressed because it is too large. Load diff