Skip to main content

physdes/
lib.rs

1//! # physdes-rs
2//!
3//! A library for Physical Design in Rust with geometric operations and algorithms.
4//!
5//! ## Overview
6//!
7//! ```svgbob
8//!    Point (x, y)
9//!         *
10//!        /|\
11//!       / | \
12//!      /  |  \
13//!     /   |   \
14//!    *----*----*
15//! Interval [lb, ub]
16//!
17//!  Vector2 (x, y)
18//!      -->
19//!     (dx, dy)
20//! ```
21//!
22//! ## Main Components
23//!
24//! The library provides several geometric structures:
25//!
26//! - `Point<T1, T2>`: A 2D point with x and y coordinates
27//! - `Vector2<T1, T2>`: A 2D vector with x and y components
28//! - `Interval<T>`: A range with lower and upper bounds
29//! - `Polygon<T>`: An arbitrary polygon
30//! - `RPolygon<T>`: A rectilinear polygon
31//! - `GeomError`: Error types for geometric operations
32//! - `vlsi_ops`: VLSI-specific geometric operations
33//! - `algorithms`: Additional geometric algorithms
34//!
35//! # Examples
36//!
37//! ```
38//! use physdes::{Point, Vector2};
39//! use physdes::interval::Interval;
40//! use physdes::polygon::Polygon as Poly;
41//!
42//! // Create a point
43//! let p = Point::new(3, 4);
44//! assert_eq!(p.xcoord, 3);
45//! assert_eq!(p.ycoord, 4);
46//!
47//! // Create a vector
48//! let v = Vector2::new(1, 2);
49//! assert_eq!(v.x_, 1);
50//! assert_eq!(v.y_, 2);
51//!
52//! // Create an interval
53//! let interval = Interval::new(1, 5);
54//! assert_eq!(interval.lb(), 1);
55//! assert_eq!(interval.ub(), 5);
56//!
57//! // Create a polygon from points
58//! let points = vec![Point::new(0, 0), Point::new(1, 0), Point::new(1, 1), Point::new(0, 1)];
59//! let polygon = Poly::new(&points);
60//! assert_eq!(polygon.origin, Point::new(0, 0));
61//! ```
62//!
63/// Geometric algorithms module
64pub mod algorithms;
65/// Doubly-linked list node for polygon decomposition
66pub mod dllink;
67/// DME algorithm for clock tree synthesis
68pub mod dme_algorithm;
69/// SVG visualizer for DME clock trees
70pub mod dme_visualizer;
71/// Error types for geometric operations
72pub mod error;
73/// Generic traits for geometric operations
74pub mod generic;
75/// Global router for Steiner tree routing
76pub mod global_router;
77/// Interval operations and types
78pub mod interval;
79/// Manhattan arc geometry for the DME algorithm
80pub mod manhattan_arc;
81/// Merge object for combining geometric objects
82pub mod merge_obj;
83/// Point types and operations
84pub mod point;
85/// Polygon types and operations
86pub mod polygon;
87/// Circular doubly-linked list for polygon decomposition
88pub mod rdllist;
89/// Rectilinear polygon types and operations
90pub mod rpolygon;
91/// Rectilinear polygon cut (decomposition) operations
92pub mod rpolygon_cut;
93/// Rectilinear polygon hull operations
94pub mod rpolygon_hull;
95/// Steiner forest grid construction using primal-dual approximation
96pub mod steiner_forest_grid;
97/// Vector2 types and operations
98pub mod vector2;
99/// VLSI-specific geometric operations
100pub mod vlsi_ops;
101
102/// Logging module - available when `std` feature is enabled.
103#[cfg(feature = "std")]
104pub mod logging;
105
106pub use crate::point::Point;
107pub use crate::polygon::Polygon;
108pub use crate::rpolygon::RPolygon;
109pub use crate::vector2::Vector2;
110
111#[cfg(test)]
112mod tests {
113    use super::*;
114    use quickcheck_macros::quickcheck;
115
116    #[quickcheck]
117    fn check_point(ax: u16, bx: u16) -> bool {
118        let pt_a = Point::<i32, i32>::new(ax as i32, 23);
119        let vec_b = Vector2::<i32, i32>::new(bx as i32, 45);
120        pt_a == (pt_a - vec_b) + vec_b
121    }
122
123    // Additional quickcheck tests to verify build configuration
124    #[quickcheck]
125    fn check_point_arithmetic_properties(x: i16, y: i16, dx: i16, dy: i16) -> bool {
126        let pt = Point::<i32, i32>::new(x as i32, y as i32);
127        let vec = Vector2::<i32, i32>::new(dx as i32, dy as i32);
128
129        // Test associative property: (pt + vec) - vec == pt
130        let result = (pt + vec) - vec;
131        pt == result
132    }
133
134    #[quickcheck]
135    fn check_interval_properties(a: i32, b: i32) -> bool {
136        let lower = a.min(b);
137        let upper = a.max(b);
138        let interval = interval::Interval::<i32>::new(lower, upper);
139
140        // Test that the interval has correct bounds
141        interval.lb() <= interval.ub()
142    }
143
144    #[test]
145    fn test_const_functions() {
146        // Test that the const functions we added actually work in const contexts
147        const _P1: Point<i32, i32> = Point::new(1, 2);
148        const _I1: interval::Interval<i32> = interval::Interval::new(1, 5);
149        const _LB: i32 = _I1.lb();
150        const _UB: i32 = _I1.ub();
151        const _M1: merge_obj::MergeObj<i32, i32> = merge_obj::MergeObj::new(1, 2);
152    }
153}