fix(tolerance): complete workflow integration

Sync current main and companion codec changes before preserving unsupported frame rows, rendering in the entity plane, and sharing final layout metrics with placement preview.
This commit is contained in:
Hakan Seven authored and GitHub committed 2026-08-27 00:14:08 +03:00
1 parent 66bf4b1d5f
commit 81e7add1dd
65 files changed
+3708 -934

No files matched your search

+3 -1
View File
@@ -94,7 +94,9 @@ pub fn general_section(entity: &EntityType) -> PropSection {
],
};
if matches!(entity, EntityType::LwPolyline(polyline) if crate::entities::lwpolyline::is_rectangle(polyline))
if matches!(entity, EntityType::Text(_))
|| matches!(entity, EntityType::LwPolyline(polyline) if crate::entities::lwpolyline::is_rectangle(polyline))
|| matches!(entity, EntityType::MText(_))
|| matches!(entity, EntityType::Tolerance(_))
{
section.props.retain(|prop| prop.field != "handle");
+9
View File
@@ -24,6 +24,7 @@ pub struct TextStroke {
pub origin: [f64; 2],
pub color: Option<[f32; 3]>,
pub fill_tris: Vec<[f32; 2]>,
pub plane: Option<TextPlane>,
/// Layout inputs to rebuild this run as per-glyph SDF quads (see
/// `scene::text::glyph_quads`). `Some` on runs wired for the SDF text
/// renderer; `None` leaves the run to the stroke path only. Heights are
@@ -32,6 +33,14 @@ pub struct TextStroke {
pub run: Option<GlyphRun>,
}
#[derive(Clone, Copy, Debug)]
pub struct TextPlane {
pub origin: [f64; 3],
pub scale_origin: [f64; 3],
pub x_axis: [f64; 3],
pub y_axis: [f64; 3],
}
/// Per-run text-layout inputs needed to reproduce a run as SDF glyph quads.
#[derive(Clone, Debug)]
pub struct GlyphRun {
+1 -1
View File
@@ -528,7 +528,7 @@ fn tessellate_entity_inner(
if let EntityType::Viewport(vp) = e {
// The sheet viewport (overall/id=1) is never shown — it represents the
// paper boundary, not a user-defined content window.
if !Scene::is_content_viewport(vp) {
if Scene::is_sheet_viewport(document, vp) {
return vec![];
}
let is_active = active_viewport == Some(h);
+199 -54
View File
@@ -78,6 +78,81 @@ fn oriented_text_corners(
]
}
fn oriented_mtext_corner_groups(
verts: &[crate::scene::pipeline::text_gpu::TextVertex],
text: &acadrust::MText,
rotation: f64,
pad: f64,
annotation_scale: f64,
) -> Vec<[[f64; 2]; 4]> {
let columns = &text.column_data;
let count = crate::entities::text_support::clamp_mtext_column_count(columns.column_count)
as usize;
if columns.column_type == 0 || count <= 1 || columns.width <= 0.0 {
return vec![oriented_text_corners(
verts,
[text.insertion_point.x, text.insertion_point.y],
rotation,
pad,
)];
}
let width = columns.width * annotation_scale;
let gutter = columns.gutter.max(0.0) * annotation_scale;
let total_width = width * count as f64 + gutter * count.saturating_sub(1) as f64;
let anchor = match text.attachment_point {
acadrust::entities::mtext::AttachmentPoint::TopCenter
| acadrust::entities::mtext::AttachmentPoint::MiddleCenter
| acadrust::entities::mtext::AttachmentPoint::BottomCenter => 0.5,
acadrust::entities::mtext::AttachmentPoint::TopRight
| acadrust::entities::mtext::AttachmentPoint::MiddleRight
| acadrust::entities::mtext::AttachmentPoint::BottomRight => 1.0,
_ => 0.0,
};
let block_left = -anchor * total_width;
let origin = [text.insertion_point.x, text.insertion_point.y];
let (sin_r, cos_r) = rotation.sin_cos();
let mut bounds = vec![[f64::MAX, f64::MAX, f64::MIN, f64::MIN]; count];
for vertex in verts {
let x = vertex.pos[0] as f64 + vertex.pos_low[0] as f64 - origin[0];
let y = vertex.pos[1] as f64 + vertex.pos_low[1] as f64 - origin[1];
let local_x = x * cos_r + y * sin_r;
let local_y = -x * sin_r + y * cos_r;
let stride = width + gutter;
let physical = ((local_x - block_left) / stride)
.floor()
.clamp(0.0, count.saturating_sub(1) as f64) as usize;
bounds[physical][0] = bounds[physical][0].min(local_x);
bounds[physical][1] = bounds[physical][1].min(local_y);
bounds[physical][2] = bounds[physical][2].max(local_x);
bounds[physical][3] = bounds[physical][3].max(local_y);
}
let to_world = |x: f64, y: f64| {
[
origin[0] + x * cos_r - y * sin_r,
origin[1] + x * sin_r + y * cos_r,
]
};
bounds
.into_iter()
.filter(|bounds| bounds[0] <= bounds[2] && bounds[1] <= bounds[3])
.map(|bounds| {
let [left, bottom, right, top] = [
bounds[0] - pad,
bounds[1] - pad,
bounds[2] + pad,
bounds[3] + pad,
];
[
to_world(left, bottom),
to_world(right, bottom),
to_world(right, top),
to_world(left, top),
]
})
.collect()
}
pub(crate) fn explicit_mtext_background(entity: &EntityType) -> Option<[f32; 4]> {
let EntityType::MText(text) = entity else {
return None;
@@ -633,7 +708,14 @@ pub fn tessellate(
// stay a roughly constant on-screen size; otherwise the header-driven path.
let te = crate::entities::point::relative_render(entity, document, world_per_pixel)
.or_else(|| crate::entities::light::relative_render(entity, document, world_per_pixel))
.or_else(|| convert(entity, document));
.or_else(|| match entity {
EntityType::Text(text) => Some(crate::entities::text::to_render_at_scale(
text,
document,
anno_scale,
)),
_ => convert(entity, document),
});
if let Some(te) = te {
match te.object {
// ── Text / MText: pre-tessellated glyph strokes ───────────────
@@ -733,9 +815,32 @@ pub fn tessellate(
}
bin_first[bi] = false;
for &[x, y] in stroke {
let xv = x as f64 * anno + slx_v;
let yv = y as f64 * anno + sly_v;
let (h, l) = split_ds_xyz(xv, yv, elev_v);
let world = if let Some(plane) = group.plane {
let scaled_origin = [
plane.scale_origin[0]
+ (plane.origin[0] - plane.scale_origin[0]) * anno,
plane.scale_origin[1]
+ (plane.origin[1] - plane.scale_origin[1]) * anno,
plane.scale_origin[2]
+ (plane.origin[2] - plane.scale_origin[2]) * anno,
];
let x = x as f64 * anno;
let y = y as f64 * anno;
[
scaled_origin[0]
+ plane.x_axis[0] * x
+ plane.y_axis[0] * y,
scaled_origin[1]
+ plane.x_axis[1] * x
+ plane.y_axis[1] * y,
scaled_origin[2]
+ plane.x_axis[2] * x
+ plane.y_axis[2] * y,
]
} else {
[x as f64 * anno + slx_v, y as f64 * anno + sly_v, elev_v]
};
let (h, l) = split_ds_xyz(world[0], world[1], world[2]);
bins[bi].pts.push(h);
bins[bi].pts_low.push(l);
}
@@ -743,9 +848,32 @@ pub fn tessellate(
// 2. Process fill triangles
for &[x, y] in &group.fill_tris {
let xv = x as f64 * anno + slx_v;
let yv = y as f64 * anno + sly_v;
let (h, l) = split_ds_xyz(xv, yv, elev_v);
let world = if let Some(plane) = group.plane {
let scaled_origin = [
plane.scale_origin[0]
+ (plane.origin[0] - plane.scale_origin[0]) * anno,
plane.scale_origin[1]
+ (plane.origin[1] - plane.scale_origin[1]) * anno,
plane.scale_origin[2]
+ (plane.origin[2] - plane.scale_origin[2]) * anno,
];
let x = x as f64 * anno;
let y = y as f64 * anno;
[
scaled_origin[0]
+ plane.x_axis[0] * x
+ plane.y_axis[0] * y,
scaled_origin[1]
+ plane.x_axis[1] * x
+ plane.y_axis[1] * y,
scaled_origin[2]
+ plane.x_axis[2] * x
+ plane.y_axis[2] * y,
]
} else {
[x as f64 * anno + slx_v, y as f64 * anno + sly_v, elev_v]
};
let (h, l) = split_ds_xyz(world[0], world[1], world[2]);
bins[bi].fill_tris.push(h);
bins[bi].fill_tris_low.push(l);
}
@@ -793,14 +921,35 @@ pub fn tessellate(
run.bold,
&run.text,
);
crate::scene::pipeline::text_gpu::push_glyph_vertices(
&mut sdf_verts,
&quads,
[slx_v, sly_v, elev_v],
anno,
gcolor,
0.0,
);
if let Some(plane) = group.plane {
let scaled_origin = [
plane.scale_origin[0]
+ (plane.origin[0] - plane.scale_origin[0]) * anno,
plane.scale_origin[1]
+ (plane.origin[1] - plane.scale_origin[1]) * anno,
plane.scale_origin[2]
+ (plane.origin[2] - plane.scale_origin[2]) * anno,
];
crate::scene::pipeline::text_gpu::push_glyph_vertices_on_plane(
&mut sdf_verts,
&quads,
scaled_origin,
plane.x_axis,
plane.y_axis,
anno,
gcolor,
0.0,
);
} else {
crate::scene::pipeline::text_gpu::push_glyph_vertices(
&mut sdf_verts,
&quads,
[slx_v, sly_v, elev_v],
anno,
gcolor,
0.0,
);
}
}
}
}
@@ -849,11 +998,12 @@ pub fn tessellate(
.unwrap_or(m.rotation);
let text_height = m.height * anno;
let pad = (m.background_scale - 1.0).max(0.0) * text_height;
let corners = oriented_text_corners(
let corner_groups = oriented_mtext_corner_groups(
&sdf_verts,
[m.insertion_point.x, m.insertion_point.y],
m,
text_rotation,
pad,
anno,
);
// Fill / mask — two triangles behind the glyphs.
if has_fill {
@@ -862,13 +1012,18 @@ pub fn tessellate(
} else {
color_or_inherit(&m.background_color, bg_color)
};
let mut ft = Vec::with_capacity(6);
let mut ftl = Vec::with_capacity(6);
for &k in &[0usize, 1, 2, 0, 2, 3] {
let (h, lo) =
split_ds_xyz(corners[k][0], corners[k][1], elev_v);
ft.push(h);
ftl.push(lo);
let mut ft = Vec::with_capacity(6 * corner_groups.len());
let mut ftl = Vec::with_capacity(6 * corner_groups.len());
for corners in &corner_groups {
for &k in &[0usize, 1, 2, 0, 2, 3] {
let (h, lo) = split_ds_xyz(
corners[k][0],
corners[k][1],
elev_v,
);
ft.push(h);
ftl.push(lo);
}
}
wires.push(WireModel {
point_marker: None,
@@ -907,19 +1062,24 @@ pub fn tessellate(
// Text frame — a closed rectangle in the text
// colour around the same box.
if has_frame {
let loop_xy = [
corners[0],
corners[1],
corners[2],
corners[3],
corners[0],
];
let mut fp = Vec::with_capacity(5);
let mut fpl = Vec::with_capacity(5);
for &[x, y] in &loop_xy {
let (h, lo) = split_ds_xyz(x, y, elev_v);
fp.push(h);
fpl.push(lo);
let mut fp = Vec::with_capacity(6 * corner_groups.len());
let mut fpl = Vec::with_capacity(6 * corner_groups.len());
for (group_index, corners) in corner_groups.iter().enumerate() {
if group_index > 0 {
fp.push([f32::NAN; 3]);
fpl.push([0.0; 3]);
}
for &[x, y] in &[
corners[0],
corners[1],
corners[2],
corners[3],
corners[0],
] {
let (h, lo) = split_ds_xyz(x, y, elev_v);
fp.push(h);
fpl.push(lo);
}
}
wires.push(WireModel {
point_marker: None,
@@ -1718,24 +1878,9 @@ pub fn tessellate(
// f64 for the WireModel's double-single-era snap buffer.
let snap_pts: Vec<(glam::DVec3, SnapHint)> =
snap_pts.into_iter().map(|(p, h)| (p.as_dvec3(), h)).collect();
// A paper-space viewport is a window, not a wireframe: give it an interior
// pick surface so a click anywhere inside the frame selects it. Ranked
// below edge and fill hits, so content drawn inside still wins the click.
// The sheet ("overall") viewport is the layout's own invisible camera
// frame covering the whole page — never pickable, or it would swallow
// every click over the real viewports beneath it. It is identified by the
// Layout object's viewport link (authoritative — DWG files carry id = 0
// and this file class centres the sheet viewport off-origin, so neither
// the id nor the geometry heuristic alone is reliable), with
// `is_content_viewport` as the fallback classifier.
let is_sheet_vp = |vp: &acadrust::entities::Viewport| {
let h = vp.common.handle;
document.objects.values().any(|obj| {
matches!(obj, acadrust::objects::ObjectType::Layout(l) if l.viewport == h)
}) || !crate::scene::Scene::is_content_viewport(vp)
};
// Paper viewports are pickable inside their frames; the sheet viewport is not.
let (pick_tris, pick_tris_low) = match entity {
EntityType::Viewport(vp) if !is_sheet_vp(vp) => {
EntityType::Viewport(vp) if !crate::scene::Scene::is_sheet_viewport(document, vp) => {
if let Some(polygon) = clipped_viewport_polygon.as_ref() {
points_to_ds(crate::entities::mesh::triangulate_planar(polygon))
} else {
-4
View File
@@ -134,10 +134,6 @@ fn apply_text_defaults(doc: &CadDocument, entity: &mut EntityType) {
if text.oblique_angle.abs() <= 1.0e-9 {
text.oblique_angle = resolved.oblique_angle;
}
if text.generation_flags == 0 {
text.generation_flags = (if resolved.flags.backward { 2 } else { 0 })
| (if resolved.flags.upside_down { 4 } else { 0 });
}
}
EntityType::MText(text) => {
if resolved.height > 1.0e-9 {
+4 -1
View File
@@ -203,8 +203,11 @@ impl Scene {
/// If any handle belongs to a selectable group, also select every member.
pub fn expand_selection_for_groups(&mut self, handles: &[Handle]) {
let previous_len = self.selected.len();
self.selected
.extend(self.handles_expanded_for_selectable_groups(handles));
self.bump_selection();
if self.selected.len() != previous_len {
self.bump_selection_set();
}
}
}
+116 -78
View File
@@ -1486,6 +1486,9 @@ pub struct Scene {
/// pick only refreshes the GPU xray overlay (cheap) instead of bumping
/// `geometry_epoch` and re-tessellating the whole model.
pub selection_generation: u64,
/// Cached fingerprint of `selected`, recomputed lazily after mutations.
selection_fingerprint_cache: u64,
selection_fingerprint_dirty: bool,
/// Cached tessellation of all visible entity wires for the current layout.
/// Keyed by `(geometry_epoch, camera_generation)` so a camera change
/// invalidates the cull-dependent wire list as well as a geometry change.
@@ -1865,6 +1868,8 @@ impl Scene {
projection_bounds_epoch: std::cell::Cell::new(0),
block_epoch: GEOMETRY_EPOCH.fetch_add(1, Ordering::Relaxed),
selection_generation: 0,
selection_fingerprint_cache: 0,
selection_fingerprint_dirty: false,
wire_cache: RefCell::new(None),
interaction_index_cache: RefCell::new(Vec::new()),
interaction_index_pending_key: std::cell::Cell::new(None),
@@ -2618,6 +2623,11 @@ impl Scene {
self.selection_generation = self.selection_generation.wrapping_add(1);
}
pub(crate) fn bump_selection_set(&mut self) {
self.selection_fingerprint_dirty = true;
self.bump_selection();
}
/// Milliseconds after the last camera change during which the view counts as
/// "actively navigating" for interaction-LOD purposes.
const NAV_SETTLE_MS: u128 = 130;
@@ -2998,32 +3008,96 @@ impl Scene {
crate::io::set_saved_active_layout(&mut self.document, &self.current_layout);
}
/// Returns true if this viewport should display model-space content
/// (i.e. it is a user viewport, not the sheet/overall viewport).
///
/// Rules:
/// - id=1 → always the sheet viewport → false
/// - id≥2 → always a user viewport → true
/// - id=0 or id<0 (DWG reader omits the id; some DXF exporters write -1):
/// use geometry: the sheet viewport is centred at the paper origin (0,0)
/// with scale≈1.0 (view_height ≈ paper-space height).
pub fn is_content_viewport(vp: &acadrust::entities::Viewport) -> bool {
if vp.id == 1 {
return false;
pub(crate) fn layout_sheet_viewport_handle(
document: &acadrust::CadDocument,
layout: &acadrust::objects::Layout,
) -> Handle {
let owned_viewport = |handle| match document.get_entity(handle) {
Some(EntityType::Viewport(vp)) if vp.common.owner_handle == layout.block_record => {
Some(vp)
}
_ => None,
};
let listed = layout
.viewports
.iter()
.copied()
.filter_map(|handle| owned_viewport(handle).map(|vp| (handle, vp)));
if let Some((handle, _)) = listed.clone().find(|(_, vp)| vp.id == 1) {
return handle;
}
if vp.id > 1 {
if let Some((handle, _)) = listed.into_iter().next() {
return handle;
}
let block_handles = document
.block_records
.iter()
.find(|block| block.handle == layout.block_record)
.map(|block| block.entity_handles.as_slice())
.unwrap_or_default();
let block_viewports = block_handles
.iter()
.copied()
.filter_map(|handle| owned_viewport(handle).map(|vp| (handle, vp)));
if let Some((handle, _)) = block_viewports.clone().find(|(_, vp)| vp.id == 1) {
return handle;
}
if let Some((handle, _)) = block_viewports.into_iter().next() {
return handle;
}
document
.entities()
.filter_map(|entity| match entity {
EntityType::Viewport(vp) if vp.common.owner_handle == layout.block_record => {
Some((
vp.common.handle,
vp.id == 1,
vp.width.abs() * vp.height.abs(),
))
}
_ => None,
})
.max_by(|a, b| a.1.cmp(&b.1).then_with(|| a.2.total_cmp(&b.2)))
.map(|(handle, _, _)| handle)
.unwrap_or(Handle::NULL)
}
pub(crate) fn is_sheet_viewport(
document: &acadrust::CadDocument,
vp: &acadrust::entities::Viewport,
) -> bool {
if vp.id == 1 {
return true;
}
// id ≤ 0: DWG files never write group-code 69 (viewport id), so all
// viewports arrive with id=0.
//
// In DWG format the sheet ("overall") viewport always has its center at
// the paper-space origin (0, 0). Content viewports are placed at their
// actual position on the paper and therefore have a non-zero center.
// Using center position is more reliable than a scale heuristic because
// the sheet viewport's scale is not always exactly 1:1 (observed: 0.8965
// in real-world files, which the old 0.02 tolerance missed entirely).
vp.center.x.abs() >= 0.5 || vp.center.y.abs() >= 0.5
if vp.id > 1 {
return false;
}
document.objects.values().any(|object| {
matches!(
object,
ObjectType::Layout(layout)
if layout.block_record == vp.common.owner_handle
&& Self::layout_sheet_viewport_handle(document, layout)
== vp.common.handle
)
})
}
pub(crate) fn sheet_viewport_handles(&self) -> std::collections::HashSet<Handle> {
self.document
.objects
.values()
.filter_map(|object| match object {
ObjectType::Layout(layout) => {
let handle = Self::layout_sheet_viewport_handle(&self.document, layout);
handle.is_valid().then_some(handle)
}
_ => None,
})
.collect()
}
fn current_layout_sheet_viewport_handle(&self) -> Handle {
@@ -3035,7 +3109,7 @@ impl Scene {
return None;
};
if layout.name == self.current_layout {
Some(layout.viewport)
Some(Self::layout_sheet_viewport_handle(&self.document, layout))
} else {
None
}
@@ -3043,82 +3117,49 @@ impl Scene {
.unwrap_or(Handle::NULL)
}
/// Guarantee that a paper layout has its full-screen overall (`id == 1`)
/// sheet viewport. `add_layout` creates it; this is a safety net for layouts
/// that arrive without it. The sheet
/// viewport is the authoritative paper-space view and the canvas every
/// floating viewport overlays.
/// Ensure a paper layout has its overall (`id == 1`) viewport.
pub fn ensure_sheet_viewport(&mut self, layout_name: &str) {
if layout_name == "Model" {
return;
}
// Locate the layout: its object handle, block-record handle, current
// sheet-viewport link, and paper limits.
// Locate the layout and its paper limits.
let info = self.document.objects.iter().find_map(|(h, obj)| {
if let ObjectType::Layout(l) = obj {
if l.name == layout_name {
return Some((*h, l.block_record, l.viewport, l.min_limits, l.max_limits));
return Some((
*h,
l.block_record,
Self::layout_sheet_viewport_handle(&self.document, l),
l.min_limits,
l.max_limits,
));
}
}
None
});
let Some((layout_handle, block_record, cur_vp, min_lim, max_lim)) = info else {
let Some((layout_handle, block_record, sheet, min_lim, max_lim)) = info else {
return;
};
if block_record.is_null() {
return;
}
// Normal files carry a valid direct Layout→Viewport link. This O(1)
// path is hit on every ordinary layout-tab switch.
if cur_vp.is_valid()
if sheet.is_valid()
&& matches!(
self.document.get_entity(cur_vp),
self.document.get_entity(sheet),
Some(EntityType::Viewport(vp)) if vp.common.owner_handle == block_record
)
{
return;
}
// Already present? Accept either the linked viewport handle or any
// `id == 1` viewport owned by the layout block.
let has_sheet = self.document.entities().any(|e| {
matches!(e, EntityType::Viewport(vp)
if vp.common.owner_handle == block_record
&& (vp.id == 1 || vp.common.handle == cur_vp))
});
if has_sheet {
// Keep the layout's link in sync if it was missing.
if !cur_vp.is_valid() {
let h = self.document.entities().find_map(|e| match e {
EntityType::Viewport(vp)
if vp.common.owner_handle == block_record && vp.id == 1 =>
{
Some(vp.common.handle)
}
_ => None,
});
if let Some(h) = h {
if let Some(ObjectType::Layout(l)) =
self.document.objects.get_mut(&layout_handle)
{
l.viewport = h;
}
}
}
return;
}
// Create the full-screen overall viewport covering the paper limits.
let pw = (max_lim.0 - min_lim.0).abs().max(1.0);
let ph = (max_lim.1 - min_lim.1).abs().max(1.0);
let mut vp = acadrust::entities::Viewport::new();
vp.id = 1;
vp.status = acadrust::entities::ViewportStatusFlags::default_on();
// Paper-space center is a 2D (x, y) point with z = 0. Putting the
// paper-height midpoint in z
// (with y = 0) left the sheet view centered at y = 0, shifting the whole
// layout half a page down. See issue #156.
// Paper-space center is an (x, y) point with z = 0.
vp.center = acadrust::types::Vector3::new(
(min_lim.0 + max_lim.0) / 2.0,
(min_lim.1 + max_lim.1) / 2.0,
@@ -3126,12 +3167,7 @@ impl Scene {
);
vp.width = pw;
vp.height = ph;
// Frame the new layout on the whole sheet: look straight down at the
// paper centre with the visible height a touch taller than the page.
// Without this the viewport keeps `Viewport::new`'s default view
// (target 0,0 / height 210), so the first time a fresh drawing's
// layout is opened the camera sits on the paper's bottom-left corner
// instead of centring the sheet.
// Frame the full sheet with a small margin.
vp.view_target = acadrust::types::Vector3::new(
(min_lim.0 + max_lim.0) / 2.0,
(min_lim.1 + max_lim.1) / 2.0,
@@ -3144,7 +3180,8 @@ impl Scene {
.add_entity_to_layout(EntityType::Viewport(vp), layout_name)
{
if let Some(ObjectType::Layout(l)) = self.document.objects.get_mut(&layout_handle) {
l.viewport = handle;
l.viewports.retain(|candidate| *candidate != handle);
l.viewports.insert(0, handle);
}
}
}
@@ -3161,7 +3198,7 @@ impl Scene {
if sheet_handle.is_valid() {
vp.common.handle != sheet_handle
} else {
Self::is_content_viewport(vp)
!Self::is_sheet_viewport(&self.document, vp)
}
}
@@ -4555,6 +4592,7 @@ impl Scene {
.extend(self.selected.iter().copied());
self.selected.clear();
self.selected_order.clear();
self.bump_selection_set();
self.bump_entities(&changes);
}
+1 -1
View File
@@ -29,7 +29,7 @@ impl Scene {
&& if sheet.is_valid() {
handle != sheet
} else {
Self::is_content_viewport(vp)
!Self::is_sheet_viewport(&self.document, vp)
}
};
let content = if let Some(block) = self
+45
View File
@@ -151,6 +151,51 @@ pub fn push_glyph_vertices(
}
}
#[allow(clippy::too_many_arguments)]
pub fn push_glyph_vertices_on_plane(
out: &mut Vec<TextVertex>,
quads: &[GlyphQuad],
origin: [f64; 3],
x_axis: [f64; 3],
y_axis: [f64; 3],
anno: f64,
color: [f32; 4],
draw_depth: f32,
) {
for q in quads {
let mk = |ci: usize, uv: [f32; 2]| -> TextVertex {
let c = q.corners[ci];
let x = c[0] as f64 * anno;
let y = c[1] as f64 * anno;
let world = [
origin[0] + x_axis[0] * x + y_axis[0] * y,
origin[1] + x_axis[1] * x + y_axis[1] * y,
origin[2] + x_axis[2] * x + y_axis[2] * y,
];
let (xh, xl) = split_ds(world[0]);
let (yh, yl) = split_ds(world[1]);
let (zh, zl) = split_ds(world[2]);
TextVertex {
pos: [xh, yh, zh],
pos_low: [xl, yl, zl],
uv,
color,
draw_depth,
}
};
let bl = [q.uv_min[0], q.uv_max[1]];
let br = [q.uv_max[0], q.uv_max[1]];
let tr = [q.uv_max[0], q.uv_min[1]];
let tl = [q.uv_min[0], q.uv_min[1]];
out.push(mk(0, bl));
out.push(mk(1, br));
out.push(mk(2, tr));
out.push(mk(0, bl));
out.push(mk(2, tr));
out.push(mk(3, tl));
}
}
/// Slide every glyph vertex by a world-space delta, re-splitting the
/// double-single position. Lets a grip drag move already-shaped text by
/// translating the drag-start glyphs each frame instead of re-tessellating
+67 -10
View File
@@ -1,6 +1,9 @@
// Auto-split from scene/mod.rs. Pure text-move; behaviour unchanged.
use super::*;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
impl Scene {
// ── Selection ─────────────────────────────────────────────────────────
/// Treat a classic LEADER and its attached annotation as one logical object.
@@ -37,8 +40,11 @@ impl Scene {
}
pub fn select_entity(&mut self, handle: Handle, exclusive: bool) {
let handles = self.handles_expanded_for_leader_annotations(&[handle]);
let mut changed = false;
if exclusive {
changed = self.selected.len() != handles.len()
|| handles.iter().any(|handle| !self.selected.contains(handle));
self.selected.clear();
self.selected_order.clear();
}
@@ -46,15 +52,35 @@ impl Scene {
for handle in handles {
if self.selected.insert(handle) {
self.selected_order.push(handle);
changed = true;
}
}
self.bump_selection();
if changed {
self.bump_selection_set();
}
}
pub fn deselect_all(&mut self) {
if self.selected.is_empty() {
return;
}
self.selected.clear();
self.selected_order.clear();
self.bump_selection();
self.bump_selection_set();
}
pub(crate) fn selection_fingerprint(&mut self) -> u64 {
if self.selection_fingerprint_dirty {
let mut fingerprint = self.selected.len() as u64;
for handle in &self.selected {
let mut hasher = DefaultHasher::new();
handle.hash(&mut hasher);
fingerprint ^= hasher.finish();
}
self.selection_fingerprint_cache = fingerprint;
self.selection_fingerprint_dirty = false;
}
self.selection_fingerprint_cache
}
pub(crate) fn selected_handles_in_order(&self) -> Vec<Handle> {
@@ -103,7 +129,7 @@ impl Scene {
order.extend(added);
self.selected = selected;
self.selected_order = order;
self.bump_selection();
self.bump_selection_set();
}
}
@@ -118,7 +144,7 @@ impl Scene {
}
if changed {
self.bump_selection();
self.bump_selection_set();
}
}
@@ -199,7 +225,7 @@ impl Scene {
}
}
if added > 0 {
self.bump_selection();
self.bump_selection_set();
}
added
}
@@ -223,7 +249,9 @@ impl Scene {
self.selected_order.push(h);
}
}
self.bump_selection();
if self.selected != prev {
self.bump_selection_set();
}
self.selected.len()
}
@@ -709,7 +737,8 @@ impl Scene {
let mut handle_set: HashSet<Handle> = HashSet::default();
let mut erased: Vec<(Handle, ChangeKind)> = Vec::new();
let mut highlight_changed = false;
let mut selection_changed = false;
let mut hover_changed = false;
for &h in &erase_handles {
// Objects on a locked layer can't be erased.
@@ -724,11 +753,11 @@ impl Scene {
self.delete_solid_history(h);
self.remember_removed_cache_categories(h);
self.document.remove_entity_arc(h);
highlight_changed |= self.selected.remove(&h);
selection_changed |= self.selected.remove(&h);
self.selected_order.retain(|selected| *selected != h);
if self.hover_highlight == Some(h) {
self.hover_highlight = None;
highlight_changed = true;
hover_changed = true;
}
self.hatches.remove(&h);
self.images.remove(&h);
@@ -738,7 +767,9 @@ impl Scene {
handle_set.insert(h);
erased.push((h, ChangeKind::Removed));
}
if highlight_changed {
if selection_changed {
self.bump_selection_set();
} else if hover_changed {
self.bump_selection();
}
// Capture exactly the group objects that this erase will rewrite, plus
@@ -838,3 +869,29 @@ impl Scene {
restored
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn selection_fingerprint_tracks_final_set_only() {
let mut scene = Scene::default();
let first = Handle::new(1);
let second = Handle::new(2);
scene.select_entity(first, false);
scene.select_entity(second, false);
let fingerprint = scene.selection_fingerprint();
assert!(!scene.selection_fingerprint_dirty);
scene.deselect_all();
scene.select_entity(second, false);
scene.select_entity(first, false);
assert!(scene.selection_fingerprint_dirty);
assert_eq!(scene.selection_fingerprint(), fingerprint);
scene.set_hover_highlight(Some(Handle::new(3)));
assert!(!scene.selection_fingerprint_dirty);
assert_eq!(scene.selection_fingerprint(), fingerprint);
}
}