1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//! Progressive validation system for 3MF models.
//!
//! This module provides a four-level validation system that lets you choose the right balance
//! between performance and thoroughness for your use case.
//!
//! ## Validation Levels
//!
//! The [`ValidationLevel`] enum defines four progressively stricter validation modes:
//!
//! ### Minimal
//!
//! Basic structural checks:
//! - Required attributes present (`unit`, `id`, etc.)
//! - Valid XML structure
//! - No obviously malformed data
//!
//! **Performance**: Very fast (< 1ms for typical models)
//! **Use case**: Quick sanity check, development testing
//!
//! ### Standard (Recommended)
//!
//! Reference integrity and semantic correctness:
//! - All resource IDs are unique
//! - Build items reference valid objects
//! - Material references point to existing materials
//! - Component references form valid DAG (no cycles)
//! - Vertex indices within mesh bounds
//!
//! **Performance**: Fast (< 10ms for typical models)
//! **Use case**: Production parsing, most applications
//!
//! ### Strict
//!
//! Full 3MF specification compliance:
//! - All Standard checks
//! - Metadata requirements enforced
//! - No unknown attributes or elements
//! - Extension namespaces correctly declared
//!
//! **Performance**: Moderate
//! **Use case**: Spec conformance testing, quality assurance
//!
//! ### Paranoid
//!
//! Deep geometry analysis with advanced algorithms:
//! - All Strict checks
//! - Mesh manifoldness (edge-manifold, vertex-manifold)
//! - Self-intersection detection (BVH-accelerated)
//! - Orientation consistency (outward-facing normals)
//! - Degenerate triangle detection
//! - Island detection (connected components)
//! - Type-specific constraints (Model objects must be manifold)
//!
//! **Performance**: Slow (can be seconds for complex models, O(n²) worst case)
//! **Use case**: Critical manufacturing workflows, geometry repair pipelines
//!
//! ## Usage
//!
//! ```
//! use lib3mf_core::{Model, validation::ValidationLevel};
//!
//! let model = Model::default();
//!
//! // Quick check
//! let report = model.validate(ValidationLevel::Minimal);
//! assert!(!report.has_errors());
//!
//! // Production use
//! let report = model.validate(ValidationLevel::Standard);
//! if report.has_errors() {
//! for item in &report.items {
//! eprintln!("[{}] {}", item.code, item.message);
//! }
//! }
//!
//! // Critical applications
//! let report = model.validate(ValidationLevel::Paranoid);
//! ```
//!
//! ## Validation Report
//!
//! Validation returns a [`ValidationReport`] containing:
//!
//! - **Errors**: Spec violations, broken references, invalid geometry
//! - **Warnings**: Suspicious patterns, deprecated features, non-standard usage
//! - **Info**: Informational messages, optimization suggestions
//!
//! Each item includes:
//! - Error code (numeric, for programmatic handling)
//! - Human-readable message
//! - Optional suggestion for fixing the issue
//! - Optional context (e.g., "Object 5", "Triangle 123")
//!
//! ## Geometry Validation Algorithms
//!
//! The [`geometry`] module implements advanced mesh validation:
//!
//! - **Manifoldness**: Each edge shared by exactly 2 triangles (edge-manifold). Each vertex has
//! a single connected fan of triangles (vertex-manifold).
//! - **Self-intersection**: BVH (Bounding Volume Hierarchy) acceleration for O(n log n) triangle-triangle
//! intersection tests. See [`bvh`] module.
//! - **Orientation**: Directed edge analysis to detect reversed normals.
//! - **Island detection**: Connected component analysis using depth-first search.
//!
//! ## Performance Optimization
//!
//! For large models, validation can be expensive. Strategies:
//!
//! - **Use Standard for production**: Catches 99% of issues in < 10ms
//! - **Defer Paranoid to background**: Run geometry checks asynchronously
//! - **Cache results**: Validation reports are cloneable and serializable
//! - **Progressive checking**: Validate incrementally during parsing (not yet implemented)
/// Bounding Volume Hierarchy for accelerated spatial queries and intersection tests.
/// Displacement mesh validation helpers.
/// Mesh geometry validation algorithms (manifoldness, self-intersection, orientation).
/// Validation report types (`ValidationReport`, `ValidationItem`, `ValidationSeverity`).
/// Schema-level validation against the 3MF core specification structure.
/// Semantic validation — resource references, ID uniqueness, and cross-reference integrity.
use ;
/// Level of validation to perform.
///
/// This enum defines four progressively stricter validation modes. Higher levels include
/// all checks from lower levels.
// Re-exports
pub use validate_displacement;
pub use validate_geometry;
pub use ;