ifc_lite_geometry/lib.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! # IFC-Lite Geometry Processing
6//!
7//! Efficient geometry processing for IFC models using [earcutr](https://docs.rs/earcutr)
8//! triangulation and [nalgebra](https://docs.rs/nalgebra) for transformations.
9//!
10//! ## Overview
11//!
12//! This crate transforms IFC geometry representations into GPU-ready triangle meshes:
13//!
14//! - **Profile Handling**: Extract and process 2D profiles (rectangle, circle, arbitrary)
15//! - **Extrusion**: Generate 3D meshes from extruded profiles
16//! - **Triangulation**: Polygon triangulation with hole support via earcutr
17//! - **CSG Operations**: Boolean clipping for wall openings
18//! - **Mesh Processing**: Normal calculation and coordinate transformations
19//!
20//! ## Supported Geometry Types
21//!
22//! | Type | Status | Description |
23//! |------|--------|-------------|
24//! | `IfcExtrudedAreaSolid` | Full | Most common - extruded profiles |
25//! | `IfcFacetedBrep` | Full | Boundary representation meshes |
26//! | `IfcTriangulatedFaceSet` | Full | Pre-triangulated (IFC4) |
27//! | `IfcBooleanClippingResult` | Partial | CSG difference operations |
28//! | `IfcMappedItem` | Full | Instanced geometry |
29//! | `IfcSweptDiskSolid` | Full | Pipe/tube geometry |
30//!
31//! ## Quick Start
32//!
33//! ```rust,ignore
34//! use ifc_lite_geometry::{
35//! Profile2D, extrude_profile, triangulate_polygon,
36//! Point2, Point3, Vector3
37//! };
38//!
39//! // Create a rectangular profile
40//! let profile = Profile2D::rectangle(2.0, 1.0);
41//!
42//! // Extrude to 3D
43//! let direction = Vector3::new(0.0, 0.0, 1.0);
44//! let mesh = extrude_profile(&profile, direction, 3.0)?;
45//!
46//! println!("Generated {} triangles", mesh.triangle_count());
47//! ```
48//!
49//! ## Geometry Router
50//!
51//! Use the [`GeometryRouter`] to automatically dispatch entities to appropriate processors:
52//!
53//! ```rust,ignore
54//! use ifc_lite_geometry::{GeometryRouter, GeometryProcessor};
55//!
56//! let router = GeometryRouter::new();
57//!
58//! // Process entity
59//! if let Some(mesh) = router.process(&decoder, &entity)? {
60//! renderer.add_mesh(mesh);
61//! }
62//! ```
63//!
64//! ## Performance
65//!
66//! - **Simple extrusions**: ~2000 entities/sec
67//! - **Complex Breps**: ~200 entities/sec
68//! - **Boolean operations**: ~20 entities/sec
69
70pub mod profile;
71pub mod extrusion;
72pub mod mesh;
73pub mod csg;
74pub mod error;
75pub mod triangulation;
76pub mod router;
77pub mod profiles;
78pub mod processors;
79
80// Re-export nalgebra types for convenience
81pub use nalgebra::{Point2, Point3, Vector2, Vector3};
82
83pub use error::{Error, Result};
84pub use mesh::Mesh;
85pub use profile::{Profile2D, ProfileType};
86pub use extrusion::extrude_profile;
87pub use csg::{Plane, Triangle, ClippingProcessor, calculate_normals};
88pub use triangulation::triangulate_polygon;
89pub use router::{GeometryRouter, GeometryProcessor};
90pub use profiles::ProfileProcessor;
91pub use processors::{ExtrudedAreaSolidProcessor, TriangulatedFaceSetProcessor, MappedItemProcessor, FacetedBrepProcessor, BooleanClippingProcessor, SweptDiskSolidProcessor, RevolvedAreaSolidProcessor, AdvancedBrepProcessor};