calib_targets_print/model/error.rs
1//! Error type for printable target generation.
2
3use calib_targets_charuco::CharucoBoardError;
4use calib_targets_puzzleboard::{PuzzleBoardSpecError, MASTER_ROWS};
5
6pub const SCHEMA_VERSION_V1: u32 = 1;
7
8/// Error returned when validating a target specification or rendering a
9/// printable target bundle.
10#[non_exhaustive]
11#[derive(thiserror::Error, Debug)]
12pub enum PrintableTargetError {
13 /// An I/O operation failed while writing one of the output files.
14 #[error(transparent)]
15 Io(#[from] std::io::Error),
16 /// The target document could not be serialized to or deserialized from JSON.
17 #[error(transparent)]
18 Json(#[from] serde_json::Error),
19 /// The document declares a `schema_version` this build does not understand.
20 #[error("unsupported schema_version {0}, expected {SCHEMA_VERSION_V1}")]
21 UnsupportedSchemaVersion(u32),
22 /// A custom page width or height is non-finite or not strictly positive.
23 #[error("page width/height must be finite and > 0")]
24 InvalidPageSize,
25 /// The page margin is non-finite or negative.
26 #[error("page margin must be finite and >= 0")]
27 InvalidMargin,
28 /// The page margins consume the entire page, leaving no printable area.
29 #[error("printable area is empty after margins")]
30 EmptyPrintableArea,
31 /// The requested PNG render resolution is not strictly positive.
32 #[error("png_dpi must be > 0")]
33 InvalidPngDpi,
34 /// A chessboard spec requests fewer than 2 inner rows or columns.
35 #[error("inner_rows and inner_cols must be >= 2")]
36 InvalidChessboardSize,
37 /// A ChArUco spec requests fewer than 2 rows or columns.
38 #[error("rows and cols must be >= 2")]
39 InvalidCharucoSize,
40 /// A square-size dimension is non-finite or not strictly positive.
41 #[error("square_size_mm must be finite and > 0")]
42 InvalidSquareSize,
43 /// The marker-to-square size ratio is non-finite or outside `(0, 1]`.
44 #[error("marker_size_rel must be finite and in (0, 1]")]
45 InvalidMarkerSizeRel,
46 /// The ArUco marker border width is not strictly positive.
47 #[error("border_bits must be > 0")]
48 InvalidBorderBits,
49 /// The circle-to-square diameter ratio is non-finite or outside `(0, 1]`.
50 #[error("circle_diameter_rel must be finite and in (0, 1]")]
51 InvalidCircleDiameter,
52 /// A marker board layout omits the millimeter cell size required to place
53 /// it on a printable page.
54 #[error("marker board layout needs cell_size in millimeters for printable conversion")]
55 MissingMarkerBoardCellSize,
56 /// A marker circle coordinate falls outside the board's square grid.
57 #[error("marker circle coordinates must fall inside the board squares")]
58 InvalidCircleCell,
59 /// Two or more marker circles are placed in the same board cell.
60 #[error("marker circle cells must be unique")]
61 DuplicateCircleCells,
62 /// The chosen ArUco dictionary has fewer codes than the board needs.
63 #[error("board needs {needed} markers, dictionary has {available}")]
64 NotEnoughDictionaryCodes {
65 /// Number of distinct marker codes the board layout requires.
66 needed: usize,
67 /// Number of marker codes available in the selected dictionary.
68 available: usize,
69 },
70 /// The board's physical size exceeds the page's printable area.
71 #[error("board does not fit page: board {board_width_mm:.3}x{board_height_mm:.3} mm, printable area {printable_width_mm:.3}x{printable_height_mm:.3} mm")]
72 BoardDoesNotFit {
73 /// Board width in millimeters.
74 board_width_mm: f64,
75 /// Board height in millimeters.
76 board_height_mm: f64,
77 /// Printable-area width in millimeters (page width minus margins).
78 printable_width_mm: f64,
79 /// Printable-area height in millimeters (page height minus margins).
80 printable_height_mm: f64,
81 },
82 /// Validation of the underlying ChArUco board layout failed.
83 #[error(transparent)]
84 CharucoBoard(#[from] CharucoBoardError),
85 /// A PuzzleBoard spec requests a row or column count outside the valid range.
86 #[error("puzzleboard: rows and cols must be in [4, {MASTER_ROWS}]")]
87 InvalidPuzzleBoardSize,
88 /// A PuzzleBoard's origin plus size extends past the 501×501 master pattern.
89 #[error("puzzleboard origin + size exceeds 501\u{d7}501 master pattern")]
90 InvalidPuzzleBoardOrigin,
91 /// The PuzzleBoard edge-dot diameter ratio is outside `(0, 1]`.
92 #[error("puzzleboard dot_diameter_rel must be in (0, 1]")]
93 InvalidPuzzleBoardDotDiameter,
94 /// Validation of the underlying PuzzleBoard specification failed.
95 #[error(transparent)]
96 PuzzleBoardSpec(#[from] PuzzleBoardSpecError),
97}