mirror of
https://github.com/bevyengine/bevy
synced 2024-12-21 02:23:08 +00:00
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")]`.
This commit is contained in:
parent
7662b4fe40
commit
bb090e6176
2 changed files with 13 additions and 3 deletions
|
@ -2,12 +2,15 @@ use core::f32::consts::{FRAC_1_SQRT_2, FRAC_PI_2, FRAC_PI_3, PI};
|
||||||
use derive_more::derive::From;
|
use derive_more::derive::From;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use super::{polygon::is_polygon_simple, Measured2d, Primitive2d, WindingOrder};
|
use super::{Measured2d, Primitive2d, WindingOrder};
|
||||||
use crate::{
|
use crate::{
|
||||||
ops::{self, FloatPow},
|
ops::{self, FloatPow},
|
||||||
Dir2, Vec2,
|
Dir2, Vec2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
|
use super::polygon::is_polygon_simple;
|
||||||
|
|
||||||
#[cfg(feature = "bevy_reflect")]
|
#[cfg(feature = "bevy_reflect")]
|
||||||
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
|
||||||
#[cfg(all(feature = "serialize", feature = "bevy_reflect"))]
|
#[cfg(all(feature = "serialize", feature = "bevy_reflect"))]
|
||||||
|
@ -1634,6 +1637,7 @@ impl<const N: usize> Polygon<N> {
|
||||||
///
|
///
|
||||||
/// A polygon is simple if it is not self intersecting and not self tangent.
|
/// A polygon is simple if it is not self intersecting and not self tangent.
|
||||||
/// As such, no two edges of the polygon may cross each other and each vertex must not lie on another edge.
|
/// As such, no two edges of the polygon may cross each other and each vertex must not lie on another edge.
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
pub fn is_simple(&self) -> bool {
|
pub fn is_simple(&self) -> bool {
|
||||||
is_polygon_simple(&self.vertices)
|
is_polygon_simple(&self.vertices)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
extern crate alloc;
|
#[cfg(feature = "alloc")]
|
||||||
use alloc::collections::BTreeMap;
|
use alloc::{collections::BTreeMap, vec::Vec};
|
||||||
|
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
|
|
||||||
use crate::Vec2;
|
use crate::Vec2;
|
||||||
|
@ -58,10 +59,12 @@ fn xy_order(a: Vec2, b: Vec2) -> Ordering {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The event queue holds an ordered list of all events the [`SweepLine`] will encounter when checking the current polygon.
|
/// The event queue holds an ordered list of all events the [`SweepLine`] will encounter when checking the current polygon.
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct EventQueue {
|
struct EventQueue {
|
||||||
events: Vec<SweepLineEvent>,
|
events: Vec<SweepLineEvent>,
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
impl EventQueue {
|
impl EventQueue {
|
||||||
/// Initialize a new `EventQueue` with all events from the polygon represented by `vertices`.
|
/// Initialize a new `EventQueue` with all events from the polygon represented by `vertices`.
|
||||||
///
|
///
|
||||||
|
@ -143,11 +146,13 @@ struct SegmentOrder {
|
||||||
///
|
///
|
||||||
/// 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
|
/// 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
|
||||||
/// the sweep line is intersecting at any given moment.
|
/// the sweep line is intersecting at any given moment.
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct SweepLine<'a> {
|
struct SweepLine<'a> {
|
||||||
vertices: &'a [Vec2],
|
vertices: &'a [Vec2],
|
||||||
tree: BTreeMap<Segment, SegmentOrder>,
|
tree: BTreeMap<Segment, SegmentOrder>,
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
impl<'a> SweepLine<'a> {
|
impl<'a> SweepLine<'a> {
|
||||||
fn new(vertices: &'a [Vec2]) -> Self {
|
fn new(vertices: &'a [Vec2]) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -253,6 +258,7 @@ fn point_side(p1: Vec2, p2: Vec2, q: Vec2) -> f32 {
|
||||||
///
|
///
|
||||||
/// The algorithm used is the Shamos-Hoey algorithm, a version of the Bentley-Ottman algorithm adapted to only detect whether any intersections exist.
|
/// The algorithm used is the Shamos-Hoey algorithm, a version of the Bentley-Ottman algorithm adapted to only detect whether any intersections exist.
|
||||||
/// This function will run in O(n * log n)
|
/// This function will run in O(n * log n)
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
pub fn is_polygon_simple(vertices: &[Vec2]) -> bool {
|
pub fn is_polygon_simple(vertices: &[Vec2]) -> bool {
|
||||||
if vertices.len() < 3 {
|
if vertices.len() < 3 {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue