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/// Error types for geometric operations
70pub mod error;
71/// Generic traits for geometric operations
72pub mod generic;
73/// Global router for Steiner tree routing
74pub mod global_router;
75/// Interval operations and types
76pub mod interval;
77/// Manhattan arc geometry for the DME algorithm
78pub mod manhattan_arc;
79/// Merge object for combining geometric objects
80pub mod merge_obj;
81/// Point types and operations
82pub mod point;
83/// Polygon types and operations
84pub mod polygon;
85/// Circular doubly-linked list for polygon decomposition
86pub mod rdllist;
87/// Rectilinear polygon types and operations
88pub mod rpolygon;
89/// Rectilinear polygon cut (decomposition) operations
90pub mod rpolygon_cut;
91/// Rectilinear polygon hull operations
92pub mod rpolygon_hull;
93/// Vector2 types and operations
94pub mod vector2;
95/// VLSI-specific geometric operations
96pub mod vlsi_ops;
97
98/// Logging module - available when `std` feature is enabled.
99#[cfg(feature = "std")]
100pub mod logging;
101
102pub use crate::point::Point;
103pub use crate::polygon::Polygon;
104pub use crate::rpolygon::RPolygon;
105pub use crate::vector2::Vector2;
106
107#[cfg(test)]
108mod tests {
109    use super::*;
110    use quickcheck_macros::quickcheck;
111
112    #[test]
113    pub fn it_works() {
114        let pt_a = Point::<i32, i32>::new(12, 23);
115        let vec_b = Vector2::<i32, i32>::new(34, 45);
116        println!("{:?}", pt_a + vec_b);
117        println!("{:?}", pt_a - vec_b);
118
119        let mut pt_a = Point::<i32, i32>::new(42, 53);
120        pt_a += vec_b;
121        pt_a -= vec_b;
122        println!("{:?}", -pt_a);
123
124        let pt_nested = Point::<Point<i32, i32>, Point<i32, i32>>::new(pt_a, pt_a);
125        println!("{:?}", pt_nested);
126
127        let interval_x = interval::Interval::<i32>::new(12, 23);
128        // let interval_y = interval::Interval::<i32>::new(42, 53);
129        println!("{:?}", interval_x);
130    }
131
132    #[quickcheck]
133    fn check_point(ax: u16, bx: u16) -> bool {
134        let pt_a = Point::<i32, i32>::new(ax as i32, 23);
135        let vec_b = Vector2::<i32, i32>::new(bx as i32, 45);
136        pt_a == (pt_a - vec_b) + vec_b
137    }
138
139    // Additional quickcheck tests to verify build configuration
140    #[quickcheck]
141    fn check_point_arithmetic_properties(x: i16, y: i16, dx: i16, dy: i16) -> bool {
142        let pt = Point::<i32, i32>::new(x as i32, y as i32);
143        let vec = Vector2::<i32, i32>::new(dx as i32, dy as i32);
144
145        // Test associative property: (pt + vec) - vec == pt
146        let result = (pt + vec) - vec;
147        pt == result
148    }
149
150    #[quickcheck]
151    fn check_interval_properties(a: i32, b: i32) -> bool {
152        let lower = a.min(b);
153        let upper = a.max(b);
154        let interval = interval::Interval::<i32>::new(lower, upper);
155
156        // Test that the interval has correct bounds
157        interval.lb() <= interval.ub()
158    }
159
160    #[test]
161    fn test_const_functions() {
162        // Test that the const functions we added actually work in const contexts
163        const _P1: Point<i32, i32> = Point::new(1, 2);
164        const _I1: interval::Interval<i32> = interval::Interval::new(1, 5);
165        const _LB: i32 = _I1.lb();
166        const _UB: i32 = _I1.ub();
167        const _M1: merge_obj::MergeObj<i32, i32> = merge_obj::MergeObj::new(1, 2);
168    }
169}