Select: a blank MTEXT's frame follows layout orientation, and its insertion points keep it a snap candidate only when INS is on and within the aperture (#2810)

A top-level MTEXT with a non-zero AcadAnnoPO value is drawn upright, so its pick frame no longer turns with the stored rotation. Insertion points now keep a blank frame in the snap pool only when INS is enabled and the point is within the aperture circle, not just the square probe.
This commit is contained in:
SBaksa
2026-11-12 00:05:58 +11:00
parent cf9f3a7ea3
commit 72f07e5cd1
2 changed files with 67 additions and 7 deletions
+24 -6
View File
@@ -220,7 +220,10 @@ fn blank_mtext_frame(d: &Drawing, e: &Entity) -> Option<(Vec2, f64, [f64; 4])> {
7..=9 => h,
_ => 0.0,
};
Some((insert, t.rotation, [dx, dx + w, top - h, top]))
// A top-level MTEXT that matches the layout orientation is drawn and measured upright, as the
// renderer and the extents do; a multileader keeps the stored rotation of its text.
let rotation = if matches!(e.kind, EntityKind::MText(_)) && e.common.matches_layout_orientation() { 0.0 } else { t.rotation };
Some((insert, rotation, [dx, dx + w, top - h, top]))
}
/// The box around a blank MTEXT's turned frame (a top-level MTEXT or a multileader's MTEXT
@@ -263,12 +266,13 @@ fn blank_snap_points(e: &Entity) -> Vec<Vec2> {
}
/// Whether `e` is within reach of a snap probe only through its blank MTEXT frame: the drawn
/// geometry (expanded by `aperture`) misses `probe` and none of the insertion points INS offers
/// (text or block content) is inside it. Such an entity is for picking and selection, not a snap
/// candidate.
pub(crate) fn blank_frame_only(d: &Drawing, e: &Entity, probe: &Bounds2, aperture: f64) -> bool {
/// geometry (expanded by `aperture`) misses `probe`, and no insertion point INS would offer (text
/// or block content) is a candidate: one counts only when `ins` is on and it is within `aperture`
/// of `cursor`, the distance snap accepts a candidate by (a corner of the square probe is not).
/// Such an entity is for picking and selection, not a snap candidate.
pub(crate) fn blank_frame_only(d: &Drawing, e: &Entity, probe: &Bounds2, cursor: Vec2, aperture: f64, ins: bool) -> bool {
let points = blank_snap_points(e);
!points.is_empty() && !points.iter().any(|p| probe.contains(*p)) && !entity_bounds(d, e, 0).expand(aperture).intersects(probe)
!points.is_empty() && !(ins && points.iter().any(|p| p.dist(cursor) <= aperture)) && !entity_bounds(d, e, 0).expand(aperture).intersects(probe)
}
pub(crate) fn bounds_of(d: &Drawing, e: &Entity, known: Option<Bounds2>) -> Bounds2 {
@@ -820,6 +824,20 @@ mod tests {
assert_eq!(at(&d, 5.0, -1.0), None);
}
/// A top-level MTEXT that matches the layout orientation is drawn upright, ignoring its stored
/// rotation, so its frame is the unturned one (the renderer and the extents do the same).
#[test]
fn rotated_blank_mtext_matching_layout_orientation_is_picked_in_its_unrotated_frame() {
let mut d = Drawing::new_metric();
let tag = |code: i32, value: &str| cadcraft_doc::RawTag { code, value: value.into() };
let common = Common { xdata: vec![tag(1001, "AcadAnnoPO"), tag(1070, "1")], ..Common::default() };
let h = d.add(&Space::Model, common, mtext_at(" ", 1, std::f64::consts::FRAC_PI_2)).unwrap();
let at = |x: f64, y: f64| pick(&d, &Space::Model, Vec2::new(x, y), 0.05);
// Unrotated frame x 0..10, y -2.5..0; the rotated one would be x 0..2.5, y 0..10.
assert_eq!(at(5.0, -1.0), Some(h), "inside the unrotated frame");
assert_eq!(at(1.0, 5.0), None, "inside only the rotated frame");
}
/// A turned blank MTEXT is hit in its turned box, not in the axis-aligned box around it (whose
/// empty corners lie off the text).
#[test]
+43 -1
View File
@@ -425,7 +425,7 @@ fn gather_in(
}
// A blank MTEXT frame covering the cursor is for picking: it neither uses up the candidate
// limit nor the intersection slots unless its insertion point or drawn geometry is in reach.
if !inf && crate::select::blank_frame_only(d, e, &probe, aperture) {
if !inf && crate::select::blank_frame_only(d, e, &probe, cursor, aperture, osmode & mode::INS != 0) {
continue;
}
count += 1;
@@ -1131,6 +1131,48 @@ mod tests {
}
}
/// 2001 blank MTEXT frames covering `cursor` (insertion points at `ins_at`), drawn before a
/// LINE whose end is at `cursor`: the END snap found with `osmode`.
fn crowded_blank_frames_end_snap(ins_at: Vec2, cursor: Vec2, aperture: f64, osmode: u32) -> Option<Vec2> {
let mut d = Drawing::new_metric();
for _ in 0..2001 {
let t = cadcraft_doc::MText {
insert: Vec3::new(ins_at.x, ins_at.y, 0.0),
height: 2.5,
width: 10.0,
attach: 1,
rotation: 0.0,
style: "Standard".into(),
contents: " ".into(),
line_spacing: 1.0,
line_spacing_exact: false,
columns: None,
};
d.add(&Space::Model, Common::default(), EntityKind::MText(t)).unwrap();
}
d.add(&Space::Model, Common::default(), EntityKind::Line(Line { a: Vec3::new(cursor.x, cursor.y, 0.0), b: Vec3::new(30.0, cursor.y, 0.0) }))
.unwrap();
osnap(&d, &Space::Model, cursor, aperture, osmode, None, false).map(|h| h.point)
}
/// An insertion point in a corner of the square probe is farther than the aperture from the
/// cursor, so snap would never accept it: its frame must not crowd out an END snap.
#[test]
fn blank_insertion_points_in_the_probe_corner_do_not_crowd_out_an_end_snap() {
let cursor = Vec2::new(5.0, -1.0);
let ap = 0.5;
let corner = Vec2::new(cursor.x - 0.9 * ap, cursor.y + 0.9 * ap);
assert!(corner.dist(cursor) > ap, "outside the circle, inside the square probe");
assert_eq!(crowded_blank_frames_end_snap(corner, cursor, ap, mode::END | mode::INS), Some(cursor));
}
/// With INS off a blank MTEXT's insertion point is no snap candidate, even right at the cursor.
#[test]
fn blank_insertion_points_with_ins_off_do_not_crowd_out_an_end_snap() {
let cursor = Vec2::new(5.0, -1.0);
assert_eq!(crowded_blank_frames_end_snap(cursor, cursor, 0.5, mode::END), Some(cursor));
}
/// A blank annotative multileader (text 6 right of its landing, 4 x 2, at 1:2) among 2100 blank
/// MTEXT frames over the cursor. `block_at` also gives it a block content at that offset from
/// the landing. Returns the INS snap at `landing + probe` (aperture 0.5).