From ab21902226740b3ee09b827f80cd5db22c49ec9b Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Thu, 30 Nov 2023 20:57:12 +0200 Subject: [PATCH 1/2] Rename `cast_ray` to `raycast`, `ray_hits` to `raycast_many` and so on --- src/plugins/spatial_query/mod.rs | 8 ++-- src/plugins/spatial_query/pipeline.rs | 28 ++++++------- src/plugins/spatial_query/system_param.rs | 48 +++++++++++------------ 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/plugins/spatial_query/mod.rs b/src/plugins/spatial_query/mod.rs index 1ca5913b..a964760a 100644 --- a/src/plugins/spatial_query/mod.rs +++ b/src/plugins/spatial_query/mod.rs @@ -25,8 +25,8 @@ //! in the [`RayHits`] component every frame. It uses local coordinates, so it will automatically follow the entity //! it's attached to or its parent. //! 2. When you need more control or don't want to cast every frame, use the raycasting methods provided by -//! [`SpatialQuery`], like [`cast_ray`](SpatialQuery::cast_ray), [`ray_hits`](SpatialQuery::ray_hits) or -//! [`ray_hits_callback`](SpatialQuery::ray_hits_callback). +//! [`SpatialQuery`], like [`raycast`](SpatialQuery::raycast), [`raycast_many`](SpatialQuery::raycast_many) or +//! [`raycast_callback`](SpatialQuery::raycast_callback). //! //! See the documentation of the components and methods for more information. //! @@ -80,8 +80,8 @@ //! in the [`ShapeHits`] component every frame. It uses local coordinates, so it will automatically follow the entity //! it's attached to or its parent. //! 2. When you need more control or don't want to cast every frame, use the shapecasting methods provided by -//! [`SpatialQuery`], like [`cast_shape`](SpatialQuery::cast_shape), [`shape_hits`](SpatialQuery::shape_hits) or -//! [`shape_hits_callback`](SpatialQuery::shape_hits_callback). +//! [`SpatialQuery`], like [`shapecast`](SpatialQuery::shapecast), [`shapecast_many`](SpatialQuery::shapecast_many) or +//! [`shapecast_callback`](SpatialQuery::shapecast_callback). //! //! See the documentation of the components and methods for more information. //! diff --git a/src/plugins/spatial_query/pipeline.rs b/src/plugins/spatial_query/pipeline.rs index 36f39095..c2ea2fcf 100644 --- a/src/plugins/spatial_query/pipeline.rs +++ b/src/plugins/spatial_query/pipeline.rs @@ -145,8 +145,8 @@ impl SpatialQueryPipeline { /// Otherwise, the collider will be treated as hollow, and the hit point will be at the collider's boundary. /// - `query_filter`: A [`SpatialQueryFilter`] that determines which colliders are taken into account in the query. /// - /// See also: [`SpatialQuery::cast_ray`] - pub fn cast_ray( + /// See also: [`SpatialQuery::raycast`] + pub fn raycast( &self, origin: Vector, direction: Vector, @@ -187,8 +187,8 @@ impl SpatialQueryPipeline { /// Otherwise, the collider will be treated as hollow, and the hit point will be at the collider's boundary. /// - `query_filter`: A [`SpatialQueryFilter`] that determines which colliders are taken into account in the query. /// - /// See also: [`SpatialQuery::ray_hits`] - pub fn ray_hits( + /// See also: [`SpatialQuery::raycast_many`] + pub fn raycast_many( &self, origin: Vector, direction: Vector, @@ -198,7 +198,7 @@ impl SpatialQueryPipeline { query_filter: SpatialQueryFilter, ) -> Vec { let mut hits = Vec::with_capacity(10); - self.ray_hits_callback( + self.raycast_callback( origin, direction, max_time_of_impact, @@ -227,8 +227,8 @@ impl SpatialQueryPipeline { /// - `query_filter`: A [`SpatialQueryFilter`] that determines which colliders are taken into account in the query. /// - `callback`: A callback function called for each hit. /// - /// See also: [`SpatialQuery::ray_hits_callback`] - pub fn ray_hits_callback( + /// See also: [`SpatialQuery::raycast_callback`] + pub fn raycast_callback( &self, origin: Vector, direction: Vector, @@ -286,9 +286,9 @@ impl SpatialQueryPipeline { /// hit will be returned. /// - `query_filter`: A [`SpatialQueryFilter`] that determines which colliders are taken into account in the query. /// - /// See also: [`SpatialQuery::cast_shape`] + /// See also: [`SpatialQuery::shapecast`] #[allow(clippy::too_many_arguments)] - pub fn cast_shape( + pub fn shapecast( &self, shape: &Collider, origin: Vector, @@ -350,9 +350,9 @@ impl SpatialQueryPipeline { /// - `query_filter`: A [`SpatialQueryFilter`] that determines which colliders are taken into account in the query. /// - `callback`: A callback function called for each hit. /// - /// See also: [`SpatialQuery::shape_hits`] + /// See also: [`SpatialQuery::shapecast_many`] #[allow(clippy::too_many_arguments)] - pub fn shape_hits( + pub fn shapecast_many( &self, shape: &Collider, origin: Vector, @@ -364,7 +364,7 @@ impl SpatialQueryPipeline { query_filter: SpatialQueryFilter, ) -> Vec { let mut hits = Vec::with_capacity(10); - self.shape_hits_callback( + self.shapecast_callback( shape, origin, shape_rotation, @@ -397,9 +397,9 @@ impl SpatialQueryPipeline { /// - `query_filter`: A [`SpatialQueryFilter`] that determines which colliders are taken into account in the query. /// - `callback`: A callback function called for each hit. /// - /// See also: [`SpatialQuery::shape_hits_callback`] + /// See also: [`SpatialQuery::shapecast_callback`] #[allow(clippy::too_many_arguments)] - pub fn shape_hits_callback( + pub fn shapecast_callback( &self, shape: &Collider, origin: Vector, diff --git a/src/plugins/spatial_query/system_param.rs b/src/plugins/spatial_query/system_param.rs index cd7ac3c6..835ff169 100644 --- a/src/plugins/spatial_query/system_param.rs +++ b/src/plugins/spatial_query/system_param.rs @@ -5,10 +5,10 @@ use bevy::{ecs::system::SystemParam, prelude::*}; /// /// ## Methods /// -/// - [Raycasting](spatial_query#raycasting): [`cast_ray`](SpatialQuery::cast_ray), -/// [`ray_hits`](SpatialQuery::ray_hits), [`ray_hits_callback`](SpatialQuery::ray_hits_callback) -/// - [Shapecasting](spatial_query#shapecasting): [`cast_shape`](SpatialQuery::cast_shape), -/// [`shape_hits`](SpatialQuery::shape_hits), [`shape_hits_callback`](SpatialQuery::shape_hits_callback) +/// - [Raycasting](spatial_query#raycasting): [`raycast`](SpatialQuery::raycast), +/// [`raycast_many`](SpatialQuery::raycast_many), [`raycast_callback`](SpatialQuery::raycast_callback) +/// - [Shapecasting](spatial_query#shapecasting): [`shapecast`](SpatialQuery::shapecast), +/// [`shapecast_many`](SpatialQuery::shapecast_many), [`shapecast_callback`](SpatialQuery::shapecast_callback) /// - [Point projection](spatial_query#point-projection): [`project_point`](SpatialQuery::project_point) /// - [Intersection tests](spatial_query#intersection-tests) /// - Point intersections: [`point_intersections`](SpatialQuery::point_intersections), @@ -33,7 +33,7 @@ use bevy::{ecs::system::SystemParam, prelude::*}; /// # #[cfg(all(feature = "3d", feature = "f32"))] /// fn print_hits(spatial_query: SpatialQuery) { /// // Cast ray and print first hit -/// if let Some(first_hit) = spatial_query.cast_ray( +/// if let Some(first_hit) = spatial_query.raycast( /// Vec3::ZERO, // Origin /// Vec3::X, // Direction /// 100.0, // Maximum time of impact (travel distance) @@ -44,7 +44,7 @@ use bevy::{ecs::system::SystemParam, prelude::*}; /// } /// /// // Cast ray and get up to 20 hits -/// let hits = spatial_query.ray_hits( +/// let hits = spatial_query.raycast_many( /// Vec3::ZERO, // Origin /// Vec3::X, // Direction /// 100.0, // Maximum time of impact (travel distance) @@ -110,7 +110,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// # #[cfg(all(feature = "3d", feature = "f32"))] /// fn print_hits(spatial_query: SpatialQuery) { /// // Cast ray and print first hit - /// if let Some(first_hit) = spatial_query.cast_ray( + /// if let Some(first_hit) = spatial_query.raycast( /// Vec3::ZERO, // Origin /// Vec3::X, // Direction /// 100.0, // Maximum time of impact (travel distance) @@ -121,7 +121,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// } /// } /// ``` - pub fn cast_ray( + pub fn raycast( &self, origin: Vector, direction: Vector, @@ -130,7 +130,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { query_filter: SpatialQueryFilter, ) -> Option { self.query_pipeline - .cast_ray(origin, direction, max_time_of_impact, solid, query_filter) + .raycast(origin, direction, max_time_of_impact, solid, query_filter) } /// Casts a [ray](spatial_query#raycasting) and computes all [hits](RayHitData) until `max_hits` is reached. @@ -160,7 +160,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// # #[cfg(all(feature = "3d", feature = "f32"))] /// fn print_hits(spatial_query: SpatialQuery) { /// // Cast ray and get hits - /// let hits = spatial_query.ray_hits( + /// let hits = spatial_query.raycast_many( /// Vec3::ZERO, // Origin /// Vec3::X, // Direction /// 100.0, // Maximum time of impact (travel distance) @@ -175,7 +175,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// } /// } /// ``` - pub fn ray_hits( + pub fn raycast_many( &self, origin: Vector, direction: Vector, @@ -184,7 +184,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { solid: bool, query_filter: SpatialQueryFilter, ) -> Vec { - self.query_pipeline.ray_hits( + self.query_pipeline.raycast_many( origin, direction, max_time_of_impact, @@ -223,7 +223,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// let mut hits = vec![]; /// /// // Cast ray and get all hits - /// spatial_query.ray_hits_callback( + /// spatial_query.raycast_callback( /// Vec3::ZERO, // Origin /// Vec3::X, // Direction /// 100.0, // Maximum time of impact (travel distance) @@ -241,7 +241,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// } /// } /// ``` - pub fn ray_hits_callback( + pub fn raycast_callback( &self, origin: Vector, direction: Vector, @@ -250,7 +250,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { query_filter: SpatialQueryFilter, callback: impl FnMut(RayHitData) -> bool, ) { - self.query_pipeline.ray_hits_callback( + self.query_pipeline.raycast_callback( origin, direction, max_time_of_impact, @@ -289,7 +289,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// # #[cfg(all(feature = "3d", feature = "f32"))] /// fn print_hits(spatial_query: SpatialQuery) { /// // Cast ray and print first hit - /// if let Some(first_hit) = spatial_query.cast_shape( + /// if let Some(first_hit) = spatial_query.shapecast( /// &Collider::ball(0.5), // Shape /// Vec3::ZERO, // Origin /// Quat::default(), // Shape rotation @@ -303,7 +303,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// } /// ``` #[allow(clippy::too_many_arguments)] - pub fn cast_shape( + pub fn shapecast( &self, shape: &Collider, origin: Vector, @@ -313,7 +313,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { ignore_origin_penetration: bool, query_filter: SpatialQueryFilter, ) -> Option { - self.query_pipeline.cast_shape( + self.query_pipeline.shapecast( shape, origin, shape_rotation, @@ -353,7 +353,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// # #[cfg(all(feature = "3d", feature = "f32"))] /// fn print_hits(spatial_query: SpatialQuery) { /// // Cast shape and get all hits - /// let hits = spatial_query.shape_hits( + /// let hits = spatial_query.shapecast_many( /// &Collider::ball(0.5), // Shape /// Vec3::ZERO, // Origin /// Quat::default(), // Shape rotation @@ -371,7 +371,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// } /// ``` #[allow(clippy::too_many_arguments)] - pub fn shape_hits( + pub fn shapecast_many( &self, shape: &Collider, origin: Vector, @@ -382,7 +382,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { ignore_origin_penetration: bool, query_filter: SpatialQueryFilter, ) -> Vec { - self.query_pipeline.shape_hits( + self.query_pipeline.shapecast_many( shape, origin, shape_rotation, @@ -425,7 +425,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// let mut hits = vec![]; /// /// // Cast shape and get all hits - /// spatial_query.shape_hits_callback( + /// spatial_query.shapecast_callback( /// &Collider::ball(0.5), // Shape /// Vec3::ZERO, // Origin /// Quat::default(), // Shape rotation @@ -446,7 +446,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { /// } /// ``` #[allow(clippy::too_many_arguments)] - pub fn shape_hits_callback( + pub fn shapecast_callback( &self, shape: &Collider, origin: Vector, @@ -457,7 +457,7 @@ impl<'w, 's> SpatialQuery<'w, 's> { query_filter: SpatialQueryFilter, callback: impl FnMut(ShapeHitData) -> bool, ) { - self.query_pipeline.shape_hits_callback( + self.query_pipeline.shapecast_callback( shape, origin, shape_rotation, From b424e2da1d405d039d27a2d70fa9c1637a7963dc Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Thu, 30 Nov 2023 21:32:58 +0200 Subject: [PATCH 2/2] Add old methods as deprecated --- src/plugins/spatial_query/system_param.rs | 137 ++++++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/src/plugins/spatial_query/system_param.rs b/src/plugins/spatial_query/system_param.rs index 835ff169..23debf35 100644 --- a/src/plugins/spatial_query/system_param.rs +++ b/src/plugins/spatial_query/system_param.rs @@ -133,6 +133,19 @@ impl<'w, 's> SpatialQuery<'w, 's> { .raycast(origin, direction, max_time_of_impact, solid, query_filter) } + /// Deprecated, use [`SpatialQuery::raycast()`] instead. + #[deprecated(since = "0.4.0", note = "renamed, please use `raycast` instead")] + pub fn cast_ray( + &self, + origin: Vector, + direction: Vector, + max_time_of_impact: Scalar, + solid: bool, + query_filter: SpatialQueryFilter, + ) -> Option { + self.raycast(origin, direction, max_time_of_impact, solid, query_filter) + } + /// Casts a [ray](spatial_query#raycasting) and computes all [hits](RayHitData) until `max_hits` is reached. /// /// Note that the order of the results is not guaranteed, and if there are more hits than `max_hits`, @@ -194,6 +207,27 @@ impl<'w, 's> SpatialQuery<'w, 's> { ) } + /// Deprecated, use [`SpatialQuery::raycast_many()`] instead. + #[deprecated(since = "0.4.0", note = "renamed, please use `raycast_many` instead")] + pub fn ray_hits( + &self, + origin: Vector, + direction: Vector, + max_time_of_impact: Scalar, + max_hits: u32, + solid: bool, + query_filter: SpatialQueryFilter, + ) -> Vec { + self.raycast_many( + origin, + direction, + max_time_of_impact, + max_hits, + solid, + query_filter, + ) + } + /// Casts a [ray](spatial_query#raycasting) and computes all [hits](RayHitData), calling the given `callback` /// for each hit. The raycast stops when `callback` returns false or all hits have been found. /// @@ -260,6 +294,30 @@ impl<'w, 's> SpatialQuery<'w, 's> { ) } + /// Deprecated, use [`SpatialQuery::raycast_many()`] instead. + #[deprecated( + since = "0.4.0", + note = "renamed, please use `raycast_callback` instead" + )] + pub fn ray_hits_callback( + &self, + origin: Vector, + direction: Vector, + max_time_of_impact: Scalar, + solid: bool, + query_filter: SpatialQueryFilter, + callback: impl FnMut(RayHitData) -> bool, + ) { + self.raycast_callback( + origin, + direction, + max_time_of_impact, + solid, + query_filter, + callback, + ) + } + /// Casts a [shape](spatial_query#shapecasting) with a given rotation and computes the closest [hit](ShapeHits) /// with a collider. If there are no hits, `None` is returned. /// @@ -324,6 +382,30 @@ impl<'w, 's> SpatialQuery<'w, 's> { ) } + /// Deprecated, use [`SpatialQuery::shapecast()`] instead. + #[deprecated(since = "0.4.0", note = "renamed, please use `shapecast` instead")] + #[allow(clippy::too_many_arguments)] + pub fn cast_shape( + &self, + shape: &Collider, + origin: Vector, + shape_rotation: RotationValue, + direction: Vector, + max_time_of_impact: Scalar, + ignore_origin_penetration: bool, + query_filter: SpatialQueryFilter, + ) -> Option { + self.query_pipeline.shapecast( + shape, + origin, + shape_rotation, + direction, + max_time_of_impact, + ignore_origin_penetration, + query_filter, + ) + } + /// Casts a [shape](spatial_query#shapecasting) with a given rotation and computes computes all [hits](ShapeHitData) /// in the order of the time of impact until `max_hits` is reached. /// @@ -394,6 +476,32 @@ impl<'w, 's> SpatialQuery<'w, 's> { ) } + /// Deprecated, use [`SpatialQuery::shapecast_many()`] instead. + #[deprecated(since = "0.4.0", note = "renamed, please use `shapecast_many` instead")] + #[allow(clippy::too_many_arguments)] + pub fn shape_hits( + &self, + shape: &Collider, + origin: Vector, + shape_rotation: RotationValue, + direction: Vector, + max_time_of_impact: Scalar, + max_hits: u32, + ignore_origin_penetration: bool, + query_filter: SpatialQueryFilter, + ) -> Vec { + self.query_pipeline.shapecast_many( + shape, + origin, + shape_rotation, + direction, + max_time_of_impact, + max_hits, + ignore_origin_penetration, + query_filter, + ) + } + /// Casts a [shape](spatial_query#shapecasting) with a given rotation and computes computes all [hits](ShapeHitData) /// in the order of the time of impact, calling the given `callback` for each hit. The shapecast stops when /// `callback` returns false or all hits have been found. @@ -469,6 +577,35 @@ impl<'w, 's> SpatialQuery<'w, 's> { ) } + /// Deprecated, use [`SpatialQuery::shapecast_callback()`] instead. + #[deprecated( + since = "0.4.0", + note = "renamed, please use `shapecast_callback` instead" + )] + #[allow(clippy::too_many_arguments)] + pub fn shape_hits_callback( + &self, + shape: &Collider, + origin: Vector, + shape_rotation: RotationValue, + direction: Vector, + max_time_of_impact: Scalar, + ignore_origin_penetration: bool, + query_filter: SpatialQueryFilter, + callback: impl FnMut(ShapeHitData) -> bool, + ) { + self.query_pipeline.shapecast_callback( + shape, + origin, + shape_rotation, + direction, + max_time_of_impact, + ignore_origin_penetration, + query_filter, + callback, + ) + } + /// Finds the [projection](spatial_query#point-projection) of a given point on the closest [collider](Collider). /// If one isn't found, `None` is returned. ///