Skip to main content

jagua_rs/
lib.rs

1#![warn(
2    clippy::pedantic,
3    clippy::correctness,
4    clippy::suspicious,
5    clippy::complexity,
6    clippy::perf,
7    clippy::style
8)]
9#![allow(clippy::missing_panics_doc, clippy::missing_errors_doc)]
10//!
11//! Collision detection for 2D irregular cutting and packing algorithms.
12//!
13//! [`geometry`] provides polygons and transformations. [`io`] imports item and container
14//! geometry and exports placements. A [`Layout`](entities::Layout) owns placements and
15//! keeps its [`CDEngine`](collision_detection::CDEngine) synchronized as items are added or removed.
16//! Use the CDE to query candidate placements before adding them to a layout.
17//! Optional `spp` and `bpp` features provide strip- and bin-packing models in [`probs`].
18//!
19//! # Import, query, place and restore
20//!
21//! ```
22//! use jagua_rs::collision_detection::{CDEConfig, hazards::filter::NoFilter};
23//! use jagua_rs::entities::Layout;
24//! use jagua_rs::geometry::{DTransformation, fail_fast::SPSurrogateConfig, geo_traits::Transformable};
25//! use jagua_rs::io::{ext_repr::{ExtContainer, ExtItem, ExtOrientation, ExtRotation, ExtShape}, import::Importer};
26//!
27//! # fn main() -> anyhow::Result<()> {
28//! let importer = Importer::new(CDEConfig {
29//!     item_surrogate_config: SPSurrogateConfig::none(),
30//! }, None, None);
31//! let container = importer.import_container(&ExtContainer {
32//!     id: 0,
33//!     shape: ExtShape::Rectangle { x_min: 0.0, y_min: 0.0, width: 20.0, height: 10.0 },
34//!     zones: vec![],
35//! })?;
36//! let item = importer.import_item(&ExtItem {
37//!     id: 42,
38//!     shape: ExtShape::Rectangle { x_min: 0.0, y_min: 0.0, width: 2.0, height: 2.0 },
39//!     orientation: ExtOrientation {
40//!         rotation: ExtRotation::Discrete { angles: vec![0.0] },
41//!         reflection_axes: vec![],
42//!     },
43//!     min_quality: None,
44//! }, 0)?;
45//! let mut layout = Layout::new(container);
46//! let empty = layout.save();
47//!
48//! // Imported item geometry is centered at the origin; angles here are in radians.
49//! let pose = DTransformation::new(0.0, (5.0, 5.0));
50//! let candidate = item.shape_cd().transform_clone(&pose.compose());
51//! if !layout.cde().detect_poly_collision(&candidate, &NoFilter) {
52//!     // Placement itself does not validate collisions or orientation permissions.
53//!     layout.place_item(&item, pose);
54//! }
55//! assert_eq!(layout.placed_items().len(), 1);
56//! assert!(layout.is_collision_free());
57//! layout.restore(&empty)?;
58//! assert!(layout.placed_items().is_empty());
59//! # Ok(())
60//! # }
61//! ```
62
63#![doc = document_features::document_features!()]
64
65/// Everything related to the Collision Detection Engine
66pub mod collision_detection;
67
68/// Entities to model 2D Irregular Cutting and Packing Problems
69pub mod entities;
70
71/// Geometric primitives and base algorithms
72pub mod geometry;
73
74/// Importing problem instances into and exporting solutions out of this library
75pub mod io;
76
77/// Helper functions which do not belong to any specific module
78pub mod util;
79
80/// Enabled variants of the 2D irregular Cutting and Packing Problem.
81pub mod probs;
82
83/// Export the `web_time` crate's `Instant` type for compatibility with web environments.
84pub type Instant = web_time::Instant;