2026-03-22 14:56:27 +03:00
|
|
|
|
use acadrust::entities::{LwPolyline, LwVertex};
|
|
|
|
|
|
use glam::Vec3;
|
|
|
|
|
|
use truck_modeling::{builder, Edge, Point3, Wire};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::command::EntityTransform;
|
2026-05-12 10:36:15 +03:00
|
|
|
|
use crate::entities::common::{
|
refactor(grip): square-only marker set + oriented stretch handles
Phase 1 of bringing the grip vocabulary in line with the standard
CAD convention: drop the per-position-type shape encoding (Diamond
for translate, Circle for parameter) and use a plain square for
every endpoint / vertex / centre grip. The behavioural midpoint vs
vertex distinction stays — it lives on `GripDef::is_midpoint` and
drives `Translate` vs `Absolute` in the grip-edit dispatcher — only
the marker shape collapses.
- `GripShape` keeps `Square`, `Rectangle`, `Triangle`. Diamond /
Circle are gone.
- `GripDef` gains `dir: Option<[f32; 2]>` — a world-XY direction
vector consumed by `Rectangle` to orient the box along its
segment.
- `entities::common` exposes `square_grip`, `center_grip` (same
square marker, flagged as translate), `rectangle_grip(id, world,
dir)` for oriented mid-segment handles, and a kept-for-Phase-2
`triangle_grip`.
- `overlay::GripMarker` / `grips_to_screen[_paper]` thread `dir`
through to the canvas painter; the Rectangle path rotates the
box around the grip centre using the world-XY direction (flipping
the sin for screen-Y).
Every existing `diamond_grip(id, w)` call becomes `center_grip(id,
w)` — the visual change is square-replacing-diamond at line
midpoints / arc midpoints / circle centres / ellipse centres /
viewport / hatch loop centroids / dimension grips / image corners /
multileader / ray / underlay / ole2frame / solid3d.
`LwPolyline` grows a stretch handle on every segment (straight or
arc), drawn as the new oriented rectangle. The grip-edit path
translates both segment endpoints for straight segments and
adjusts the arc bulge from the new midpoint for arc segments.
2026-05-29 02:07:34 +03:00
|
|
|
|
edit_prop as edit, parse_f64, rectangle_grip, ro_prop as ro, square_grip,
|
2026-05-12 10:36:15 +03:00
|
|
|
|
};
|
refactor(entities): collapse trait wrapper boilerplate via macro
Every entity file ended with the same three-trait wrapper block:
impl Grippable for T {
fn grips(&self) -> Vec<GripDef> { grips(self) }
fn apply_grip(&mut self, ...) { apply_grip(self, ...) }
}
impl PropertyEditable for T { ... }
impl Transformable for T { ... }
— 23 lines of pure delegation around five same-named free functions.
Replace with `crate::impl_entity_basics!(T);` (a macro in
entities/traits.rs that expands to the three trait impls).
Applied where the file already follows the free-fn delegation
convention (Arc, Circle, Ellipse, Insert, Leader, Line, LwPolyline,
MultiLeader, Ole2Frame, Point, Spline, Viewport). Files that inlined
the trait method bodies directly (Ray, XLine, Shape, Solid, Tolerance,
MLine, Mesh, Solid3D/Region/Body, Table, RasterImage, Wipeout,
Underlay, Hatch, Polyline, Polyline2D, Polyline3D, Dimension) left
alone — they already skip the indirection. Text/MText/Attribute use
the with-text-style flavour and will move once that variant is needed
beyond the existing two manual impls.
A second macro `impl_entity_basics_with_text_styles!` is included for
the text-like flavour but no entity uses it yet.
Net: -204 lines.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 17:16:06 +03:00
|
|
|
|
use crate::entities::traits::{TruckConvertible};
|
2026-03-22 14:56:27 +03:00
|
|
|
|
use crate::scene::acad_to_truck::{TruckEntity, TruckObject};
|
|
|
|
|
|
use crate::scene::object::{GripApply, GripDef, PropSection};
|
|
|
|
|
|
use crate::scene::wire_model::TangentGeom;
|
|
|
|
|
|
|
|
|
|
|
|
const TAU: f64 = std::f64::consts::TAU;
|
|
|
|
|
|
|
2026-04-27 02:22:51 +03:00
|
|
|
|
/// Midpoint position on an arc segment defined by its bulge.
|
|
|
|
|
|
fn arc_midpoint(p0: [f64; 2], p1: [f64; 2], bulge: f64) -> [f64; 2] {
|
refactor(common): unify bulge → arc math into BulgeArc
The same DXF/DWG bulge → (center, radius, sweep) formula was inlined
in six places (hatch outline, polyline tess + truck path, lwpolyline
×4, scene hatch fill, explode bulge_to_arc) — each with subtly
different sweep-direction handling for the bulge sign.
Add `entities::common::BulgeArc { center, radius, start_angle,
end_angle, sweep }` with one `from_bulge(p0, p1, bulge)` constructor
and a `sample(t)` helper. Callsites collapse to a few lines.
Net: -121 lines, one canonical sweep-direction convention shared by
all consumers.
array.rs (the path-along-curve f32 helper) keeps its inline math —
its sign convention is inverted relative to the others and changing
it without exercising the array-path command risks regressing the
output.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:42:26 +03:00
|
|
|
|
match crate::entities::common::BulgeArc::from_bulge(p0, p1, bulge) {
|
|
|
|
|
|
Some(arc) => arc.sample(0.5),
|
|
|
|
|
|
None => [(p0[0] + p1[0]) * 0.5, (p0[1] + p1[1]) * 0.5],
|
2026-04-27 02:22:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Compute the DXF bulge for an arc that passes through p0, mid_pt, and p1.
|
|
|
|
|
|
/// Returns None when the three points are collinear (straight segment).
|
|
|
|
|
|
fn bulge_from_midpoint(p0: [f64; 2], p1: [f64; 2], mid: [f64; 2]) -> Option<f64> {
|
|
|
|
|
|
// Circumcircle of (p0, mid, p1)
|
|
|
|
|
|
let ax = 2.0 * (mid[0] - p0[0]);
|
|
|
|
|
|
let ay = 2.0 * (mid[1] - p0[1]);
|
|
|
|
|
|
let bx = 2.0 * (p1[0] - p0[0]);
|
|
|
|
|
|
let by = 2.0 * (p1[1] - p0[1]);
|
|
|
|
|
|
let ca = mid[0] * mid[0] + mid[1] * mid[1] - p0[0] * p0[0] - p0[1] * p0[1];
|
|
|
|
|
|
let cb = p1[0] * p1[0] + p1[1] * p1[1] - p0[0] * p0[0] - p0[1] * p0[1];
|
|
|
|
|
|
let det = ax * by - ay * bx;
|
|
|
|
|
|
if det.abs() < 1e-12 {
|
|
|
|
|
|
return None; // collinear
|
|
|
|
|
|
}
|
|
|
|
|
|
let cx = (ca * by - cb * ay) / det;
|
|
|
|
|
|
let cy = (ax * cb - bx * ca) / det;
|
|
|
|
|
|
let a0 = (p0[1] - cy).atan2(p0[0] - cx);
|
|
|
|
|
|
let a1 = (p1[1] - cy).atan2(p1[0] - cx);
|
|
|
|
|
|
// Determine arc direction: cross product (p1-p0) × (mid-p0)
|
|
|
|
|
|
let cross = (p1[0] - p0[0]) * (mid[1] - p0[1]) - (p1[1] - p0[1]) * (mid[0] - p0[0]);
|
|
|
|
|
|
let (sa, mut ea) = if cross > 0.0 { (a0, a1) } else { (a1, a0) };
|
2026-05-12 10:36:15 +03:00
|
|
|
|
if ea < sa {
|
|
|
|
|
|
ea += TAU;
|
|
|
|
|
|
}
|
2026-04-27 02:22:51 +03:00
|
|
|
|
let span = ea - sa; // central angle in (0, TAU]
|
|
|
|
|
|
let bulge = (span / 4.0).tan();
|
|
|
|
|
|
Some(if cross >= 0.0 { bulge } else { -bulge })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-05 20:03:57 +03:00
|
|
|
|
/// Tessellate a thick polyline segment list into NaN-separated Lines geometry.
|
|
|
|
|
|
/// Shared by LwPolyline and Polyline2D thickness paths.
|
|
|
|
|
|
fn thick_segments(
|
|
|
|
|
|
seg_data: &[(f64, f64, f64, f64)], // (x0, y0, x1, y1) per seg — or use run of (x,y,bulge)
|
2026-05-12 23:47:40 +03:00
|
|
|
|
path_pts: &[[f64; 3]],
|
2026-05-05 20:03:57 +03:00
|
|
|
|
thickness: f64,
|
|
|
|
|
|
normal: (f64, f64, f64),
|
2026-05-12 23:47:40 +03:00
|
|
|
|
key_verts: Vec<[f64; 3]>,
|
2026-05-05 20:03:57 +03:00
|
|
|
|
tangents: Vec<TangentGeom>,
|
|
|
|
|
|
) -> TruckEntity {
|
|
|
|
|
|
let (nx, ny, nz) = normal;
|
|
|
|
|
|
let t = thickness;
|
2026-05-12 23:47:40 +03:00
|
|
|
|
let off = |p: [f64; 3]| -> [f64; 3] {
|
|
|
|
|
|
[p[0] + t * nx, p[1] + t * ny, p[2] + t * nz]
|
2026-05-05 20:03:57 +03:00
|
|
|
|
};
|
2026-05-12 23:47:40 +03:00
|
|
|
|
let mut pts: Vec<[f64; 3]> = Vec::with_capacity(path_pts.len() * 2 + seg_data.len() * 3 + 4);
|
2026-05-05 20:03:57 +03:00
|
|
|
|
// Bottom path
|
|
|
|
|
|
pts.extend_from_slice(path_pts);
|
2026-05-12 23:47:40 +03:00
|
|
|
|
pts.push([f64::NAN; 3]);
|
2026-05-05 20:03:57 +03:00
|
|
|
|
// Top path
|
|
|
|
|
|
for &p in path_pts {
|
|
|
|
|
|
pts.push(off(p));
|
|
|
|
|
|
}
|
|
|
|
|
|
// Walls at each vertex (seg_data.0/.1 = start x/y of each seg, last seg appends its end too)
|
|
|
|
|
|
if !seg_data.is_empty() {
|
2026-05-12 23:47:40 +03:00
|
|
|
|
pts.push([f64::NAN; 3]);
|
2026-05-05 20:03:57 +03:00
|
|
|
|
for (k, &(x0, y0, _x1, _y1)) in seg_data.iter().enumerate() {
|
|
|
|
|
|
let pb = key_verts[k];
|
|
|
|
|
|
let _ = (x0, y0); // key_verts already has correct WCS
|
|
|
|
|
|
pts.push(pb);
|
|
|
|
|
|
pts.push(off(pb));
|
|
|
|
|
|
if k + 1 < seg_data.len() {
|
2026-05-12 23:47:40 +03:00
|
|
|
|
pts.push([f64::NAN; 3]);
|
2026-05-05 20:03:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// Last wall at the final vertex
|
|
|
|
|
|
if let Some(&last) = key_verts.last() {
|
2026-05-12 23:47:40 +03:00
|
|
|
|
pts.push([f64::NAN; 3]);
|
2026-05-05 20:03:57 +03:00
|
|
|
|
pts.push(last);
|
|
|
|
|
|
pts.push(off(last));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-12 10:36:15 +03:00
|
|
|
|
TruckEntity {
|
|
|
|
|
|
object: TruckObject::Lines(pts),
|
|
|
|
|
|
snap_pts: vec![],
|
|
|
|
|
|
tangent_geoms: tangents,
|
|
|
|
|
|
key_vertices: key_verts,
|
|
|
|
|
|
fill_tris: vec![],
|
|
|
|
|
|
}
|
2026-05-05 20:03:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-22 14:56:27 +03:00
|
|
|
|
fn to_truck(pline: &LwPolyline) -> TruckEntity {
|
|
|
|
|
|
let verts = &pline.vertices;
|
|
|
|
|
|
if verts.is_empty() {
|
|
|
|
|
|
return TruckEntity {
|
2026-04-25 20:30:26 +03:00
|
|
|
|
object: TruckObject::Point(builder::vertex(Point3::new(0.0, 0.0, 0.0))),
|
2026-03-22 14:56:27 +03:00
|
|
|
|
snap_pts: vec![],
|
|
|
|
|
|
tangent_geoms: vec![],
|
|
|
|
|
|
key_vertices: vec![],
|
2026-05-06 23:24:26 +03:00
|
|
|
|
fill_tris: vec![],
|
2026-03-22 14:56:27 +03:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let elev = pline.elevation;
|
2026-05-02 19:56:23 +03:00
|
|
|
|
let normal = (pline.normal.x, pline.normal.y, pline.normal.z);
|
2026-03-22 14:56:27 +03:00
|
|
|
|
let count = verts.len();
|
|
|
|
|
|
let seg_count = if pline.is_closed { count } else { count - 1 };
|
|
|
|
|
|
let mut edges: Vec<Edge> = Vec::new();
|
|
|
|
|
|
let mut tangents: Vec<TangentGeom> = Vec::new();
|
2026-05-12 23:47:40 +03:00
|
|
|
|
let mut key_verts: Vec<[f64; 3]> = Vec::new();
|
2026-03-22 14:56:27 +03:00
|
|
|
|
|
2026-05-02 19:56:23 +03:00
|
|
|
|
// Convert OCS (x, y, elevation) to WCS Point3.
|
|
|
|
|
|
let to_wcs = |x: f64, y: f64| -> (f64, f64, f64) {
|
|
|
|
|
|
crate::scene::transform::ocs_point_to_wcs((x, y, elev), normal)
|
|
|
|
|
|
};
|
|
|
|
|
|
let to_pt = |v: &LwVertex| -> Point3 {
|
|
|
|
|
|
let (wx, wy, wz) = to_wcs(v.location.x, v.location.y);
|
|
|
|
|
|
Point3::new(wx, wy, wz)
|
|
|
|
|
|
};
|
2026-03-22 14:56:27 +03:00
|
|
|
|
|
2026-05-05 20:03:57 +03:00
|
|
|
|
if pline.thickness.abs() > 1e-10 {
|
2026-05-12 23:47:40 +03:00
|
|
|
|
let mut path: Vec<[f64; 3]> = Vec::new();
|
|
|
|
|
|
let mut kv: Vec<[f64; 3]> = Vec::new();
|
2026-05-05 20:03:57 +03:00
|
|
|
|
let mut tgs: Vec<TangentGeom> = Vec::new();
|
|
|
|
|
|
let mut seg_data: Vec<(f64, f64, f64, f64)> = Vec::new();
|
|
|
|
|
|
// First vertex
|
|
|
|
|
|
let (w0x, w0y, w0z) = to_wcs(verts[0].location.x, verts[0].location.y);
|
2026-05-12 23:47:40 +03:00
|
|
|
|
path.push([w0x, w0y, w0z]);
|
|
|
|
|
|
kv.push([w0x, w0y, w0z]);
|
2026-05-05 20:03:57 +03:00
|
|
|
|
for i in 0..seg_count {
|
|
|
|
|
|
let va = &verts[i];
|
|
|
|
|
|
let vb = &verts[(i + 1) % count];
|
|
|
|
|
|
let (ox0, oy0) = (va.location.x, va.location.y);
|
|
|
|
|
|
let (ox1, oy1) = (vb.location.x, vb.location.y);
|
|
|
|
|
|
let bulge = va.bulge;
|
|
|
|
|
|
if bulge.abs() < 1e-9 {
|
|
|
|
|
|
let (wx, wy, wz) = to_wcs(ox1, oy1);
|
2026-05-12 23:47:40 +03:00
|
|
|
|
path.push([wx, wy, wz]);
|
|
|
|
|
|
let p1_pt = path[path.len() - 2];
|
|
|
|
|
|
let p2_pt = *path.last().unwrap();
|
2026-05-12 10:36:15 +03:00
|
|
|
|
tgs.push(TangentGeom::Line {
|
2026-05-12 23:47:40 +03:00
|
|
|
|
p1: [p1_pt[0] as f32, p1_pt[1] as f32, p1_pt[2] as f32],
|
|
|
|
|
|
p2: [p2_pt[0] as f32, p2_pt[1] as f32, p2_pt[2] as f32],
|
2026-05-12 10:36:15 +03:00
|
|
|
|
});
|
refactor(common): unify bulge → arc math into BulgeArc
The same DXF/DWG bulge → (center, radius, sweep) formula was inlined
in six places (hatch outline, polyline tess + truck path, lwpolyline
×4, scene hatch fill, explode bulge_to_arc) — each with subtly
different sweep-direction handling for the bulge sign.
Add `entities::common::BulgeArc { center, radius, start_angle,
end_angle, sweep }` with one `from_bulge(p0, p1, bulge)` constructor
and a `sample(t)` helper. Callsites collapse to a few lines.
Net: -121 lines, one canonical sweep-direction convention shared by
all consumers.
array.rs (the path-along-curve f32 helper) keeps its inline math —
its sign convention is inverted relative to the others and changing
it without exercising the array-path command risks regressing the
output.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:42:26 +03:00
|
|
|
|
} else if let Some(arc) =
|
|
|
|
|
|
crate::entities::common::BulgeArc::from_bulge([ox0, oy0], [ox1, oy1], bulge)
|
|
|
|
|
|
{
|
|
|
|
|
|
let (wcx, wcy, wcz) = to_wcs(arc.center[0], arc.center[1]);
|
2026-05-12 10:36:15 +03:00
|
|
|
|
tgs.push(TangentGeom::Circle {
|
|
|
|
|
|
center: [wcx as f32, wcy as f32, wcz as f32],
|
refactor(common): unify bulge → arc math into BulgeArc
The same DXF/DWG bulge → (center, radius, sweep) formula was inlined
in six places (hatch outline, polyline tess + truck path, lwpolyline
×4, scene hatch fill, explode bulge_to_arc) — each with subtly
different sweep-direction handling for the bulge sign.
Add `entities::common::BulgeArc { center, radius, start_angle,
end_angle, sweep }` with one `from_bulge(p0, p1, bulge)` constructor
and a `sample(t)` helper. Callsites collapse to a few lines.
Net: -121 lines, one canonical sweep-direction convention shared by
all consumers.
array.rs (the path-along-curve f32 helper) keeps its inline math —
its sign convention is inverted relative to the others and changing
it without exercising the array-path command risks regressing the
output.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:42:26 +03:00
|
|
|
|
radius: arc.radius as f32,
|
2026-05-12 10:36:15 +03:00
|
|
|
|
});
|
2026-05-05 20:03:57 +03:00
|
|
|
|
for j in 1..=16usize {
|
refactor(common): unify bulge → arc math into BulgeArc
The same DXF/DWG bulge → (center, radius, sweep) formula was inlined
in six places (hatch outline, polyline tess + truck path, lwpolyline
×4, scene hatch fill, explode bulge_to_arc) — each with subtly
different sweep-direction handling for the bulge sign.
Add `entities::common::BulgeArc { center, radius, start_angle,
end_angle, sweep }` with one `from_bulge(p0, p1, bulge)` constructor
and a `sample(t)` helper. Callsites collapse to a few lines.
Net: -121 lines, one canonical sweep-direction convention shared by
all consumers.
array.rs (the path-along-curve f32 helper) keeps its inline math —
its sign convention is inverted relative to the others and changing
it without exercising the array-path command risks regressing the
output.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:42:26 +03:00
|
|
|
|
let s = arc.sample(j as f64 / 16.0);
|
|
|
|
|
|
let (wx, wy, wz) = to_wcs(s[0], s[1]);
|
2026-05-12 23:47:40 +03:00
|
|
|
|
path.push([wx, wy, wz]);
|
2026-05-05 20:03:57 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let (wbx, wby, wbz) = to_wcs(ox1, oy1);
|
2026-05-12 23:47:40 +03:00
|
|
|
|
kv.push([wbx, wby, wbz]);
|
2026-05-05 20:03:57 +03:00
|
|
|
|
seg_data.push((ox0, oy0, ox1, oy1));
|
|
|
|
|
|
}
|
|
|
|
|
|
return thick_segments(&seg_data, &path, pline.thickness, normal, kv, tgs);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-06 06:55:28 +03:00
|
|
|
|
// plinegen=false: NaN-separated segments so the linetype pattern restarts per vertex.
|
|
|
|
|
|
if !pline.plinegen {
|
2026-05-12 23:47:40 +03:00
|
|
|
|
let mut pts: Vec<[f64; 3]> = Vec::new();
|
2026-05-06 06:55:28 +03:00
|
|
|
|
let mut tgs: Vec<TangentGeom> = Vec::new();
|
2026-05-12 23:47:40 +03:00
|
|
|
|
let mut kv: Vec<[f64; 3]> = Vec::new();
|
|
|
|
|
|
let to_f32 = |p: [f64; 3]| -> [f32; 3] { [p[0] as f32, p[1] as f32, p[2] as f32] };
|
2026-05-06 06:55:28 +03:00
|
|
|
|
for i in 0..seg_count {
|
|
|
|
|
|
let va = &verts[i];
|
|
|
|
|
|
let vb = &verts[(i + 1) % count];
|
|
|
|
|
|
let (ox0, oy0) = (va.location.x, va.location.y);
|
|
|
|
|
|
let (ox1, oy1) = (vb.location.x, vb.location.y);
|
|
|
|
|
|
let bulge = va.bulge;
|
|
|
|
|
|
let (wx0, wy0, wz0) = to_wcs(ox0, oy0);
|
2026-05-12 23:47:40 +03:00
|
|
|
|
let p_start = [wx0, wy0, wz0];
|
2026-05-06 06:55:28 +03:00
|
|
|
|
pts.push(p_start);
|
2026-05-12 10:36:15 +03:00
|
|
|
|
if i == 0 {
|
|
|
|
|
|
kv.push(p_start);
|
|
|
|
|
|
}
|
2026-05-06 06:55:28 +03:00
|
|
|
|
if bulge.abs() < 1e-9 {
|
|
|
|
|
|
let (wx1, wy1, wz1) = to_wcs(ox1, oy1);
|
2026-05-12 23:47:40 +03:00
|
|
|
|
let p_end = [wx1, wy1, wz1];
|
2026-05-06 06:55:28 +03:00
|
|
|
|
pts.push(p_end);
|
|
|
|
|
|
kv.push(p_end);
|
2026-05-12 10:36:15 +03:00
|
|
|
|
tgs.push(TangentGeom::Line {
|
2026-05-12 23:47:40 +03:00
|
|
|
|
p1: to_f32(p_start),
|
|
|
|
|
|
p2: to_f32(p_end),
|
2026-05-12 10:36:15 +03:00
|
|
|
|
});
|
refactor(common): unify bulge → arc math into BulgeArc
The same DXF/DWG bulge → (center, radius, sweep) formula was inlined
in six places (hatch outline, polyline tess + truck path, lwpolyline
×4, scene hatch fill, explode bulge_to_arc) — each with subtly
different sweep-direction handling for the bulge sign.
Add `entities::common::BulgeArc { center, radius, start_angle,
end_angle, sweep }` with one `from_bulge(p0, p1, bulge)` constructor
and a `sample(t)` helper. Callsites collapse to a few lines.
Net: -121 lines, one canonical sweep-direction convention shared by
all consumers.
array.rs (the path-along-curve f32 helper) keeps its inline math —
its sign convention is inverted relative to the others and changing
it without exercising the array-path command risks regressing the
output.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:42:26 +03:00
|
|
|
|
} else if let Some(arc) =
|
|
|
|
|
|
crate::entities::common::BulgeArc::from_bulge([ox0, oy0], [ox1, oy1], bulge)
|
|
|
|
|
|
{
|
2026-05-06 06:55:28 +03:00
|
|
|
|
for j in 1..=16usize {
|
refactor(common): unify bulge → arc math into BulgeArc
The same DXF/DWG bulge → (center, radius, sweep) formula was inlined
in six places (hatch outline, polyline tess + truck path, lwpolyline
×4, scene hatch fill, explode bulge_to_arc) — each with subtly
different sweep-direction handling for the bulge sign.
Add `entities::common::BulgeArc { center, radius, start_angle,
end_angle, sweep }` with one `from_bulge(p0, p1, bulge)` constructor
and a `sample(t)` helper. Callsites collapse to a few lines.
Net: -121 lines, one canonical sweep-direction convention shared by
all consumers.
array.rs (the path-along-curve f32 helper) keeps its inline math —
its sign convention is inverted relative to the others and changing
it without exercising the array-path command risks regressing the
output.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:42:26 +03:00
|
|
|
|
let s = arc.sample(j as f64 / 16.0);
|
|
|
|
|
|
let (wx, wy, wz) = to_wcs(s[0], s[1]);
|
2026-05-12 23:47:40 +03:00
|
|
|
|
pts.push([wx, wy, wz]);
|
2026-05-06 06:55:28 +03:00
|
|
|
|
}
|
|
|
|
|
|
let (wx1, wy1, wz1) = to_wcs(ox1, oy1);
|
2026-05-12 23:47:40 +03:00
|
|
|
|
kv.push([wx1, wy1, wz1]);
|
refactor(common): unify bulge → arc math into BulgeArc
The same DXF/DWG bulge → (center, radius, sweep) formula was inlined
in six places (hatch outline, polyline tess + truck path, lwpolyline
×4, scene hatch fill, explode bulge_to_arc) — each with subtly
different sweep-direction handling for the bulge sign.
Add `entities::common::BulgeArc { center, radius, start_angle,
end_angle, sweep }` with one `from_bulge(p0, p1, bulge)` constructor
and a `sample(t)` helper. Callsites collapse to a few lines.
Net: -121 lines, one canonical sweep-direction convention shared by
all consumers.
array.rs (the path-along-curve f32 helper) keeps its inline math —
its sign convention is inverted relative to the others and changing
it without exercising the array-path command risks regressing the
output.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:42:26 +03:00
|
|
|
|
let (wcx, wcy, wcz) = to_wcs(arc.center[0], arc.center[1]);
|
2026-05-12 10:36:15 +03:00
|
|
|
|
tgs.push(TangentGeom::Circle {
|
|
|
|
|
|
center: [wcx as f32, wcy as f32, wcz as f32],
|
refactor(common): unify bulge → arc math into BulgeArc
The same DXF/DWG bulge → (center, radius, sweep) formula was inlined
in six places (hatch outline, polyline tess + truck path, lwpolyline
×4, scene hatch fill, explode bulge_to_arc) — each with subtly
different sweep-direction handling for the bulge sign.
Add `entities::common::BulgeArc { center, radius, start_angle,
end_angle, sweep }` with one `from_bulge(p0, p1, bulge)` constructor
and a `sample(t)` helper. Callsites collapse to a few lines.
Net: -121 lines, one canonical sweep-direction convention shared by
all consumers.
array.rs (the path-along-curve f32 helper) keeps its inline math —
its sign convention is inverted relative to the others and changing
it without exercising the array-path command risks regressing the
output.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:42:26 +03:00
|
|
|
|
radius: arc.radius as f32,
|
2026-05-12 10:36:15 +03:00
|
|
|
|
});
|
2026-05-06 06:55:28 +03:00
|
|
|
|
}
|
|
|
|
|
|
if i + 1 < seg_count {
|
2026-05-12 23:47:40 +03:00
|
|
|
|
pts.push([f64::NAN; 3]);
|
2026-05-06 06:55:28 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return TruckEntity {
|
|
|
|
|
|
object: TruckObject::SegmentedLines(pts),
|
|
|
|
|
|
snap_pts: vec![],
|
|
|
|
|
|
tangent_geoms: tgs,
|
|
|
|
|
|
key_vertices: kv,
|
2026-05-06 23:24:26 +03:00
|
|
|
|
fill_tris: vec![],
|
2026-05-06 06:55:28 +03:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-22 14:56:27 +03:00
|
|
|
|
for i in 0..seg_count {
|
|
|
|
|
|
let v0 = &verts[i];
|
|
|
|
|
|
let v1 = &verts[(i + 1) % count];
|
|
|
|
|
|
let p0 = to_pt(v0);
|
|
|
|
|
|
let p1 = to_pt(v1);
|
|
|
|
|
|
let bulge = v0.bulge;
|
|
|
|
|
|
|
|
|
|
|
|
if bulge.abs() < 1e-9 {
|
|
|
|
|
|
let tv0 = builder::vertex(p0);
|
|
|
|
|
|
let tv1 = builder::vertex(p1);
|
|
|
|
|
|
edges.push(builder::line(&tv0, &tv1));
|
|
|
|
|
|
tangents.push(TangentGeom::Line {
|
|
|
|
|
|
p1: [p0.x as f32, p0.y as f32, p0.z as f32],
|
|
|
|
|
|
p2: [p1.x as f32, p1.y as f32, p1.z as f32],
|
|
|
|
|
|
});
|
refactor(common): unify bulge → arc math into BulgeArc
The same DXF/DWG bulge → (center, radius, sweep) formula was inlined
in six places (hatch outline, polyline tess + truck path, lwpolyline
×4, scene hatch fill, explode bulge_to_arc) — each with subtly
different sweep-direction handling for the bulge sign.
Add `entities::common::BulgeArc { center, radius, start_angle,
end_angle, sweep }` with one `from_bulge(p0, p1, bulge)` constructor
and a `sample(t)` helper. Callsites collapse to a few lines.
Net: -121 lines, one canonical sweep-direction convention shared by
all consumers.
array.rs (the path-along-curve f32 helper) keeps its inline math —
its sign convention is inverted relative to the others and changing
it without exercising the array-path command risks regressing the
output.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:42:26 +03:00
|
|
|
|
} else if let Some(arc) = crate::entities::common::BulgeArc::from_bulge(
|
|
|
|
|
|
[v0.location.x, v0.location.y],
|
|
|
|
|
|
[v1.location.x, v1.location.y],
|
|
|
|
|
|
bulge as f64,
|
|
|
|
|
|
) {
|
|
|
|
|
|
let mid_s = arc.sample(0.5);
|
|
|
|
|
|
let (mid_wx, mid_wy, mid_wz) = to_wcs(mid_s[0], mid_s[1]);
|
2026-05-02 19:56:23 +03:00
|
|
|
|
let p_mid = Point3::new(mid_wx, mid_wy, mid_wz);
|
2026-03-22 14:56:27 +03:00
|
|
|
|
let tv0 = builder::vertex(p0);
|
|
|
|
|
|
let tv1 = builder::vertex(p1);
|
|
|
|
|
|
edges.push(builder::circle_arc(&tv0, &tv1, p_mid));
|
refactor(common): unify bulge → arc math into BulgeArc
The same DXF/DWG bulge → (center, radius, sweep) formula was inlined
in six places (hatch outline, polyline tess + truck path, lwpolyline
×4, scene hatch fill, explode bulge_to_arc) — each with subtly
different sweep-direction handling for the bulge sign.
Add `entities::common::BulgeArc { center, radius, start_angle,
end_angle, sweep }` with one `from_bulge(p0, p1, bulge)` constructor
and a `sample(t)` helper. Callsites collapse to a few lines.
Net: -121 lines, one canonical sweep-direction convention shared by
all consumers.
array.rs (the path-along-curve f32 helper) keeps its inline math —
its sign convention is inverted relative to the others and changing
it without exercising the array-path command risks regressing the
output.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:42:26 +03:00
|
|
|
|
let (wcx, wcy, wcz) = to_wcs(arc.center[0], arc.center[1]);
|
2026-03-22 14:56:27 +03:00
|
|
|
|
tangents.push(TangentGeom::Circle {
|
2026-05-02 19:56:23 +03:00
|
|
|
|
center: [wcx as f32, wcy as f32, wcz as f32],
|
refactor(common): unify bulge → arc math into BulgeArc
The same DXF/DWG bulge → (center, radius, sweep) formula was inlined
in six places (hatch outline, polyline tess + truck path, lwpolyline
×4, scene hatch fill, explode bulge_to_arc) — each with subtly
different sweep-direction handling for the bulge sign.
Add `entities::common::BulgeArc { center, radius, start_angle,
end_angle, sweep }` with one `from_bulge(p0, p1, bulge)` constructor
and a `sample(t)` helper. Callsites collapse to a few lines.
Net: -121 lines, one canonical sweep-direction convention shared by
all consumers.
array.rs (the path-along-curve f32 helper) keeps its inline math —
its sign convention is inverted relative to the others and changing
it without exercising the array-path command risks regressing the
output.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:42:26 +03:00
|
|
|
|
radius: arc.radius as f32,
|
2026-03-22 14:56:27 +03:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if i == 0 {
|
2026-05-12 23:47:40 +03:00
|
|
|
|
key_verts.push([p0.x, p0.y, p0.z]);
|
2026-03-22 14:56:27 +03:00
|
|
|
|
}
|
2026-05-12 23:47:40 +03:00
|
|
|
|
key_verts.push([p1.x, p1.y, p1.z]);
|
2026-03-22 14:56:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TruckEntity {
|
|
|
|
|
|
object: TruckObject::Contour(edges.into_iter().collect::<Wire>()),
|
|
|
|
|
|
snap_pts: vec![],
|
|
|
|
|
|
tangent_geoms: tangents,
|
|
|
|
|
|
key_vertices: key_verts,
|
2026-05-06 23:24:26 +03:00
|
|
|
|
fill_tris: vec![],
|
2026-03-22 14:56:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn grips(pline: &LwPolyline) -> Vec<GripDef> {
|
|
|
|
|
|
let elev = pline.elevation as f32;
|
2026-04-27 02:22:51 +03:00
|
|
|
|
let n = pline.vertices.len();
|
2026-05-12 10:36:15 +03:00
|
|
|
|
let seg_count = if pline.is_closed {
|
|
|
|
|
|
n
|
|
|
|
|
|
} else {
|
|
|
|
|
|
n.saturating_sub(1)
|
|
|
|
|
|
};
|
2026-04-27 02:22:51 +03:00
|
|
|
|
|
|
|
|
|
|
let mut out: Vec<GripDef> = pline
|
2026-03-22 14:56:27 +03:00
|
|
|
|
.vertices
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.enumerate()
|
|
|
|
|
|
.map(|(i, v)| square_grip(i, Vec3::new(v.location.x as f32, v.location.y as f32, elev)))
|
2026-04-27 02:22:51 +03:00
|
|
|
|
.collect();
|
|
|
|
|
|
|
refactor(grip): square-only marker set + oriented stretch handles
Phase 1 of bringing the grip vocabulary in line with the standard
CAD convention: drop the per-position-type shape encoding (Diamond
for translate, Circle for parameter) and use a plain square for
every endpoint / vertex / centre grip. The behavioural midpoint vs
vertex distinction stays — it lives on `GripDef::is_midpoint` and
drives `Translate` vs `Absolute` in the grip-edit dispatcher — only
the marker shape collapses.
- `GripShape` keeps `Square`, `Rectangle`, `Triangle`. Diamond /
Circle are gone.
- `GripDef` gains `dir: Option<[f32; 2]>` — a world-XY direction
vector consumed by `Rectangle` to orient the box along its
segment.
- `entities::common` exposes `square_grip`, `center_grip` (same
square marker, flagged as translate), `rectangle_grip(id, world,
dir)` for oriented mid-segment handles, and a kept-for-Phase-2
`triangle_grip`.
- `overlay::GripMarker` / `grips_to_screen[_paper]` thread `dir`
through to the canvas painter; the Rectangle path rotates the
box around the grip centre using the world-XY direction (flipping
the sin for screen-Y).
Every existing `diamond_grip(id, w)` call becomes `center_grip(id,
w)` — the visual change is square-replacing-diamond at line
midpoints / arc midpoints / circle centres / ellipse centres /
viewport / hatch loop centroids / dimension grips / image corners /
multileader / ray / underlay / ole2frame / solid3d.
`LwPolyline` grows a stretch handle on every segment (straight or
arc), drawn as the new oriented rectangle. The grip-edit path
translates both segment endpoints for straight segments and
adjusts the arc bulge from the new midpoint for arc segments.
2026-05-29 02:07:34 +03:00
|
|
|
|
// One mid-segment stretch grip per segment (straight or arc). The
|
|
|
|
|
|
// marker is a small box rotated along the chord direction so the
|
|
|
|
|
|
// shape itself signals which way the segment runs.
|
2026-04-27 02:22:51 +03:00
|
|
|
|
for i in 0..seg_count {
|
|
|
|
|
|
let v0 = &pline.vertices[i];
|
|
|
|
|
|
let v1 = &pline.vertices[(i + 1) % n];
|
refactor(grip): square-only marker set + oriented stretch handles
Phase 1 of bringing the grip vocabulary in line with the standard
CAD convention: drop the per-position-type shape encoding (Diamond
for translate, Circle for parameter) and use a plain square for
every endpoint / vertex / centre grip. The behavioural midpoint vs
vertex distinction stays — it lives on `GripDef::is_midpoint` and
drives `Translate` vs `Absolute` in the grip-edit dispatcher — only
the marker shape collapses.
- `GripShape` keeps `Square`, `Rectangle`, `Triangle`. Diamond /
Circle are gone.
- `GripDef` gains `dir: Option<[f32; 2]>` — a world-XY direction
vector consumed by `Rectangle` to orient the box along its
segment.
- `entities::common` exposes `square_grip`, `center_grip` (same
square marker, flagged as translate), `rectangle_grip(id, world,
dir)` for oriented mid-segment handles, and a kept-for-Phase-2
`triangle_grip`.
- `overlay::GripMarker` / `grips_to_screen[_paper]` thread `dir`
through to the canvas painter; the Rectangle path rotates the
box around the grip centre using the world-XY direction (flipping
the sin for screen-Y).
Every existing `diamond_grip(id, w)` call becomes `center_grip(id,
w)` — the visual change is square-replacing-diamond at line
midpoints / arc midpoints / circle centres / ellipse centres /
viewport / hatch loop centroids / dimension grips / image corners /
multileader / ray / underlay / ole2frame / solid3d.
`LwPolyline` grows a stretch handle on every segment (straight or
arc), drawn as the new oriented rectangle. The grip-edit path
translates both segment endpoints for straight segments and
adjusts the arc bulge from the new midpoint for arc segments.
2026-05-29 02:07:34 +03:00
|
|
|
|
let (mx, my) = if v0.bulge.abs() < 1e-9 {
|
|
|
|
|
|
(
|
|
|
|
|
|
(v0.location.x + v1.location.x) * 0.5,
|
|
|
|
|
|
(v0.location.y + v1.location.y) * 0.5,
|
|
|
|
|
|
)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
let m = arc_midpoint(
|
|
|
|
|
|
[v0.location.x, v0.location.y],
|
|
|
|
|
|
[v1.location.x, v1.location.y],
|
|
|
|
|
|
v0.bulge,
|
|
|
|
|
|
);
|
|
|
|
|
|
(m[0], m[1])
|
|
|
|
|
|
};
|
|
|
|
|
|
let dx = (v1.location.x - v0.location.x) as f32;
|
|
|
|
|
|
let dy = (v1.location.y - v0.location.y) as f32;
|
|
|
|
|
|
out.push(rectangle_grip(
|
2026-05-12 10:36:15 +03:00
|
|
|
|
n + i,
|
refactor(grip): square-only marker set + oriented stretch handles
Phase 1 of bringing the grip vocabulary in line with the standard
CAD convention: drop the per-position-type shape encoding (Diamond
for translate, Circle for parameter) and use a plain square for
every endpoint / vertex / centre grip. The behavioural midpoint vs
vertex distinction stays — it lives on `GripDef::is_midpoint` and
drives `Translate` vs `Absolute` in the grip-edit dispatcher — only
the marker shape collapses.
- `GripShape` keeps `Square`, `Rectangle`, `Triangle`. Diamond /
Circle are gone.
- `GripDef` gains `dir: Option<[f32; 2]>` — a world-XY direction
vector consumed by `Rectangle` to orient the box along its
segment.
- `entities::common` exposes `square_grip`, `center_grip` (same
square marker, flagged as translate), `rectangle_grip(id, world,
dir)` for oriented mid-segment handles, and a kept-for-Phase-2
`triangle_grip`.
- `overlay::GripMarker` / `grips_to_screen[_paper]` thread `dir`
through to the canvas painter; the Rectangle path rotates the
box around the grip centre using the world-XY direction (flipping
the sin for screen-Y).
Every existing `diamond_grip(id, w)` call becomes `center_grip(id,
w)` — the visual change is square-replacing-diamond at line
midpoints / arc midpoints / circle centres / ellipse centres /
viewport / hatch loop centroids / dimension grips / image corners /
multileader / ray / underlay / ole2frame / solid3d.
`LwPolyline` grows a stretch handle on every segment (straight or
arc), drawn as the new oriented rectangle. The grip-edit path
translates both segment endpoints for straight segments and
adjusts the arc bulge from the new midpoint for arc segments.
2026-05-29 02:07:34 +03:00
|
|
|
|
Vec3::new(mx as f32, my as f32, elev),
|
|
|
|
|
|
[dx, dy],
|
2026-05-12 10:36:15 +03:00
|
|
|
|
));
|
2026-04-27 02:22:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
out
|
2026-03-22 14:56:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn properties(pline: &LwPolyline) -> PropSection {
|
|
|
|
|
|
PropSection {
|
|
|
|
|
|
title: "Geometry".into(),
|
|
|
|
|
|
props: vec![
|
|
|
|
|
|
ro("Vertices", "vertices", pline.vertices.len().to_string()),
|
|
|
|
|
|
ro(
|
|
|
|
|
|
"Closed",
|
|
|
|
|
|
"closed",
|
|
|
|
|
|
if pline.is_closed { "Yes" } else { "No" },
|
|
|
|
|
|
),
|
|
|
|
|
|
edit("Elevation", "elevation", pline.elevation),
|
|
|
|
|
|
],
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn apply_geom_prop(pline: &mut LwPolyline, field: &str, value: &str) {
|
|
|
|
|
|
let Some(v) = parse_f64(value) else {
|
|
|
|
|
|
return;
|
|
|
|
|
|
};
|
|
|
|
|
|
if field == "elevation" {
|
|
|
|
|
|
pline.elevation = v;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn apply_grip(pline: &mut LwPolyline, grip_id: usize, apply: GripApply) {
|
2026-04-27 02:22:51 +03:00
|
|
|
|
let n = pline.vertices.len();
|
|
|
|
|
|
if grip_id < n {
|
|
|
|
|
|
// Vertex position grip
|
|
|
|
|
|
let v = &mut pline.vertices[grip_id];
|
2026-03-22 14:56:27 +03:00
|
|
|
|
match apply {
|
|
|
|
|
|
GripApply::Absolute(p) => {
|
|
|
|
|
|
v.location.x = p.x as f64;
|
|
|
|
|
|
v.location.y = p.y as f64;
|
|
|
|
|
|
}
|
|
|
|
|
|
GripApply::Translate(d) => {
|
|
|
|
|
|
v.location.x += d.x as f64;
|
|
|
|
|
|
v.location.y += d.y as f64;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-04-27 02:22:51 +03:00
|
|
|
|
} else {
|
refactor(grip): square-only marker set + oriented stretch handles
Phase 1 of bringing the grip vocabulary in line with the standard
CAD convention: drop the per-position-type shape encoding (Diamond
for translate, Circle for parameter) and use a plain square for
every endpoint / vertex / centre grip. The behavioural midpoint vs
vertex distinction stays — it lives on `GripDef::is_midpoint` and
drives `Translate` vs `Absolute` in the grip-edit dispatcher — only
the marker shape collapses.
- `GripShape` keeps `Square`, `Rectangle`, `Triangle`. Diamond /
Circle are gone.
- `GripDef` gains `dir: Option<[f32; 2]>` — a world-XY direction
vector consumed by `Rectangle` to orient the box along its
segment.
- `entities::common` exposes `square_grip`, `center_grip` (same
square marker, flagged as translate), `rectangle_grip(id, world,
dir)` for oriented mid-segment handles, and a kept-for-Phase-2
`triangle_grip`.
- `overlay::GripMarker` / `grips_to_screen[_paper]` thread `dir`
through to the canvas painter; the Rectangle path rotates the
box around the grip centre using the world-XY direction (flipping
the sin for screen-Y).
Every existing `diamond_grip(id, w)` call becomes `center_grip(id,
w)` — the visual change is square-replacing-diamond at line
midpoints / arc midpoints / circle centres / ellipse centres /
viewport / hatch loop centroids / dimension grips / image corners /
multileader / ray / underlay / ole2frame / solid3d.
`LwPolyline` grows a stretch handle on every segment (straight or
arc), drawn as the new oriented rectangle. The grip-edit path
translates both segment endpoints for straight segments and
adjusts the arc bulge from the new midpoint for arc segments.
2026-05-29 02:07:34 +03:00
|
|
|
|
// Mid-segment stretch grip for segment (grip_id - n).
|
|
|
|
|
|
// Straight segments translate both endpoints by the drag delta
|
|
|
|
|
|
// (the shared vertices then carry along whichever adjacent
|
|
|
|
|
|
// segments share them). Arc segments adjust their bulge from
|
|
|
|
|
|
// the new midpoint position.
|
2026-04-27 02:22:51 +03:00
|
|
|
|
let seg = grip_id - n;
|
2026-05-12 10:36:15 +03:00
|
|
|
|
let count = if pline.is_closed {
|
|
|
|
|
|
n
|
|
|
|
|
|
} else {
|
|
|
|
|
|
n.saturating_sub(1)
|
|
|
|
|
|
};
|
2026-04-27 02:22:51 +03:00
|
|
|
|
if seg >= count {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
refactor(grip): square-only marker set + oriented stretch handles
Phase 1 of bringing the grip vocabulary in line with the standard
CAD convention: drop the per-position-type shape encoding (Diamond
for translate, Circle for parameter) and use a plain square for
every endpoint / vertex / centre grip. The behavioural midpoint vs
vertex distinction stays — it lives on `GripDef::is_midpoint` and
drives `Translate` vs `Absolute` in the grip-edit dispatcher — only
the marker shape collapses.
- `GripShape` keeps `Square`, `Rectangle`, `Triangle`. Diamond /
Circle are gone.
- `GripDef` gains `dir: Option<[f32; 2]>` — a world-XY direction
vector consumed by `Rectangle` to orient the box along its
segment.
- `entities::common` exposes `square_grip`, `center_grip` (same
square marker, flagged as translate), `rectangle_grip(id, world,
dir)` for oriented mid-segment handles, and a kept-for-Phase-2
`triangle_grip`.
- `overlay::GripMarker` / `grips_to_screen[_paper]` thread `dir`
through to the canvas painter; the Rectangle path rotates the
box around the grip centre using the world-XY direction (flipping
the sin for screen-Y).
Every existing `diamond_grip(id, w)` call becomes `center_grip(id,
w)` — the visual change is square-replacing-diamond at line
midpoints / arc midpoints / circle centres / ellipse centres /
viewport / hatch loop centroids / dimension grips / image corners /
multileader / ray / underlay / ole2frame / solid3d.
`LwPolyline` grows a stretch handle on every segment (straight or
arc), drawn as the new oriented rectangle. The grip-edit path
translates both segment endpoints for straight segments and
adjusts the arc bulge from the new midpoint for arc segments.
2026-05-29 02:07:34 +03:00
|
|
|
|
let i0 = seg;
|
|
|
|
|
|
let i1 = (seg + 1) % n;
|
|
|
|
|
|
let is_arc = pline.vertices[i0].bulge.abs() >= 1e-9;
|
|
|
|
|
|
if !is_arc {
|
|
|
|
|
|
let d = match apply {
|
|
|
|
|
|
GripApply::Translate(d) => [d.x as f64, d.y as f64],
|
|
|
|
|
|
GripApply::Absolute(p) => {
|
|
|
|
|
|
let old_mid = (
|
|
|
|
|
|
(pline.vertices[i0].location.x + pline.vertices[i1].location.x) * 0.5,
|
|
|
|
|
|
(pline.vertices[i0].location.y + pline.vertices[i1].location.y) * 0.5,
|
|
|
|
|
|
);
|
|
|
|
|
|
[p.x as f64 - old_mid.0, p.y as f64 - old_mid.1]
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
pline.vertices[i0].location.x += d[0];
|
|
|
|
|
|
pline.vertices[i0].location.y += d[1];
|
|
|
|
|
|
pline.vertices[i1].location.x += d[0];
|
|
|
|
|
|
pline.vertices[i1].location.y += d[1];
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-04-27 02:22:51 +03:00
|
|
|
|
let new_mid: [f64; 2] = match apply {
|
|
|
|
|
|
GripApply::Absolute(p) => [p.x as f64, p.y as f64],
|
|
|
|
|
|
GripApply::Translate(d) => {
|
refactor(grip): square-only marker set + oriented stretch handles
Phase 1 of bringing the grip vocabulary in line with the standard
CAD convention: drop the per-position-type shape encoding (Diamond
for translate, Circle for parameter) and use a plain square for
every endpoint / vertex / centre grip. The behavioural midpoint vs
vertex distinction stays — it lives on `GripDef::is_midpoint` and
drives `Translate` vs `Absolute` in the grip-edit dispatcher — only
the marker shape collapses.
- `GripShape` keeps `Square`, `Rectangle`, `Triangle`. Diamond /
Circle are gone.
- `GripDef` gains `dir: Option<[f32; 2]>` — a world-XY direction
vector consumed by `Rectangle` to orient the box along its
segment.
- `entities::common` exposes `square_grip`, `center_grip` (same
square marker, flagged as translate), `rectangle_grip(id, world,
dir)` for oriented mid-segment handles, and a kept-for-Phase-2
`triangle_grip`.
- `overlay::GripMarker` / `grips_to_screen[_paper]` thread `dir`
through to the canvas painter; the Rectangle path rotates the
box around the grip centre using the world-XY direction (flipping
the sin for screen-Y).
Every existing `diamond_grip(id, w)` call becomes `center_grip(id,
w)` — the visual change is square-replacing-diamond at line
midpoints / arc midpoints / circle centres / ellipse centres /
viewport / hatch loop centroids / dimension grips / image corners /
multileader / ray / underlay / ole2frame / solid3d.
`LwPolyline` grows a stretch handle on every segment (straight or
arc), drawn as the new oriented rectangle. The grip-edit path
translates both segment endpoints for straight segments and
adjusts the arc bulge from the new midpoint for arc segments.
2026-05-29 02:07:34 +03:00
|
|
|
|
let v0 = &pline.vertices[i0];
|
|
|
|
|
|
let v1 = &pline.vertices[i1];
|
2026-04-27 02:22:51 +03:00
|
|
|
|
let old = arc_midpoint(
|
|
|
|
|
|
[v0.location.x, v0.location.y],
|
|
|
|
|
|
[v1.location.x, v1.location.y],
|
|
|
|
|
|
v0.bulge,
|
|
|
|
|
|
);
|
|
|
|
|
|
[old[0] + d.x as f64, old[1] + d.y as f64]
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2026-05-12 10:36:15 +03:00
|
|
|
|
let p0 = [
|
refactor(grip): square-only marker set + oriented stretch handles
Phase 1 of bringing the grip vocabulary in line with the standard
CAD convention: drop the per-position-type shape encoding (Diamond
for translate, Circle for parameter) and use a plain square for
every endpoint / vertex / centre grip. The behavioural midpoint vs
vertex distinction stays — it lives on `GripDef::is_midpoint` and
drives `Translate` vs `Absolute` in the grip-edit dispatcher — only
the marker shape collapses.
- `GripShape` keeps `Square`, `Rectangle`, `Triangle`. Diamond /
Circle are gone.
- `GripDef` gains `dir: Option<[f32; 2]>` — a world-XY direction
vector consumed by `Rectangle` to orient the box along its
segment.
- `entities::common` exposes `square_grip`, `center_grip` (same
square marker, flagged as translate), `rectangle_grip(id, world,
dir)` for oriented mid-segment handles, and a kept-for-Phase-2
`triangle_grip`.
- `overlay::GripMarker` / `grips_to_screen[_paper]` thread `dir`
through to the canvas painter; the Rectangle path rotates the
box around the grip centre using the world-XY direction (flipping
the sin for screen-Y).
Every existing `diamond_grip(id, w)` call becomes `center_grip(id,
w)` — the visual change is square-replacing-diamond at line
midpoints / arc midpoints / circle centres / ellipse centres /
viewport / hatch loop centroids / dimension grips / image corners /
multileader / ray / underlay / ole2frame / solid3d.
`LwPolyline` grows a stretch handle on every segment (straight or
arc), drawn as the new oriented rectangle. The grip-edit path
translates both segment endpoints for straight segments and
adjusts the arc bulge from the new midpoint for arc segments.
2026-05-29 02:07:34 +03:00
|
|
|
|
pline.vertices[i0].location.x,
|
|
|
|
|
|
pline.vertices[i0].location.y,
|
2026-05-12 10:36:15 +03:00
|
|
|
|
];
|
2026-04-27 02:22:51 +03:00
|
|
|
|
let p1 = [
|
refactor(grip): square-only marker set + oriented stretch handles
Phase 1 of bringing the grip vocabulary in line with the standard
CAD convention: drop the per-position-type shape encoding (Diamond
for translate, Circle for parameter) and use a plain square for
every endpoint / vertex / centre grip. The behavioural midpoint vs
vertex distinction stays — it lives on `GripDef::is_midpoint` and
drives `Translate` vs `Absolute` in the grip-edit dispatcher — only
the marker shape collapses.
- `GripShape` keeps `Square`, `Rectangle`, `Triangle`. Diamond /
Circle are gone.
- `GripDef` gains `dir: Option<[f32; 2]>` — a world-XY direction
vector consumed by `Rectangle` to orient the box along its
segment.
- `entities::common` exposes `square_grip`, `center_grip` (same
square marker, flagged as translate), `rectangle_grip(id, world,
dir)` for oriented mid-segment handles, and a kept-for-Phase-2
`triangle_grip`.
- `overlay::GripMarker` / `grips_to_screen[_paper]` thread `dir`
through to the canvas painter; the Rectangle path rotates the
box around the grip centre using the world-XY direction (flipping
the sin for screen-Y).
Every existing `diamond_grip(id, w)` call becomes `center_grip(id,
w)` — the visual change is square-replacing-diamond at line
midpoints / arc midpoints / circle centres / ellipse centres /
viewport / hatch loop centroids / dimension grips / image corners /
multileader / ray / underlay / ole2frame / solid3d.
`LwPolyline` grows a stretch handle on every segment (straight or
arc), drawn as the new oriented rectangle. The grip-edit path
translates both segment endpoints for straight segments and
adjusts the arc bulge from the new midpoint for arc segments.
2026-05-29 02:07:34 +03:00
|
|
|
|
pline.vertices[i1].location.x,
|
|
|
|
|
|
pline.vertices[i1].location.y,
|
2026-04-27 02:22:51 +03:00
|
|
|
|
];
|
|
|
|
|
|
if let Some(new_bulge) = bulge_from_midpoint(p0, p1, new_mid) {
|
refactor(grip): square-only marker set + oriented stretch handles
Phase 1 of bringing the grip vocabulary in line with the standard
CAD convention: drop the per-position-type shape encoding (Diamond
for translate, Circle for parameter) and use a plain square for
every endpoint / vertex / centre grip. The behavioural midpoint vs
vertex distinction stays — it lives on `GripDef::is_midpoint` and
drives `Translate` vs `Absolute` in the grip-edit dispatcher — only
the marker shape collapses.
- `GripShape` keeps `Square`, `Rectangle`, `Triangle`. Diamond /
Circle are gone.
- `GripDef` gains `dir: Option<[f32; 2]>` — a world-XY direction
vector consumed by `Rectangle` to orient the box along its
segment.
- `entities::common` exposes `square_grip`, `center_grip` (same
square marker, flagged as translate), `rectangle_grip(id, world,
dir)` for oriented mid-segment handles, and a kept-for-Phase-2
`triangle_grip`.
- `overlay::GripMarker` / `grips_to_screen[_paper]` thread `dir`
through to the canvas painter; the Rectangle path rotates the
box around the grip centre using the world-XY direction (flipping
the sin for screen-Y).
Every existing `diamond_grip(id, w)` call becomes `center_grip(id,
w)` — the visual change is square-replacing-diamond at line
midpoints / arc midpoints / circle centres / ellipse centres /
viewport / hatch loop centroids / dimension grips / image corners /
multileader / ray / underlay / ole2frame / solid3d.
`LwPolyline` grows a stretch handle on every segment (straight or
arc), drawn as the new oriented rectangle. The grip-edit path
translates both segment endpoints for straight segments and
adjusts the arc bulge from the new midpoint for arc segments.
2026-05-29 02:07:34 +03:00
|
|
|
|
pline.vertices[i0].bulge = new_bulge.clamp(-1e6, 1e6);
|
2026-04-27 02:22:51 +03:00
|
|
|
|
}
|
2026-03-22 14:56:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn apply_transform(pline: &mut LwPolyline, t: &EntityTransform) {
|
|
|
|
|
|
crate::scene::transform::apply_standard_entity_transform(pline, t, |entity, p1, p2| {
|
|
|
|
|
|
for v in &mut entity.vertices {
|
|
|
|
|
|
crate::scene::transform::reflect_xy_point(&mut v.location.x, &mut v.location.y, p1, p2);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl TruckConvertible for LwPolyline {
|
|
|
|
|
|
fn to_truck(&self, _document: &acadrust::CadDocument) -> Option<TruckEntity> {
|
|
|
|
|
|
Some(to_truck(self))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
refactor(entities): collapse trait wrapper boilerplate via macro
Every entity file ended with the same three-trait wrapper block:
impl Grippable for T {
fn grips(&self) -> Vec<GripDef> { grips(self) }
fn apply_grip(&mut self, ...) { apply_grip(self, ...) }
}
impl PropertyEditable for T { ... }
impl Transformable for T { ... }
— 23 lines of pure delegation around five same-named free functions.
Replace with `crate::impl_entity_basics!(T);` (a macro in
entities/traits.rs that expands to the three trait impls).
Applied where the file already follows the free-fn delegation
convention (Arc, Circle, Ellipse, Insert, Leader, Line, LwPolyline,
MultiLeader, Ole2Frame, Point, Spline, Viewport). Files that inlined
the trait method bodies directly (Ray, XLine, Shape, Solid, Tolerance,
MLine, Mesh, Solid3D/Region/Body, Table, RasterImage, Wipeout,
Underlay, Hatch, Polyline, Polyline2D, Polyline3D, Dimension) left
alone — they already skip the indirection. Text/MText/Attribute use
the with-text-style flavour and will move once that variant is needed
beyond the existing two manual impls.
A second macro `impl_entity_basics_with_text_styles!` is included for
the text-like flavour but no entity uses it yet.
Net: -204 lines.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 17:16:06 +03:00
|
|
|
|
crate::impl_entity_basics!(LwPolyline);
|
2026-03-22 14:56:27 +03:00
|
|
|
|
|
2026-05-23 23:26:14 +03:00
|
|
|
|
pub(crate) fn wide_fills(pl: &acadrust::entities::LwPolyline) -> Vec<Vec<[f32; 2]>> {
|
|
|
|
|
|
let hw_const = (pl.constant_width / 2.0) as f32;
|
|
|
|
|
|
let verts = &pl.vertices;
|
|
|
|
|
|
let n = verts.len();
|
|
|
|
|
|
if n < 2 {
|
|
|
|
|
|
return vec![];
|
|
|
|
|
|
}
|
|
|
|
|
|
let seg_count = if pl.is_closed { n } else { n - 1 };
|
|
|
|
|
|
let mut out = Vec::new();
|
|
|
|
|
|
for i in 0..seg_count {
|
|
|
|
|
|
let v0 = &verts[i];
|
|
|
|
|
|
let v1 = &verts[(i + 1) % n];
|
|
|
|
|
|
let hw0 = if v0.start_width > 1e-9 {
|
|
|
|
|
|
v0.start_width as f32 / 2.0
|
|
|
|
|
|
} else {
|
|
|
|
|
|
hw_const
|
|
|
|
|
|
};
|
|
|
|
|
|
let hw1 = if v0.end_width > 1e-9 {
|
|
|
|
|
|
v0.end_width as f32 / 2.0
|
|
|
|
|
|
} else {
|
|
|
|
|
|
hw_const
|
|
|
|
|
|
};
|
|
|
|
|
|
if hw0 < 1e-6 && hw1 < 1e-6 {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
let p0 = [v0.location.x as f32, v0.location.y as f32];
|
|
|
|
|
|
let p1 = [v1.location.x as f32, v1.location.y as f32];
|
|
|
|
|
|
if let Some(poly) = crate::entities::common::polyline_segment_fill(p0, p1, hw0, hw1, v0.bulge as f32) {
|
|
|
|
|
|
out.push(poly);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
out
|
|
|
|
|
|
}
|
refactor(commands): per-entity MassProps + TextContent traits
Two free helpers in app/commands.rs lived as big match-on-EntityType
blocks: massprop_entity (Circle/Arc/Line/LwPolyline/Ellipse area +
perimeter + centroid, ~140 lines) and entity_text_content /
replace_entity_text (Text/MText/AttributeDefinition/AttributeEntity).
Move each to its own trait in entities/traits.rs and implement
per-entity:
MassPropsCalc — Circle, Arc, Line, LwPolyline, Ellipse
TextContent — Text, MText, AttributeDefinition, AttributeEntity
EntityTypeOps gets dispatch shims that route to the trait via the
existing macro, so callsites just call entity.mass_props() /
entity.text_content() / entity.replace_text(search, rep).
The remaining free helpers in commands.rs (entity_list_details,
entity_extra_info, entity_type_name, build_data_extraction_csv) are
single-command formatting helpers tightly coupled to LIST / EXTRACT /
text-format output. Distributing them as per-entity methods would
inflate every entity file with command-side formatting concerns
without making the command-side any cleaner — left in place.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:30:34 +03:00
|
|
|
|
|
|
|
|
|
|
impl crate::entities::traits::MassPropsCalc for acadrust::entities::LwPolyline {
|
|
|
|
|
|
fn mass_props(&self) -> crate::entities::traits::MassProps {
|
|
|
|
|
|
let p = self;
|
|
|
|
|
|
let n = p.vertices.len();
|
|
|
|
|
|
if n < 2 {
|
|
|
|
|
|
return crate::entities::traits::MassProps {
|
|
|
|
|
|
area: 0.0,
|
|
|
|
|
|
perimeter: 0.0,
|
|
|
|
|
|
cx: 0.0,
|
|
|
|
|
|
cy: 0.0,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
// Shoelace area + perimeter
|
|
|
|
|
|
let mut area_sum = 0.0f64;
|
|
|
|
|
|
let mut perimeter = 0.0f64;
|
|
|
|
|
|
let mut cx_sum = 0.0f64;
|
|
|
|
|
|
let mut cy_sum = 0.0f64;
|
|
|
|
|
|
let n_segs = if p.is_closed { n } else { n - 1 };
|
|
|
|
|
|
for idx in 0..n_segs {
|
|
|
|
|
|
let v0 = &p.vertices[idx];
|
|
|
|
|
|
let v1 = &p.vertices[(idx + 1) % n];
|
|
|
|
|
|
let x0 = v0.location.x;
|
|
|
|
|
|
let y0 = v0.location.y;
|
|
|
|
|
|
let x1 = v1.location.x;
|
|
|
|
|
|
let y1 = v1.location.y;
|
|
|
|
|
|
area_sum += x0 * y1 - x1 * y0;
|
|
|
|
|
|
perimeter += ((x1 - x0).powi(2) + (y1 - y0).powi(2)).sqrt();
|
|
|
|
|
|
cx_sum += (x0 + x1) * (x0 * y1 - x1 * y0);
|
|
|
|
|
|
cy_sum += (y0 + y1) * (x0 * y1 - x1 * y0);
|
|
|
|
|
|
}
|
|
|
|
|
|
let area = (area_sum / 2.0).abs();
|
|
|
|
|
|
let (cx, cy) = if area > 1e-12 {
|
|
|
|
|
|
(cx_sum / (6.0 * area), cy_sum / (6.0 * area))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
let sx: f64 = p.vertices.iter().map(|v| v.location.x).sum::<f64>() / n as f64;
|
|
|
|
|
|
let sy: f64 = p.vertices.iter().map(|v| v.location.y).sum::<f64>() / n as f64;
|
|
|
|
|
|
(sx, sy)
|
|
|
|
|
|
};
|
|
|
|
|
|
crate::entities::traits::MassProps {
|
|
|
|
|
|
area,
|
|
|
|
|
|
perimeter,
|
|
|
|
|
|
cx,
|
|
|
|
|
|
cy,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|