forked from 1b-agent/opencadstudio-upstream
refactor(modify): take plane geometry from cadkernel
TRIM, FILLET and EXPLODE each carried their own copy of the same plane maths. The copies had already drifted apart: `ll` differed only in parameter names between trim.rs and fillet.rs, `arc_pts` only in which angle helper it called, and `norm` meant angle normalisation in trim.rs and explode.rs while meaning vector normalisation in two other files. The implementations now live in cadkernel's geom2d. A new local `geom` module adapts the call shapes — the kernel takes `[f64; 2]` points and returns `[f64; 3]`, while these commands pass loose scalars and feed `WireModel::points`, which is `[f32; 3]`. Narrowing stays on this side because only the caller knows whether it is a preview wire, which leaves `points_low` empty and accepts the loss, or resident geometry, which splits the f64 into a high/low pair instead. Call sites are untouched: the kernel functions are imported under the old local names, so the signatures they were written against still hold. This also fixes ELLIPSE trim and extend previews. `ellipse_pts` wrote its components as [x, z, y] while `arc_pts` — reached from the same match in `entity_pts`, feeding the same `[f32; 3]` — wrote [x, y, z], and `WireModel::points` is documented as world-space positions. Ellipse previews were collapsing onto y = 0 and displacing along Z. The kernel's `ellipse_arc` orders them correctly, so delegating corrects it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
051272ad71
commit
d0cc3284d2
6 files changed
+152
-272
No files matched your search
@@ -10,6 +10,10 @@
|
||||
// Finds intersection, backs off dist1 along line 1 and dist2 along line 2.
|
||||
|
||||
use acadrust::entities::{Arc as ArcEnt, Line as LineEnt, LwPolyline};
|
||||
|
||||
// Shared plane geometry, from cadkernel via the local adapters.
|
||||
use super::geom;
|
||||
use super::geom::{arc_points as arc_pts, line_line as ll, normalize_angle as norm_angle};
|
||||
use acadrust::types::Vector3;
|
||||
use acadrust::{EntityType, Handle};
|
||||
use glam::DVec3;
|
||||
@@ -46,26 +50,6 @@ pub const DROPDOWN_ITEMS: &[(&str, &str, IconKind)] = &[
|
||||
// Geometry
|
||||
// ══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/// Intersect two infinite lines. Returns (t on L1, u on L2).
|
||||
fn ll(
|
||||
ax: f64,
|
||||
ay: f64,
|
||||
dx: f64,
|
||||
dy: f64,
|
||||
cx: f64,
|
||||
cy: f64,
|
||||
ex: f64,
|
||||
ey: f64,
|
||||
) -> Option<(f64, f64)> {
|
||||
let det = dx * ey - dy * ex;
|
||||
if det.abs() < 1e-10 {
|
||||
return None;
|
||||
}
|
||||
let t = ((cx - ax) * ey - (cy - ay) * ex) / det;
|
||||
let u = ((cx - ax) * dy - (cy - ay) * dx) / det;
|
||||
Some((t, u))
|
||||
}
|
||||
|
||||
/// Extract coords and unit direction for a Line entity.
|
||||
fn line_geom(l: &LineEnt) -> ([f64; 2], [f64; 2], [f64; 2], f64) {
|
||||
let p1 = [l.start.x, l.start.y];
|
||||
@@ -229,32 +213,10 @@ fn trim_to_xy(
|
||||
// ── Point-generation helpers ──────────────────────────────────────────────
|
||||
|
||||
fn line_pts(l: &LineEnt) -> Vec<[f32; 3]> {
|
||||
vec![
|
||||
[l.start.x as f32, l.start.y as f32, l.start.z as f32],
|
||||
[l.end.x as f32, l.end.y as f32, l.end.z as f32],
|
||||
]
|
||||
}
|
||||
|
||||
fn arc_pts(cx: f64, cy: f64, r: f64, a0: f64, a1: f64, z: f64) -> Vec<[f32; 3]> {
|
||||
let span = {
|
||||
let s = norm_angle(a1) - norm_angle(a0);
|
||||
if s <= 0.0 {
|
||||
s + TAU
|
||||
} else {
|
||||
s
|
||||
}
|
||||
};
|
||||
let steps = (span.abs() * 20.0).ceil().max(4.0) as usize;
|
||||
(0..=steps)
|
||||
.map(|i| {
|
||||
let ang = norm_angle(a0) + span * (i as f64 / steps as f64);
|
||||
[
|
||||
(cx + r * ang.cos()) as f32,
|
||||
(cy + r * ang.sin()) as f32,
|
||||
z as f32,
|
||||
]
|
||||
})
|
||||
.collect()
|
||||
geom::line_points(
|
||||
[l.start.x, l.start.y, l.start.z],
|
||||
[l.end.x, l.end.y, l.end.z],
|
||||
)
|
||||
}
|
||||
|
||||
fn entity_pts(e: &EntityType) -> Vec<[f32; 3]> {
|
||||
@@ -286,11 +248,6 @@ fn arc_geom(a: &ArcEnt) -> ([f64; 2], f64, f64, f64, f64) {
|
||||
)
|
||||
}
|
||||
|
||||
/// Normalize angle to [0, 2π).
|
||||
fn norm_angle(a: f64) -> f64 {
|
||||
((a % TAU) + TAU) % TAU
|
||||
}
|
||||
|
||||
/// Return the CCW angular span from `start` to `end`.
|
||||
fn arc_span(start: f64, end: f64) -> f64 {
|
||||
let s = (end - start).rem_euclid(TAU);
|
||||
|
||||
Reference in new issue
Block a user