Skip to main content

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**: Full boolean operations (difference, union, intersection)
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` | Full | CSG operations (difference, union, intersection) |
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 bool2d;
71mod bsp_csg;
72pub mod csg;
73pub mod error;
74pub mod extrusion;
75pub mod material_layer_index;
76pub mod mesh;
77pub mod processors;
78pub mod profile;
79pub mod profile_extractor;
80pub mod profiles;
81pub mod router;
82pub mod transform;
83pub mod triangulation;
84pub mod void_analysis;
85pub mod void_index;
86
87// Re-export nalgebra types for convenience
88pub use nalgebra::{Point2, Point3, Vector2, Vector3};
89
90pub use bool2d::{
91    compute_signed_area, ensure_ccw, ensure_cw, is_valid_contour, point_in_contour, subtract_2d,
92    subtract_multiple_2d, union_contours,
93};
94pub use csg::{calculate_normals, ClippingProcessor, Plane, Triangle};
95pub use error::{Error, Result};
96pub use extrusion::{extrude_profile, extrude_profile_with_voids};
97pub use material_layer_index::{LayerAxis, LayerBuildup, LayerInfo, MaterialLayerIndex};
98pub use mesh::{CoordinateShift, Mesh, SubMesh, SubMeshCollection};
99pub use processors::{
100    AdvancedBrepProcessor, BooleanClippingProcessor, ExtrudedAreaSolidProcessor,
101    FaceBasedSurfaceModelProcessor, FacetedBrepProcessor, MappedItemProcessor,
102    PolygonalFaceSetProcessor, RevolvedAreaSolidProcessor, SurfaceOfLinearExtrusionProcessor,
103    SweptDiskSolidProcessor, TriangulatedFaceSetProcessor,
104};
105pub use profile::{Profile2D, Profile2DWithVoids, ProfileType, VoidInfo};
106pub use profile_extractor::{extract_profiles, ExtractedProfile};
107pub use profiles::ProfileProcessor;
108pub use router::{GeometryProcessor, GeometryRouter};
109pub use transform::{
110    apply_rtc_offset, parse_axis2_placement_3d, parse_axis2_placement_3d_from_id,
111    parse_cartesian_point, parse_cartesian_point_from_id, parse_direction, parse_direction_from_id,
112};
113pub use triangulation::triangulate_polygon;
114pub use void_analysis::{
115    classify_voids_batch, extract_coplanar_voids, extract_nonplanar_voids, VoidAnalyzer,
116    VoidClassification,
117};
118pub use void_index::{propagate_voids_to_parts, VoidIndex, VoidStatistics};