Files
OneCAD-Draft/tests/zoom_extents_xline.rs
T
Hakan SevenandClaude Opus 5.5 f537aff75c feat: node graph overlay; move to opencadcodec/opencadkernel/opencadgraph
The codec and kernel repositories and crates are renamed opencadcodec and
opencadkernel. Inside OCS they are depended on under short keys, so code
reads `codec::`, `kernel::` and the new `graph::` (opencadgraph, the node
graph engine). File-format and protocol spellings stay as they were: the
ACIS product id `acadrust`, the ACADRUST_* switches and the plugin
version keys `acadrust_version` / `acadrust_source`.

A button left of MCP on the command line opens a translucent node graph
over the viewport, with a palette of object, input, math, logic, list,
text and geometry nodes added by click or drag. An object node owns
drawing entities and its rows are the Properties panel's own rows for
them: the single-object page is extracted from refresh_properties as
entity_property_sections, values use the control protocol's
property_json, and writes go through set_property_value with a property
target override, so the panel, MCP and the graph share one read/write
path. A list reaching an object row makes one entity per element. Each
graph action is one undo step; the canvas pans and zooms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-25 07:34:23 +03:00

72 lines
2.3 KiB
Rust

// Regression for #284: ZOOM Extents must ignore the ±1e6 display segments
// that XLine/Ray tessellate into, instead of fitting the camera to them.
use codec::entities::{Line, XLine};
use codec::types::Vector3;
use codec::EntityType;
use OpenCADStudio::scene::Scene;
fn add_rect(scene: &mut Scene) {
let corners = [
(0.0, 0.0, 10.0, 0.0),
(10.0, 0.0, 10.0, 10.0),
(10.0, 10.0, 0.0, 10.0),
(0.0, 10.0, 0.0, 0.0),
];
for (x1, y1, x2, y2) in corners {
let mut line = Line::new();
line.start = Vector3::new(x1, y1, 0.0);
line.end = Vector3::new(x2, y2, 0.0);
scene.add_entity(EntityType::Line(line));
}
}
#[test]
fn fit_all_ignores_xline_display_extent() {
let mut scene = Scene::new();
add_rect(&mut scene);
// Construction line through the rectangle centre at 45° — its centroid
// sits inside the drawing cluster, and in a fresh document
// `local_extent_max` is still the 1e9 default, so before the fix both
// outlier rejects passed its ±1e6 display endpoints into the bounds.
let xl = XLine::new(Vector3::new(5.0, 5.0, 0.0), Vector3::new(1.0, 1.0, 0.0));
scene.add_entity(EntityType::XLine(xl));
scene.fit_all();
let cam = scene.camera.borrow();
assert!(
cam.distance.is_finite() && cam.distance < 1000.0,
"camera must fit the 10x10 rectangle, not the xline's 1e6 display \
segment (distance = {})",
cam.distance
);
assert!(
(cam.target.x - 5.0).abs() < 5.0 && (cam.target.y - 5.0).abs() < 5.0,
"camera target must stay on the rectangle (target = {:?})",
cam.target
);
}
#[test]
fn fit_all_with_only_xline_fits_base_point() {
let mut scene = Scene::new();
let xl = XLine::new(Vector3::new(100.0, 200.0, 0.0), Vector3::new(0.0, 1.0, 0.0));
scene.add_entity(EntityType::XLine(xl));
scene.fit_all();
let cam = scene.camera.borrow();
assert!(
cam.distance.is_finite() && cam.distance < 1000.0,
"xline-only drawing must fit near the base point, not ±1e6 \
(distance = {})",
cam.distance
);
assert!(
(cam.target.x - 100.0).abs() < 5.0 && (cam.target.y - 200.0).abs() < 5.0,
"camera target must be the xline base point (target = {:?})",
cam.target
);
}