cad-editor/src/modules/view/zoom_window.rs
Hakan Seven bfd8d0411a perf: AABB snap pre-rejection via acadrust bounding_box() (Option K upgrade)
Add `aabb: [f32; 4]` field to WireModel (world-space 2-D bounding box).
In tessellate_entity() set each wire's AABB from e.as_entity().bounding_box()
via new entity_aabb() helper; Insert sub-entities each get their own AABB.
Preview/interim wires and any entity returning a zero-extent default box get
UNBOUNDED_AABB so they are never pre-rejected.

Replace the chord-sphere heuristic in Snapper::wire_in_range() with a proper
AABB vs snap-circle overlap test.  The new check is four scalar comparisons and
correctly handles closed curves (circles, arcs) which the chord-sphere approach
had to special-case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 12:21:51 +03:00

74 lines
1.8 KiB
Rust

// ZOOM WINDOW command — pick two corners to define the zoom area.
use glam::Vec3;
use crate::command::{CadCommand, CmdResult};
use crate::scene::wire_model::WireModel;
pub struct ZoomWindowCommand {
first: Option<Vec3>,
}
impl ZoomWindowCommand {
pub fn new() -> Self {
Self { first: None }
}
}
impl CadCommand for ZoomWindowCommand {
fn name(&self) -> &'static str {
"ZOOM WINDOW"
}
fn prompt(&self) -> String {
if self.first.is_none() {
"ZOOM WINDOW Specify first corner:".into()
} else {
"ZOOM WINDOW Specify opposite corner:".into()
}
}
fn on_point(&mut self, pt: Vec3) -> CmdResult {
if let Some(p1) = self.first {
CmdResult::ZoomToWindow { p1, p2: pt }
} else {
self.first = Some(pt);
CmdResult::NeedPoint
}
}
fn on_enter(&mut self) -> CmdResult {
CmdResult::Cancel
}
fn on_escape(&mut self) -> CmdResult {
CmdResult::Cancel
}
fn on_mouse_move(&mut self, pt: Vec3) -> Option<WireModel> {
let p1 = self.first?;
let min = p1.min(pt);
let max = p1.max(pt);
// Draw a rectangle preview
Some(WireModel {
name: "zoom_window_preview".into(),
points: vec![
[min.x, min.y, 0.0],
[max.x, min.y, 0.0],
[max.x, max.y, 0.0],
[min.x, max.y, 0.0],
[min.x, min.y, 0.0],
],
color: WireModel::CYAN,
selected: false,
pattern_length: 0.0,
pattern: [0.0; 8],
line_weight_px: 1.0,
snap_pts: vec![],
tangent_geoms: vec![],
aci: 0,
key_vertices: vec![],
aabb: WireModel::UNBOUNDED_AABB,
})
}
}