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