Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ seq-macro = "0.3.6"
bevy_app = { path = "../crates/bevy_app" }
bevy_ecs = { path = "../crates/bevy_ecs", features = ["multi_threaded"] }
bevy_math = { path = "../crates/bevy_math" }
bevy_shape = { path = "../crates/bevy_shape" }
bevy_geometry = { path = "../crates/bevy_geometry" }
bevy_picking = { path = "../crates/bevy_picking", features = ["mesh_picking"] }
bevy_reflect = { path = "../crates/bevy_reflect", features = ["functions"] }
bevy_camera = { path = "../crates/bevy_camera" }
Expand Down
6 changes: 2 additions & 4 deletions benches/benches/bevy_camera/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use bevy_camera::primitives::{Aabb, Frustum, Sphere};
use bevy_math::{
primitives::{HalfSpace, ViewFrustum},
Affine3A, Quat, Vec3, Vec3A, Vec4,
};
use bevy_math::{Affine3A, Quat, Vec3, Vec3A, Vec4};
use bevy_shape::{HalfSpace, ViewFrustum};
use core::hint::black_box;
use criterion::{criterion_group, Criterion};

Expand Down
6 changes: 2 additions & 4 deletions benches/benches/bevy_math/bounding.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use benches::bench;
use bevy_math::{
bounding::{Aabb3d, BoundingSphere, BoundingVolume},
prelude::*,
};
use bevy_geometry::bounding::{Aabb3d, BoundingSphere, BoundingVolume};
use bevy_math::prelude::*;
use core::hint::black_box;
use criterion::{criterion_group, Criterion};
use rand::{
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_camera/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ bevy_asset = { path = "../bevy_asset", version = "0.20.0-dev" }
bevy_image = { path = "../bevy_image", version = "0.20.0-dev" }
bevy_mesh = { path = "../bevy_mesh", version = "0.20.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.20.0-dev" }
bevy_shape = { path = "../bevy_shape", version = "0.20.0-dev" }
bevy_geometry = { path = "../bevy_geometry", version = "0.20.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.20.0-dev", features = [
"wgpu-types",
] }
Expand Down
8 changes: 3 additions & 5 deletions crates/bevy_camera/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ use core::borrow::Borrow;

use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{component::Component, entity::EntityHashMap, reflect::ReflectComponent};
use bevy_math::{
bounding::{Aabb3d, BoundingVolume},
primitives::{HalfSpace, ViewFrustum},
Affine3A, Mat3A, Vec3, Vec3A,
};
use bevy_geometry::bounding::{Aabb3d, BoundingVolume};
use bevy_math::{Affine3A, Mat3A, Vec3, Vec3A};
use bevy_mesh::{Mesh, VertexAttributeValues};
use bevy_reflect::prelude::*;
use bevy_shape::{HalfSpace, ViewFrustum};

pub trait MeshAabb {
/// Compute the Axis-Aligned Bounding Box of the mesh vertices in model space,
Expand Down
5 changes: 2 additions & 3 deletions crates/bevy_camera/src/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use core::ops::{Deref, DerefMut};
use crate::{primitives::Frustum, visibility::VisibilitySystems};
use bevy_app::{App, Plugin, PostUpdate};
use bevy_ecs::prelude::*;
use bevy_math::{
ops, primitives::ViewFrustum, proj, vec4, AspectRatio, Mat4, Rect, Vec2, Vec3A, Vec4,
};
use bevy_math::{ops, proj, vec4, AspectRatio, Mat4, Rect, Vec2, Vec3A, Vec4};
use bevy_reflect::{std_traits::ReflectDefault, Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_shape::ViewFrustum;
use bevy_transform::{components::GlobalTransform, TransformSystems};
use derive_more::derive::From;
use serde::{Deserialize, Serialize};
Expand Down
98 changes: 98 additions & 0 deletions crates/bevy_geometry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
[package]
description = "Provides geometric functionality primitive shapes for Bevy Engine"
edition = "2024"
homepage = "https://bevy.org"
keywords = ["bevy"]
license = "MIT OR Apache-2.0"
name = "bevy_geometry"
repository = "https://github.com/bevyengine/bevy"
rust-version = "1.94.0"
version = "0.20.0-dev"

[dependencies]
approx = { default-features = false, optional = true, version = "0.5" }
arrayvec = { default-features = false, version = "0.7" }
bevy_math = { default-features = false, path = "../bevy_math" }
bevy_reflect = { default-features = false, features = [
"glam",
], optional = true, path = "../bevy_reflect", version = "0.20.0-dev" }
bevy_shape = { default-features = false, path = "../bevy_shape" }
derive_more = { default-features = false, features = [
"from",
"into",
], version = "2" }
itertools = { default-features = false, version = "0.14.0" }
rand = { default-features = false, optional = true, version = "0.10" }
rand_distr = { optional = true, version = "0.6" }
serde = { default-features = false, features = [
"derive",
], optional = true, version = "1" }
thiserror = { default-features = false, version = "2" }
variadics_please = "2.0"

[dev-dependencies]
approx = "0.5"
# Supply rngs for examples and tests
chacha20 = { default-features = false, features = ["rng"], version = "0.10.0" }
rand = "0.10"
# Enable the approx feature when testing.
bevy_math = { default-features = false, features = [
"approx",
], path = "../bevy_math" }
bevy_shape = { default-features = false, features = [
"approx",
], path = "../bevy_shape" }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
getrandom = { default-features = false, features = [
"wasm_js",
], version = "0.4" }

[features]
alloc = [
"bevy_math/alloc",
"bevy_shape/alloc",
"itertools/use_alloc",
"rand?/alloc",
"rand_distr?/alloc",
"serde?/alloc",
]
default = ["curve", "rand", "std"]
std = [
"alloc",
"approx?/std",
"bevy_math/std",
"bevy_reflect?/std",
"bevy_shape/std",
"derive_more/std",
"itertools/use_std",
"rand?/std",
"rand_distr?/std",
"serde?/std",
]

serialize = ["bevy_math/serialize", "bevy_shape/serialize", "dep:serde"]
# Enable approx for glam types to approximate floating point equality comparisons and assertions
approx = ["bevy_math/approx", "bevy_shape/approx", "dep:approx"]
# Enable the rand dependency for shape_sampling
rand = ["dep:rand", "dep:rand_distr"]
# Include code related to the Curve trait
curve = []
# Enable bevy_reflect (requires alloc)
bevy_reflect = [
"alloc",
"bevy_math/bevy_reflect",
"bevy_shape/bevy_reflect",
"dep:bevy_reflect",
]

[lints]
workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = [
"--generate-link-to-definition",
"--generate-macro-expansion",
"-Zunstable-options",
]
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
mod primitive_impls;

use super::{BoundingVolume, IntersectsVolume};
use crate::{
ops,
prelude::{Mat2, Rot2, Vec2},
FloatPow, Isometry2d,
};
use crate::bounding::{BoundingVolume, IntersectsVolume};
use bevy_math::{ops, FloatPow, Isometry2d, Mat2, Rot2, Vec2};

#[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect;
Expand Down Expand Up @@ -272,11 +268,11 @@ impl IntersectsVolume<BoundingCircle> for Aabb2d {
mod aabb2d_tests {
use approx::assert_relative_eq;

use super::Aabb2d;
use crate::{
bounding::{BoundingCircle, BoundingVolume, IntersectsVolume},
ops, Vec2,
use crate::bounding::{
bounded2d::{Aabb2d, BoundingCircle},
BoundingVolume, IntersectsVolume,
};
use bevy_math::{ops, Vec2};

#[test]
fn center() {
Expand Down Expand Up @@ -469,7 +465,7 @@ mod aabb2d_tests {
}
}

use crate::primitives::Circle;
use bevy_shape::Circle;

/// A bounding circle
#[derive(Clone, Copy, Debug, PartialEq)]
Expand Down Expand Up @@ -643,11 +639,8 @@ impl IntersectsVolume<Aabb2d> for BoundingCircle {

#[cfg(test)]
mod bounding_circle_tests {
use super::BoundingCircle;
use crate::{
bounding::{BoundingVolume, IntersectsVolume},
ops, Vec2,
};
use crate::bounding::{bounded2d::BoundingCircle, BoundingVolume, IntersectsVolume};
use bevy_math::{ops, Vec2};

#[test]
fn area() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
//! Contains [`Bounded2d`] implementations for [geometric primitives](crate::primitives).

use crate::{
bounding::BoundingVolume,
ops,
primitives::{
Annulus, Arc2d, Capsule2d, Circle, CircularSector, CircularSegment, Ellipse, Line2d,
Plane2d, Primitive2d, Rectangle, RegularPolygon, Rhombus, Ring, Segment2d, Triangle2d,
},
Dir2, Isometry2d, Mat2, Rot2, Vec2,
use crate::bounding::{
bounded2d::{Aabb2d, Bounded2d, BoundingCircle},
BoundingVolume,
};
use bevy_math::{ops, Dir2, Isometry2d, Mat2, Rot2, Vec2};
use bevy_shape::{
Annulus, Arc2d, Capsule2d, Circle, CircularSector, CircularSegment, Ellipse, Line2d, Plane2d,
Rectangle, RegularPolygon, Rhombus, Segment2d, Triangle2d,
};
use core::f32::consts::{FRAC_PI_2, PI, TAU};

#[cfg(feature = "alloc")]
use crate::primitives::{ConvexPolygon, Polygon, Polyline2d};
use bevy_shape::{ConvexPolygon, Polygon, Polyline2d};

use arrayvec::ArrayVec;

use super::{Aabb2d, Bounded2d, BoundingCircle};

impl Bounded2d for Circle {
fn aabb_2d(&self, isometry: impl Into<Isometry2d>) -> Aabb2d {
let isometry = isometry.into();
Expand Down Expand Up @@ -428,34 +426,22 @@ impl Bounded2d for Capsule2d {
}
}

impl<P: Bounded2d + Primitive2d> Bounded2d for Ring<P> {
fn aabb_2d(&self, isometry: impl Into<Isometry2d>) -> Aabb2d {
self.outer_shape.aabb_2d(isometry)
}

fn bounding_circle(&self, isometry: impl Into<Isometry2d>) -> BoundingCircle {
self.outer_shape.bounding_circle(isometry)
}
}

#[cfg(test)]
#[expect(clippy::print_stdout, reason = "Allowed in tests.")]
mod tests {
use core::f32::consts::{FRAC_PI_2, FRAC_PI_3, FRAC_PI_4, FRAC_PI_6, TAU};
use std::println;

use approx::assert_abs_diff_eq;
use glam::Vec2;

use crate::{
bounding::Bounded2d,
use bevy_math::{
ops::{self, FloatPow},
primitives::{
Annulus, Arc2d, Capsule2d, Circle, CircularSector, CircularSegment, Ellipse, Line2d,
Plane2d, Polygon, Polyline2d, Rectangle, RegularPolygon, Rhombus, Segment2d,
Triangle2d,
},
Dir2, Isometry2d, Rot2,
Dir2, Isometry2d, Rot2, Vec2,
};

use crate::bounding::bounded2d::Bounded2d;
use bevy_shape::{
Annulus, Arc2d, Capsule2d, Circle, CircularSector, CircularSegment, Ellipse, Line2d,
Plane2d, Polygon, Polyline2d, Rectangle, RegularPolygon, Rhombus, Segment2d, Triangle2d,
};

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
use core::f32::consts::FRAC_PI_2;

use glam::{Vec2, Vec3A, Vec3Swizzles};

use crate::{
bounding::{BoundingCircle, BoundingVolume},
ops,
primitives::{
Capsule2d, Cuboid, Cylinder, Ellipse, Extrusion, Line2d, Primitive2d, Rectangle,
RegularPolygon, Ring, Segment2d, Triangle2d,
},
Isometry2d, Isometry3d, Quat, Rot2,
use crate::bounding::{bounded2d::BoundingCircle, BoundingVolume};
use bevy_math::{ops, Isometry2d, Isometry3d, Quat, Rot2, Vec2, Vec3A, Vec3Swizzles};
use bevy_shape::{
Capsule2d, Circle, Cuboid, Cylinder, Ellipse, Extrusion, Line2d, Primitive2d, Rectangle,
RegularPolygon, Segment2d, Triangle2d,
};

#[cfg(feature = "alloc")]
use crate::primitives::{Polygon, Polyline2d};
use bevy_shape::{Polygon, Polyline2d};

use crate::{bounding::Bounded2d, primitives::Circle};
use crate::bounding::Bounded2d;

use super::{Aabb3d, Bounded3d, BoundingSphere};

Expand Down Expand Up @@ -165,21 +160,6 @@ impl BoundedExtrusion for Capsule2d {
}
}

impl<T: BoundedExtrusion> BoundedExtrusion for Ring<T> {
fn extrusion_aabb_3d(&self, half_depth: f32, isometry: impl Into<Isometry3d>) -> Aabb3d {
self.outer_shape.extrusion_aabb_3d(half_depth, isometry)
}

fn extrusion_bounding_sphere(
&self,
half_depth: f32,
isometry: impl Into<Isometry3d>,
) -> BoundingSphere {
self.outer_shape
.extrusion_bounding_sphere(half_depth, isometry)
}
}

impl<T: BoundedExtrusion> Bounded3d for Extrusion<T> {
fn aabb_3d(&self, isometry: impl Into<Isometry3d>) -> Aabb3d {
self.base_shape.extrusion_aabb_3d(self.half_depth, isometry)
Expand Down Expand Up @@ -260,16 +240,11 @@ pub trait BoundedExtrusion: Primitive2d + Bounded2d {
mod tests {
use core::f32::consts::FRAC_PI_4;

use glam::{EulerRot, Quat, Vec2, Vec3, Vec3A};

use crate::{
bounding::{Bounded3d, BoundingVolume},
ops,
primitives::{
Capsule2d, Circle, Ellipse, Extrusion, Line2d, Polygon, Polyline2d, Rectangle,
RegularPolygon, Segment2d, Triangle2d,
},
Dir2, Isometry3d,
use crate::bounding::{bounded3d::Bounded3d, BoundingVolume};
use bevy_math::{ops, Dir2, EulerRot, Isometry3d, Quat, Vec2, Vec3, Vec3A};
use bevy_shape::{
Capsule2d, Circle, Ellipse, Extrusion, Line2d, Polygon, Polyline2d, Rectangle,
RegularPolygon, Segment2d, Triangle2d,
};

#[test]
Expand Down
Loading
Loading