diff --git a/src/entities/common.rs b/src/entities/common.rs index 136af184e..bdc2544db 100644 --- a/src/entities/common.rs +++ b/src/entities/common.rs @@ -818,6 +818,9 @@ pub(crate) fn triangulate_band_ring(ring: &[[f64; 3]]) -> Vec<[f64; 3]> { } pub(crate) fn wide_band_tris(origin: [f64; 2], fills: &[Vec<[f32; 2]>]) -> Vec<[f64; 3]> { + if fills.is_empty() { + return Vec::new(); + } let mut total_verts = 0; for poly in fills { let n = poly.len(); @@ -925,8 +928,8 @@ pub(crate) fn tapered_band_points( ) -> (Vec<[f64; 3]>, Vec) { let n = verts.len(); let seg_count = if is_closed { n } else { n.saturating_sub(1) }; - let mut pts: Vec<[f64; 3]> = Vec::new(); - let mut widths: Vec = Vec::new(); + let mut pts: Vec<[f64; 3]> = Vec::with_capacity(seg_count + 1); + let mut widths: Vec = Vec::with_capacity(seg_count + 1); let mut push = |x: f64, y: f64, w: f32| { let (wx, wy, wz) = to_wcs(x, y); pts.push([wx, wy, wz]); diff --git a/src/entities/lwpolyline.rs b/src/entities/lwpolyline.rs index f1fe5ac84..2649321d4 100644 --- a/src/entities/lwpolyline.rs +++ b/src/entities/lwpolyline.rs @@ -1582,6 +1582,11 @@ pub(crate) fn wide_fills(pl: &acadrust::entities::LwPolyline) -> ([f64; 2], Vec< if n < 2 { return ([0.0; 2], vec![]); } + let is_wide = pl.constant_width > 1e-9 + || verts.iter().any(|v| v.start_width > 1e-9 || v.end_width > 1e-9); + if !is_wide { + return ([0.0; 2], Vec::new()); + } let origin = [verts[0].location.x, verts[0].location.y]; let seg_count = if pl.is_closed { n } else { n - 1 }; let mut out = Vec::new(); diff --git a/src/scene/convert/tessellate.rs b/src/scene/convert/tessellate.rs index 485b192e9..75b7cf647 100644 --- a/src/scene/convert/tessellate.rs +++ b/src/scene/convert/tessellate.rs @@ -186,6 +186,9 @@ pub(crate) fn points_to_ds( let it = src.into_iter(); let (lo, hi) = it.size_hint(); let cap = hi.unwrap_or(lo); + if cap == 0 { + return (Vec::new(), Vec::new()); + } let mut high = Vec::with_capacity(cap); let mut low = Vec::with_capacity(cap); for [x, y, z] in it { @@ -327,9 +330,10 @@ fn split_mixed_polyline( (sw, ew) }; - let mut arc_pts = Vec::with_capacity(17); - let mut arc_widths = Vec::with_capacity(17); let n = 16; + let mut points = Vec::with_capacity(n + 1); + let mut points_low = Vec::with_capacity(n + 1); + let mut arc_widths = Vec::with_capacity(n + 1); let sweep = if end_angle >= start_angle { end_angle - start_angle } else { @@ -338,15 +342,15 @@ fn split_mixed_polyline( for s in 0..=n { let frac = s as f64 / n as f64; let ang = start_angle + frac * sweep; - let p = [ - center[0] + radius * (ang.cos() * axis_x[0] + ang.sin() * axis_y[0]), - center[1] + radius * (ang.cos() * axis_x[1] + ang.sin() * axis_y[1]), - center[2] + radius * (ang.cos() * axis_x[2] + ang.sin() * axis_y[2]), - ]; - arc_pts.push(p); + let (sin_a, cos_a) = ang.sin_cos(); + let x = center[0] + radius * (cos_a * axis_x[0] + sin_a * axis_y[0]); + let y = center[1] + radius * (cos_a * axis_x[1] + sin_a * axis_y[1]); + let z = center[2] + radius * (cos_a * axis_x[2] + sin_a * axis_y[2]); + let (h, l) = split_ds_xyz(x, y, z); + points.push(h); + points_low.push(l); arc_widths.push(w_at_sa + (w_at_ea - w_at_sa) * frac as f32); } - let (points, points_low) = points_to_ds(arc_pts); let taper_widths = if (w_at_sa - w_at_ea).abs() > 1e-6 { arc_widths