geometry/lib.rs
1//! 2-D geometric operations relevant to integrated circuit layout.
2//!
3//! # Examples
4//!
5//! Create a [rectangle](crate::rect::Rect):
6//!
7//! ```
8//! # use geometry::prelude::*;
9//! let rect = Rect::from_sides(10, 20, 30, 40);
10//! ```
11#![warn(missing_docs)]
12
13extern crate self as geometry;
14
15pub mod align;
16pub mod bbox;
17pub mod contains;
18pub mod corner;
19pub mod dims;
20pub mod dir;
21pub mod edge;
22pub mod intersect;
23pub mod orientation;
24pub mod place;
25pub mod point;
26pub mod polygon;
27pub mod prelude;
28pub mod rect;
29pub mod ring;
30pub mod shape;
31pub mod side;
32pub mod sign;
33pub mod snap;
34pub mod span;
35pub mod transform;
36pub mod union;
37
38/// Wraps the given angle to the interval `[0, 360)` degrees.
39///
40/// # Examples
41///
42/// ```
43/// use geometry::wrap_angle;
44///
45/// assert_eq!(wrap_angle(10.), 10.);
46/// assert_eq!(wrap_angle(-10.), 350.);
47/// assert_eq!(wrap_angle(-740.), 340.);
48/// assert_eq!(wrap_angle(-359.), 1.);
49/// assert_eq!(wrap_angle(-1.), 359.);
50/// assert_eq!(wrap_angle(725.), 5.);
51/// assert_eq!(wrap_angle(360.), 0.);
52/// assert_eq!(wrap_angle(-360.), 0.);
53/// ```
54pub fn wrap_angle(angle: f64) -> f64 {
55 ((angle % 360.) + 360.) % 360.
56}