feat(domain): per-view minimum point radius in preview state

PreviewState.min_point_radius maps a view id to the smallest point
hitbox radius that passes TooSmall on the smallest preview, so the
sheet editor can mark it on a size slider. Twin constants named in
layer.rs; frame.rs shares one first-view drawing lookup.
This commit is contained in:
bchanot committed 2026-11-17 16:33:40 +01:00
1 parent 56c75b12ef
commit 5ca2b7e3ad
8 files changed
+202 -9

No files matched your search

+42 -7
View File
@@ -20,8 +20,10 @@
//! Owner brief 2026-11-01 (the last MEDIUM, zone without interior): a polygon or a path must
//! also fill a disc of `MIN_VISIBLE_PX` on that preview (`interior`), its stroke left out.
use std::collections::BTreeMap;
use super::interior::{Budget, LAYER_FILL_RULE, Search, geometry_outline, widest_disc};
use super::layer::{find_view, twin_radius};
use super::layer::{TWIN_INSET, TWIN_MIN_RADIUS, find_view, twin_radius};
use super::path::{Bounds, number_list, path_bounds};
use super::svg::Element;
use crate::domain::sheet::{AnatomicalSheetDocument, Annotation, Geometry, SheetView};
@@ -227,6 +229,31 @@ pub fn annotation_placement(
}
}
/// The smallest hitbox radius of a point (a circle that is not a trigger) that passes
/// `TooSmall` in a view with this frame, rounded up to 0.01; `None` when every positive radius
/// passes (preview scale of 1 or more: the twin's 2-unit floor already shows 4 px).
pub fn min_point_radius(frame: &Frame, main_view: bool) -> Option<f64> {
let half_disc = MIN_VISIBLE_PX / 2.0 / frame.preview_scale(main_view);
// `twin_radius(r) = max(2, r - 12)`: below the floor no radius is too small.
(half_disc > TWIN_MIN_RADIUS).then(|| ((TWIN_INSET + half_disc) * 100.0).ceil() / 100.0)
}
/// The minimum point radius of each view whose frame is usable and which has one, by view id.
pub fn min_point_radii<'a>(
document: &AnatomicalSheetDocument,
drawing_of: impl Fn(&str) -> Option<&'a Element>,
) -> BTreeMap<String, f64> {
document
.views
.iter()
.filter_map(|view| {
let drawing = first_view_drawing(document, view, &drawing_of)?;
let radius = min_point_radius(&view_frame(view, drawing)?, view.is_main())?;
Some((view.id().to_owned(), radius))
})
.collect()
}
/// Whether the fill of a polygon or a path holds a disc of `MIN_VISIBLE_PX` at `scale` CSS px
/// per unit; a circle's disc is its own. A path without an outline is refused (the bounds and
/// the outline share one reader, so it does not happen).
@@ -274,12 +301,7 @@ pub fn frame_faults<'a>(
let mut faults = Vec::new();
let mut budget = Budget::default();
for (view_index, view) in document.views.iter().enumerate() {
// A repeated view id draws the first view of that id, as the composers find it.
if !find_view(document, view.id()).is_some_and(|first| std::ptr::eq(first, view)) {
continue;
}
let drawing = super::compose::asset_id_of_view(document, view.id()).and_then(&drawing_of);
let Some(drawing) = drawing else {
let Some(drawing) = first_view_drawing(document, view, &drawing_of) else {
continue;
};
let Some(frame) = view_frame(view, drawing) else {
@@ -291,6 +313,19 @@ pub fn frame_faults<'a>(
faults
}
/// The drawing `view` is drawn on, when it is the first view of its id (a repeated view id draws
/// the first view of that id, as the composers find it) and its drawing is given.
fn first_view_drawing<'a>(
document: &AnatomicalSheetDocument,
view: &SheetView,
drawing_of: &impl Fn(&str) -> Option<&'a Element>,
) -> Option<&'a Element> {
if !find_view(document, view.id()).is_some_and(|first| std::ptr::eq(first, view)) {
return None;
}
super::compose::asset_id_of_view(document, view.id()).and_then(drawing_of)
}
fn annotation_faults(
document: &AnatomicalSheetDocument,
view: &SheetView,
+6 -1
View File
@@ -256,9 +256,14 @@ impl Context<'_> {
}
}
/// The smallest radius of a point's visible twin, in view units.
pub const TWIN_MIN_RADIUS: f64 = 2.0;
/// How much smaller than its hitbox a point's visible twin is drawn, in view units.
pub const TWIN_INSET: f64 = 12.0;
/// The radius of a point's visible twin, drawn on its hitbox of radius `r`.
pub fn twin_radius(r: f64) -> f64 {
2.0_f64.max(r - 12.0)
TWIN_MIN_RADIUS.max(r - TWIN_INSET)
}
/// A trigger without a name of its own takes the opened view's name in each language
+8
View File
@@ -25,6 +25,7 @@ use super::report::{SheetReport, frame_issues, referenced_asset_ids, sheet_repor
use super::review::DigestError;
use super::schema::{AnatomicalSheetDocument, LocalizedText};
use super::verdict::{read_document, sha256_hex};
use crate::anatomy::frame::min_point_radii;
use crate::anatomy::svg::processing_instructions;
use crate::anatomy::svg::serialize::stored_form;
use crate::domain::archive::SnapshotCaps;
@@ -284,6 +285,9 @@ impl PreviewSheet {
fingerprint: self.fingerprint.clone(),
drawings: self.drawing_states(),
index: preview_index(&self.document),
min_point_radius: min_point_radii(&self.document, |id| {
self.drawing(id).and_then(|d| d.as_ref().ok())
}),
report,
document: self.document.clone(),
})
@@ -365,6 +369,10 @@ pub struct PreviewState {
pub report: SheetReport,
pub drawings: Vec<PreviewDrawingState>,
pub index: Option<PreviewIndex>,
/// The smallest hitbox radius of a point in each view, by view id: the radius whose visible
/// disc just passes the minimum size on the smallest preview. Absent for a view without a
/// usable frame or drawing, and for one where every radius passes.
pub min_point_radius: BTreeMap<String, f64>,
/// The document as read (defaults filled in).
pub document: AnatomicalSheetDocument,
}