bevy_shape 0.20.0-rc.1

Provides primitive shape data definitions for Bevy Engine
Documentation
#![forbid(unsafe_code)]
#![cfg_attr(
    any(docsrs, docsrs_dep),
    expect(
        internal_features,
        reason = "rustdoc_internals is needed for fake_variadic"
    )
)]
#![cfg_attr(any(docsrs, docsrs_dep), feature(rustdoc_internals))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc(
    html_logo_url = "https://bevy.org/assets/icon.png",
    html_favicon_url = "https://bevy.org/assets/icon.png"
)]
#![no_std]

//! This module defines primitive shapes.
//! The origin is (0, 0) for 2D primitives and (0, 0, 0) for 3D primitives,
//! unless stated otherwise.

#[cfg(feature = "std")]
extern crate std;

#[cfg(feature = "alloc")]
extern crate alloc;

mod dim2;
pub use dim2::*;
mod dim3;
pub use dim3::*;
mod half_space;
pub use half_space::*;
mod view_frustum;
pub use view_frustum::*;
mod inset;
pub use inset::*;
mod ray;
pub use ray::{Ray2d, Ray3d};
mod bounding;
pub use bounding::*;

#[cfg(feature = "rand")]
pub mod sampling;
#[cfg(feature = "rand")]
pub use sampling::ShapeSample;

#[cfg(feature = "alloc")]
mod polygon;
#[cfg(feature = "alloc")]
pub use polygon::*;

/// A marker trait for 2D primitives
pub trait Primitive2d {}

/// A marker trait for 3D primitives
pub trait Primitive3d {}

impl Primitive2d for bevy_math::Dir2 {}
impl Primitive3d for bevy_math::Dir3 {}
impl Primitive3d for bevy_math::Dir3A {}

/// The winding order for a set of points
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[doc(alias = "Orientation")]
pub enum WindingOrder {
    /// A clockwise winding order
    Clockwise,
    /// A counterclockwise winding order
    #[doc(alias = "AntiClockwise")]
    CounterClockwise,
    /// An invalid winding order indicating that it could not be computed reliably.
    /// This often happens in *degenerate cases* where the points lie on the same line
    #[doc(alias("Degenerate", "Collinear"))]
    Invalid,
}

/// A trait for getting measurements of 2D shapes
pub trait Measured2d {
    /// Get the perimeter of the shape
    fn perimeter(&self) -> f32;

    /// Get the area of the shape
    fn area(&self) -> f32;
}

/// A trait for getting measurements of 3D shapes
pub trait Measured3d {
    /// Get the surface area of the shape
    fn area(&self) -> f32;

    /// Get the volume of the shape
    fn volume(&self) -> f32;
}

/// The shape prelude.
///
/// This includes all primitive shape types in this crate, re-exported for your convenience.
pub mod prelude {
    // just re-export everything, it's just shape definitions anyways
    #[doc(hidden)]
    pub use crate::{Measured2d, Measured3d, Primitive2d, Primitive3d, WindingOrder};

    #[doc(hidden)]
    pub use crate::bounding::*;

    #[doc(hidden)]
    pub use crate::dim2::*;

    #[doc(hidden)]
    pub use crate::dim3::*;

    #[doc(hidden)]
    pub use crate::half_space::*;

    #[doc(hidden)]
    pub use crate::inset::*;

    #[doc(hidden)]
    pub use crate::ray::{Ray2d, Ray3d};

    #[doc(hidden)]
    pub use crate::view_frustum::*;

    #[doc(hidden)]
    #[cfg(feature = "rand")]
    pub use crate::sampling::ShapeSample;

    #[doc(hidden)]
    #[cfg(feature = "alloc")]
    pub use crate::polygon::*;
}