Drawing sheets: centring marks across the whole margin (#3875) (#5554)

The built-in sheet's centring marks now run from the trimmed sheet's edge to the drawing border.
From the grid reference border, as before, a mark was the same length as a grid field mark, and on
A3 it sat on one (the sheet's centre falls on a field edge), so it no longer read as a mark once the
grid reference border's outline is left out (Cameron, after the prototype on #3875).

- DrawingBorderProfile.centring_mark_start: sheet_edge (the built-in's, and when not given) or
  grid_border (ISO 5457's figure 5); ISO's full border in the tests asks for grid_border.
- A mark still needs a length: one that stops on the drawing border needs room outside it on the
  side it starts from, every margin for sheet_edge, the grid reference border for grid_border.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
CamWightandClaude Opus 5.5 authored and GitHub committed 2026-10-23 11:48:17 -04:00
1 parent 5e23f58f62
commit 4c63a88fc3
2 files changed
+87 -34

No files matched your search

+39 -14
View File
@@ -16,12 +16,12 @@
//! fields taking what is left. Rows are lettered from the top without I and O and columns numbered
//! from the left, on the sides [`LabelSides::Iso`] gives: the top and right of an A4 sheet, every
//! side of the others. The labels sit between the drawing border and the grid reference border,
//! 5 mm outside it. A centring mark runs from the grid reference border to the drawing border at
//! each end of the sheet's centre lines, never into the drawing area.
//! 5 mm outside it. A centring mark runs across the whole margin, from the trimmed sheet's edge to
//! the drawing border, at each end of the sheet's centre lines, never into the drawing area.
//!
//! The rest of ISO 5457's border is a choice in the profile: the 20 mm filing margin on the left,
//! for drawings that get bound; centring marks that reach inside the drawing border (10 mm in the
//! standard's figure); and a trimming mark at each corner, outside the grid reference border, of
//! for drawings that get bound; centring marks that start at the grid reference border and reach
//! inside the drawing border (10 mm in the standard's figure); and a trimming mark at each corner, outside the grid reference border, of
//! two overlapping 10 x 5 mm rectangles. The built-in profile leaves the trimming marks out, as
//! they take a lot of ink.
//!
@@ -231,12 +231,27 @@ pub struct DrawingBorderProfile {
/// How far each centring mark reaches inside the drawing border, 0 to stop it on the drawing
/// border (`None`: no centring marks).
pub centring_mark_mm: Option<f64>,
/// Where each centring mark starts outside the drawing border. The trimmed sheet's edge when not
/// given.
#[serde(default)]
pub centring_mark_start: CentringMarkStart,
/// The trimming mark's rectangles: their length along the sheet border and their width into
/// the sheet, which must leave them outside the grid reference border (`None`: no trimming
/// marks).
pub trimming_mark_mm: Option<[f64; 2]>,
}
/// Where a centring mark starts, outside the drawing border.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CentringMarkStart {
/// The trimmed sheet's edge, so the mark runs across the whole margin (the built-in sheet's).
#[default]
SheetEdge,
/// The grid reference border, as ISO 5457's figure 5 draws it.
GridBorder,
}
/// One reference field along its axis: `from_mm < to_mm` in sheet coordinates.
#[derive(Clone, Debug, PartialEq)]
pub struct Field {
@@ -311,6 +326,7 @@ impl DrawingBorderProfile {
label_sides: LabelSides::Iso,
grid_border_mm: 5.0,
centring_mark_mm: Some(0.0),
centring_mark_start: CentringMarkStart::SheetEdge,
trimming_mark_mm: None,
}
}
@@ -349,7 +365,11 @@ impl DrawingBorderProfile {
if let Some(reach) = self.centring_mark_mm {
require(reach.is_finite() && reach >= 0.0, "a centring mark ends on the drawing border or inside it")?;
// Else it would start and end on the drawing border.
require(g > 0.0 || reach > 0.0, "a centring mark needs a grid reference border to start from or a reach inside the drawing border")?;
let outside = match self.centring_mark_start {
CentringMarkStart::SheetEdge => narrowest,
CentringMarkStart::GridBorder => g,
};
require(outside > 0.0 || reach > 0.0, "a centring mark needs room outside the drawing border to start from, or a reach inside it")?;
}
if let Some([length, width]) = self.trimming_mark_mm {
require(length.is_finite() && width > 0.0 && width <= length, "a trimming mark is finite, above 0 and no wider than it is long")?;
@@ -383,9 +403,14 @@ impl DrawingBorderProfile {
for (i, row) in rows.iter_mut().enumerate() {
row.label = letters(i, self.skip_i_and_o);
}
let sheet_border = Aabb2 { min: Vec2::ZERO, max: size };
let grid_border = drawing_border.inflated(self.grid_border_mm);
let start = match self.centring_mark_start {
CentringMarkStart::SheetEdge => sheet_border,
CentringMarkStart::GridBorder => grid_border,
};
let centring_marks = match self.centring_mark_mm {
Some(reach) => centring_marks(grid_border, drawing_border, size, reach)?,
Some(reach) => centring_marks(start, drawing_border, size, reach)?,
None => Vec::new(),
};
let trimming_marks = match self.trimming_mark_mm {
@@ -393,7 +418,7 @@ impl DrawingBorderProfile {
None => Vec::new(),
};
Ok(SheetLayout {
sheet_border: Aabb2 { min: Vec2::ZERO, max: size },
sheet_border,
drawing_border,
drawing_border_line_mm: self.drawing_border_line_mm,
columns,
@@ -406,18 +431,18 @@ impl DrawingBorderProfile {
}
}
/// The four centring marks: on the sheet's centre lines, from the grid reference border to
/// `reach` inside the drawing border, which must not take them past the centre.
fn centring_marks(grid_border: Aabb2, drawing_border: Aabb2, size: Vec2, reach: f64) -> Result<Vec<[Vec2; 2]>> {
/// The four centring marks: on the sheet's centre lines, from the edges of `start` to `reach`
/// inside the drawing border, which must not take them past the centre.
fn centring_marks(start: Aabb2, drawing_border: Aabb2, size: Vec2, reach: f64) -> Result<Vec<[Vec2; 2]>> {
let (cx, cy) = (size.x / 2.0, size.y / 2.0);
let (lo, hi) = (drawing_border.min, drawing_border.max);
let room = (cx - lo.x).min(hi.x - cx).min(cy - lo.y).min(hi.y - cy);
require(reach <= room, "a centring mark stops at the sheet's centre lines")?;
Ok(vec![
[Vec2::new(cx, grid_border.min.y), Vec2::new(cx, lo.y + reach)],
[Vec2::new(cx, grid_border.max.y), Vec2::new(cx, hi.y - reach)],
[Vec2::new(grid_border.min.x, cy), Vec2::new(lo.x + reach, cy)],
[Vec2::new(grid_border.max.x, cy), Vec2::new(hi.x - reach, cy)],
[Vec2::new(cx, start.min.y), Vec2::new(cx, lo.y + reach)],
[Vec2::new(cx, start.max.y), Vec2::new(cx, hi.y - reach)],
[Vec2::new(start.min.x, cy), Vec2::new(lo.x + reach, cy)],
[Vec2::new(start.max.x, cy), Vec2::new(hi.x - reach, cy)],
])
}
+48 -20
View File
@@ -10,10 +10,15 @@ fn with_filing_margin() -> DrawingBorderProfile {
DrawingBorderProfile { filing_margin: true, ..DrawingBorderProfile::iso() }
}
/// ISO 5457's border with every choice on: the filing margin, centring marks 10 mm inside the
/// drawing border and trimming marks.
/// ISO 5457's border with every choice on: the filing margin, centring marks from the grid
/// reference border to 10 mm inside the drawing border, and trimming marks.
fn full_iso_5457() -> DrawingBorderProfile {
DrawingBorderProfile { centring_mark_mm: Some(10.0), trimming_mark_mm: Some([10.0, 5.0]), ..with_filing_margin() }
DrawingBorderProfile {
centring_mark_mm: Some(10.0),
centring_mark_start: CentringMarkStart::GridBorder,
trimming_mark_mm: Some([10.0, 5.0]),
..with_filing_margin()
}
}
fn lengths(fields: &[Field]) -> Vec<f64> {
@@ -95,21 +100,26 @@ fn a3_landscape_has_a_400_by_277_drawing_border_and_8_by_6_fields() {
}
#[test]
fn a3_landscape_has_a_grid_border_and_centring_marks_that_stop_at_the_drawing_border() {
fn a3_landscape_has_a_grid_border_and_centring_marks_across_the_margin() {
let layout = iso_layout(PaperSize::A3, Orientation::Landscape);
// 5 mm outside the drawing border (10, 10)-(410, 287).
assert_eq!(layout.grid_border, Aabb2 { min: Vec2::new(5.0, 5.0), max: Vec2::new(415.0, 292.0) });
// On the centre lines x = 210 and y = 148.5, from the grid reference border to the drawing border.
// On the centre lines x = 210 and y = 148.5, from the sheet's edge to the drawing border.
let mark = |a: (f64, f64), b: (f64, f64)| [Vec2::new(a.0, a.1), Vec2::new(b.0, b.1)];
assert_eq!(
layout.centring_marks,
[
mark((210.0, 5.0), (210.0, 10.0)),
mark((210.0, 292.0), (210.0, 287.0)),
mark((5.0, 148.5), (10.0, 148.5)),
mark((415.0, 148.5), (410.0, 148.5))
mark((210.0, 0.0), (210.0, 10.0)),
mark((210.0, 297.0), (210.0, 287.0)),
mark((0.0, 148.5), (10.0, 148.5)),
mark((420.0, 148.5), (410.0, 148.5))
]
);
// From the grid reference border instead, when the profile asks.
let iso_start = DrawingBorderProfile { centring_mark_start: CentringMarkStart::GridBorder, ..DrawingBorderProfile::iso() };
let from_grid = iso_start.layout(&Sheet::standard(PaperSize::A3, Orientation::Landscape)).unwrap();
assert_eq!(from_grid.centring_marks[0], mark((210.0, 5.0), (210.0, 10.0)));
assert_eq!(from_grid.centring_marks[3], mark((415.0, 148.5), (410.0, 148.5)));
assert!(layout.trimming_marks.is_empty());
// On the sheet's centre lines, not the drawing border's: a deeper bottom margin leaves them at 148.5.
let sheet = Sheet::standard(PaperSize::A3, Orientation::Landscape);
@@ -162,8 +172,9 @@ fn a3_landscape_with_iso_5457s_full_border_has_its_filing_margin_and_every_mark(
}
/// On every standard size either way, the marks are where the profile puts them: the built-in
/// centring marks end exactly on the drawing border and there are no trimming marks; ISO 5457's
/// full border reaches 10 mm inside and has its trimming marks in the corners.
/// centring marks run from the sheet's edge and end exactly on the drawing border, and there are no
/// trimming marks; ISO 5457's full border starts them at the grid reference border, reaches 10 mm
/// inside and has its trimming marks in the corners.
#[test]
fn every_sheet_has_centring_marks_on_its_centre_lines_and_trimming_marks_only_when_asked() {
for (profile, reach, trimming_marks) in [(DrawingBorderProfile::iso(), 0.0, 0), (full_iso_5457(), 10.0, 8)] {
@@ -172,12 +183,16 @@ fn every_sheet_has_centring_marks_on_its_centre_lines_and_trimming_marks_only_wh
let layout = profile.layout(&Sheet::standard(size, orientation)).unwrap();
let (size_mm, drawing, grid) = (layout.sheet_border.max, layout.drawing_border, layout.grid_border);
let centre = Vec2::new(size_mm.x / 2.0, size_mm.y / 2.0);
// Bottom, top, left and right, from the grid reference border.
let start = match profile.centring_mark_start {
CentringMarkStart::SheetEdge => layout.sheet_border,
CentringMarkStart::GridBorder => grid,
};
// Bottom, top, left and right, from where the profile starts them.
let expected = [
[Vec2::new(centre.x, grid.min.y), Vec2::new(centre.x, drawing.min.y + reach)],
[Vec2::new(centre.x, grid.max.y), Vec2::new(centre.x, drawing.max.y - reach)],
[Vec2::new(grid.min.x, centre.y), Vec2::new(drawing.min.x + reach, centre.y)],
[Vec2::new(grid.max.x, centre.y), Vec2::new(drawing.max.x - reach, centre.y)],
[Vec2::new(centre.x, start.min.y), Vec2::new(centre.x, drawing.min.y + reach)],
[Vec2::new(centre.x, start.max.y), Vec2::new(centre.x, drawing.max.y - reach)],
[Vec2::new(start.min.x, centre.y), Vec2::new(drawing.min.x + reach, centre.y)],
[Vec2::new(start.max.x, centre.y), Vec2::new(drawing.max.x - reach, centre.y)],
];
assert_eq!(layout.centring_marks, expected, "{size:?} {orientation:?} {reach}");
assert_eq!(layout.trimming_marks.len(), trimming_marks, "{size:?} {orientation:?}");
@@ -347,8 +362,10 @@ fn hostile_sizes_and_profiles_are_refused() {
DrawingBorderProfile { centring_mark_mm: Some(-10.0), ..iso },
DrawingBorderProfile { centring_mark_mm: Some(f64::NAN), ..iso },
DrawingBorderProfile { centring_mark_mm: Some(f64::INFINITY), ..iso },
// ...and is longer than 0: one that stops on the drawing border needs a grid reference border.
DrawingBorderProfile { grid_border_mm: 0.0, ..iso },
// ...and is longer than 0: one that stops on the drawing border needs room outside it on
// the side it starts from, a grid reference border or every margin.
DrawingBorderProfile { grid_border_mm: 0.0, centring_mark_start: CentringMarkStart::GridBorder, ..iso },
DrawingBorderProfile { grid_border_mm: 0.0, ..with_margins(0.0, 10.0, 10.0, 10.0) },
// A trimming mark is finite, above 0 and no wider than it is long...
DrawingBorderProfile { trimming_mark_mm: Some([4.0, 5.0]), ..iso },
DrawingBorderProfile { trimming_mark_mm: Some([10.0, 0.0]), ..iso },
@@ -398,8 +415,10 @@ fn hostile_sizes_and_profiles_are_refused() {
DrawingBorderProfile { grid_border_mm: 0.0, centring_mark_mm: None, ..with_margins(0.0, 0.0, 0.0, 0.0) },
DrawingBorderProfile { grid_border_mm: 10.0, ..iso },
DrawingBorderProfile { centring_mark_mm: Some(138.5), ..iso },
// With no grid reference border, a centring mark that reaches inside has a length.
DrawingBorderProfile { grid_border_mm: 0.0, centring_mark_mm: Some(10.0), ..iso },
// With no grid reference border, a centring mark that reaches inside has a length, and so
// does one from the sheet's edge.
DrawingBorderProfile { grid_border_mm: 0.0, centring_mark_mm: Some(10.0), centring_mark_start: CentringMarkStart::GridBorder, ..iso },
DrawingBorderProfile { grid_border_mm: 0.0, ..iso },
// A centre line on the drawing border's left side: a mark that stops on the border fits.
DrawingBorderProfile { grid: GridRule::Equal { columns: 2, rows: 2 }, ..with_margins(210.0, 10.0, 10.0, 10.0) },
// The filing margin stands in for a left margin too narrow for the grid reference border.
@@ -436,6 +455,14 @@ fn names_round_trip_and_unknown_fields_are_refused() {
assert_eq!(value["grid"], serde_json::json!({"from_centre": {"field_mm": 50.0}}));
assert_eq!(value["label_sides"], serde_json::json!("iso"));
assert_eq!(value["centring_mark_mm"], serde_json::json!(0.0));
assert_eq!(value["centring_mark_start"], serde_json::json!("sheet_edge"));
// Not given, it is the sheet's edge; an unknown start is refused.
let mut without = value.clone();
without.as_object_mut().unwrap().remove("centring_mark_start");
assert_eq!(serde_json::from_value::<DrawingBorderProfile>(without).unwrap(), profile);
let mut unknown = value.clone();
unknown["centring_mark_start"] = serde_json::json!("middle");
assert!(serde_json::from_value::<DrawingBorderProfile>(unknown).is_err());
assert_eq!(value["trimming_mark_mm"], serde_json::json!(null));
assert_eq!(serde_json::to_value(GridRule::None).unwrap(), serde_json::json!("none"));
assert_eq!(serde_json::from_value::<DrawingBorderProfile>(value.clone()).unwrap(), profile);
@@ -515,6 +542,7 @@ fn fields_tile_every_drawing_border_exactly() {
label_sides: LabelSides::Fixed(Sides::ALL),
grid_border_mm: 0.0,
centring_mark_mm: None,
centring_mark_start: CentringMarkStart::SheetEdge,
trimming_mark_mm: None,
};
let Ok(layout) = profile.layout(sheet) else { continue };