ifc_spatial/lib.rs
1//! `ifc-spatial` — containment and objectified relationship traversal.
2//!
3//! # The problem
4//!
5//! IFC stores no parent pointers. A wall does not name its storey; a separate
6//! `IfcRelContainedInSpatialStructure` entity names both ends. Asking "which
7//! elements are on this storey" therefore means finding relationship entities
8//! and reading the right attribute slot — and the two relationships that build
9//! the tree **disagree about which slot is which**:
10//!
11//! ```text
12//! IfcRelAggregates 4 = RelatingObject 5 = RelatedObjects
13//! IfcRelContainedInSpatialStructure 4 = RelatedElements 5 = RelatingStructure
14//! ```
15//!
16//! Assuming a uniform layout inverts containment silently: elements become the
17//! parents of their storey, and every downstream answer is wrong in a way no
18//! type error catches.
19//!
20//! # Example
21//!
22//! ```no_run
23//! use ifc_spatial::{SpatialKind, SpatialTree};
24//! # let model = ifc_model::Model::new();
25//!
26//! let tree = SpatialTree::build(&model);
27//!
28//! for storey in tree.of_kind(SpatialKind::Storey) {
29//! let elements = tree.elements_of(storey.id);
30//! println!("storey {:?} holds {} elements", storey.id, elements.len());
31//! }
32//! ```
33//!
34//! # Tolerating real files
35//!
36//! The canonical hierarchy is project → site → building → storey → element, and
37//! real exports deviate: omitted sites, elements hung directly off a building,
38//! duplicate storeys, relationships naming entities that are not in the file.
39//! The tree records what the file says and reports anomalies through
40//! [`SpatialTree::orphans`] and [`SpatialTree::dangling`] rather than asserting
41//! the ideal shape or panicking.
42//!
43//! # Boundaries
44//!
45//! This crate reads containment. It does not validate it — `ifc-validate` owns
46//! WHERE rules and cardinality — and it does not interpret geometry or
47//! properties of the elements it groups.
48
49pub mod authoring;
50pub mod relation;
51mod tree;
52
53pub use relation::{
54 BoundaryExposure, BoundaryPhysicality, ConnectionGeometryAnomaly, Relationship,
55 RelationshipIndex, RelationshipKind, SpaceBoundary,
56};
57pub use tree::{SpatialAnomaly, SpatialKind, SpatialNode, SpatialTree};
58
59/// The IFC release a tree classifies against (re-exported from `ifc-schema`).
60pub use ifc_schema::SchemaVersion;
61
62pub mod facility;
63
64pub use facility::{create_facility, Facility, FacilityDraft, FacilityError, FacilityResult};
65
66pub use authoring::{
67 aggregate, connect_path_elements, contain, create_external_spatial_element, create_project,
68 create_project_library, create_space_boundary, create_spatial_element, BoundaryDraft,
69 BoundaryLevel, ExternalSpatialDraft, ProjectLibraryDraft, SpatialAuthoringError,
70 SpatialAuthoringResult, SpatialDraft,
71};