Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clear methods for ray and shape hits and clear the hits on disable #82

Merged
merged 1 commit into from
Jul 17, 2023
Merged
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
4 changes: 4 additions & 0 deletions src/plugins/spatial_query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ fn raycast(mut rays: Query<(&RayCaster, &mut RayHits)>, spatial_query: SpatialQu
for (ray, mut hits) in &mut rays {
if ray.enabled {
ray.cast(&mut hits, &spatial_query.query_pipeline);
} else if !hits.is_empty() {
hits.clear();
}
}
}
Expand All @@ -386,6 +388,8 @@ fn shapecast(
for (shape_caster, mut hits) in &mut shape_casters {
if shape_caster.enabled {
shape_caster.cast(&mut hits, &spatial_query.query_pipeline);
} else if !hits.is_empty() {
hits.clear();
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/spatial_query/ray_caster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ impl RayHits {
self.count == 0
}

/// Clears the hits.
pub fn clear(&mut self) {
self.vector.clear();
self.count = 0;
}

/// Returns an iterator over the hits in arbitrary order.
///
/// If you want to get them sorted by time of impact, use `iter_sorted`.
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/spatial_query/shape_caster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ impl ShapeHits {
self.count == 0
}

/// Clears the hits.
pub fn clear(&mut self) {
self.vector.clear();
self.count = 0;
}

/// Returns an iterator over the hits in the order of time of impact.
pub fn iter(&self) -> std::slice::Iter<ShapeHitData> {
self.as_slice().iter()
Expand Down