Skip to content

Commit 3cd8f83

Browse files
pcwaltonBD103
authored andcommitted
Feature gate is_polygon_simple behind the alloc feature. (#16739)
CI was failing because `bevy_math` no longer compiled with `libcore`. This was due to PR #15981. This commit fixes the issue by moving the applicable functionality behind `#[cfg(feature = "alloc")]`.
1 parent 233b725 commit 3cd8f83

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

crates/bevy_math/src/primitives/dim2.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ use core::f32::consts::{FRAC_1_SQRT_2, FRAC_PI_2, FRAC_PI_3, PI};
22
use derive_more::derive::From;
33
use thiserror::Error;
44

5-
use super::{polygon::is_polygon_simple, Measured2d, Primitive2d, WindingOrder};
5+
use super::{Measured2d, Primitive2d, WindingOrder};
66
use crate::{
77
ops::{self, FloatPow},
88
Dir2, Vec2,
99
};
1010

11+
#[cfg(feature = "alloc")]
12+
use super::polygon::is_polygon_simple;
13+
1114
#[cfg(feature = "bevy_reflect")]
1215
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
1316
#[cfg(all(feature = "serialize", feature = "bevy_reflect"))]
@@ -1634,6 +1637,7 @@ impl<const N: usize> Polygon<N> {
16341637
///
16351638
/// A polygon is simple if it is not self intersecting and not self tangent.
16361639
/// As such, no two edges of the polygon may cross each other and each vertex must not lie on another edge.
1640+
#[cfg(feature = "alloc")]
16371641
pub fn is_simple(&self) -> bool {
16381642
is_polygon_simple(&self.vertices)
16391643
}

crates/bevy_math/src/primitives/polygon.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
extern crate alloc;
2-
use alloc::collections::BTreeMap;
1+
#[cfg(feature = "alloc")]
2+
use alloc::{collections::BTreeMap, vec::Vec};
3+
34
use core::cmp::Ordering;
45

56
use crate::Vec2;
@@ -58,10 +59,12 @@ fn xy_order(a: Vec2, b: Vec2) -> Ordering {
5859
}
5960

6061
/// The event queue holds an ordered list of all events the [`SweepLine`] will encounter when checking the current polygon.
62+
#[cfg(feature = "alloc")]
6163
#[derive(Debug, Clone)]
6264
struct EventQueue {
6365
events: Vec<SweepLineEvent>,
6466
}
67+
#[cfg(feature = "alloc")]
6568
impl EventQueue {
6669
/// Initialize a new `EventQueue` with all events from the polygon represented by `vertices`.
6770
///
@@ -143,11 +146,13 @@ struct SegmentOrder {
143146
///
144147
/// 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
145148
/// the sweep line is intersecting at any given moment.
149+
#[cfg(feature = "alloc")]
146150
#[derive(Debug, Clone)]
147151
struct SweepLine<'a> {
148152
vertices: &'a [Vec2],
149153
tree: BTreeMap<Segment, SegmentOrder>,
150154
}
155+
#[cfg(feature = "alloc")]
151156
impl<'a> SweepLine<'a> {
152157
fn new(vertices: &'a [Vec2]) -> Self {
153158
Self {
@@ -253,6 +258,7 @@ fn point_side(p1: Vec2, p2: Vec2, q: Vec2) -> f32 {
253258
///
254259
/// The algorithm used is the Shamos-Hoey algorithm, a version of the Bentley-Ottman algorithm adapted to only detect whether any intersections exist.
255260
/// This function will run in O(n * log n)
261+
#[cfg(feature = "alloc")]
256262
pub fn is_polygon_simple(vertices: &[Vec2]) -> bool {
257263
if vertices.len() < 3 {
258264
return true;

0 commit comments

Comments
 (0)