|
1 | | -extern crate alloc; |
2 | | -use alloc::collections::BTreeMap; |
| 1 | +#[cfg(feature = "alloc")] |
| 2 | +use alloc::{collections::BTreeMap, vec::Vec}; |
| 3 | + |
3 | 4 | use core::cmp::Ordering; |
4 | 5 |
|
5 | 6 | use crate::Vec2; |
@@ -58,10 +59,12 @@ fn xy_order(a: Vec2, b: Vec2) -> Ordering { |
58 | 59 | } |
59 | 60 |
|
60 | 61 | /// The event queue holds an ordered list of all events the [`SweepLine`] will encounter when checking the current polygon. |
| 62 | +#[cfg(feature = "alloc")] |
61 | 63 | #[derive(Debug, Clone)] |
62 | 64 | struct EventQueue { |
63 | 65 | events: Vec<SweepLineEvent>, |
64 | 66 | } |
| 67 | +#[cfg(feature = "alloc")] |
65 | 68 | impl EventQueue { |
66 | 69 | /// Initialize a new `EventQueue` with all events from the polygon represented by `vertices`. |
67 | 70 | /// |
@@ -143,11 +146,13 @@ struct SegmentOrder { |
143 | 146 | /// |
144 | 147 | /// It can be thought of as a vertical line sweeping from -X to +X across the polygon that keeps track of the order of the segments |
145 | 148 | /// the sweep line is intersecting at any given moment. |
| 149 | +#[cfg(feature = "alloc")] |
146 | 150 | #[derive(Debug, Clone)] |
147 | 151 | struct SweepLine<'a> { |
148 | 152 | vertices: &'a [Vec2], |
149 | 153 | tree: BTreeMap<Segment, SegmentOrder>, |
150 | 154 | } |
| 155 | +#[cfg(feature = "alloc")] |
151 | 156 | impl<'a> SweepLine<'a> { |
152 | 157 | fn new(vertices: &'a [Vec2]) -> Self { |
153 | 158 | Self { |
@@ -253,6 +258,7 @@ fn point_side(p1: Vec2, p2: Vec2, q: Vec2) -> f32 { |
253 | 258 | /// |
254 | 259 | /// The algorithm used is the Shamos-Hoey algorithm, a version of the Bentley-Ottman algorithm adapted to only detect whether any intersections exist. |
255 | 260 | /// This function will run in O(n * log n) |
| 261 | +#[cfg(feature = "alloc")] |
256 | 262 | pub fn is_polygon_simple(vertices: &[Vec2]) -> bool { |
257 | 263 | if vertices.len() < 3 { |
258 | 264 | return true; |
|
0 commit comments