Skip to content

Commit

Permalink
Add clear methods for ray and shape hits and clear the hits on disa…
Browse files Browse the repository at this point in the history
…ble (#82)
  • Loading branch information
Jondolf authored Jul 17, 2023
1 parent 4b04ce9 commit b0d75a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
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

0 comments on commit b0d75a8

Please sign in to comment.