Skip to content

Commit

Permalink
jaguars: improve readability + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenGar committed Feb 14, 2024
1 parent ebe928f commit 47f4b56
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::geometry::primitives::point::Point;

/// Generates a grid of equal sized square rectangles within a shape.
/// The number of cells is approximately equal to target_n_cells, but can be slightly more or less
/// This is due to the fact that the cells are always remain square, so we cannot guarantee an exact number of cells
pub fn generate(bbox: AARectangle, hazards: &[Hazard], target_n_cells: usize) -> Vec<AARectangle> {
assert!(bbox.area() > 0.0, "bbox has zero area");

Expand Down
31 changes: 14 additions & 17 deletions jaguars/src/collision_detection/quadtree/qt_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use crate::collision_detection::quadtree::qt_hazard::QTHazard;
use crate::collision_detection::quadtree::qt_hazard::QTHazPresence;
use crate::collision_detection::quadtree::qt_hazard_vec::QTHazardVec;
use crate::collision_detection::quadtree::qt_partial_hazard::QTPartialHazard;
use crate::geometry::geo_traits::{CollidesWith};
use crate::geometry::geo_traits::CollidesWith;
use crate::geometry::primitives::aa_rectangle::AARectangle;
use crate::geometry::primitives::point::Point;


/// A node in the quadtree
#[derive(Clone, Debug)]
pub struct QTNode {
Expand Down Expand Up @@ -140,6 +139,7 @@ impl QTNode {

/// Returns None if no collision between the entity and any hazard is detected,
/// otherwise returns the first encountered hazard that collides with the entity
/// In practice T is usually an `Edge` or `Circle`
pub fn collides<T>(&self, entity: &T, irrelevant_hazards: &[HazardEntity]) -> Option<&HazardEntity>
where T: CollidesWith<AARectangle>, QTPartialHazard: CollidesWith<T>
{
Expand All @@ -152,27 +152,24 @@ impl QTNode {
QTHazPresence::Entire => Some(&strongest_hazard.entity),
QTHazPresence::Partial(_) => match self.children() {
Some(children) => {
//Search if any of the children intersect with the entity
//Check if any of the children intersect with the entity
children.iter()
.map(|child| child.collides(entity, irrelevant_hazards))
.find(|x| x.is_some())
.flatten()
}
None => {
for hz in self.hazards.active_hazards() {
//Check if any of the partially present (and active) hazards collide with the entity
self.hazards.active_hazards().iter().find(|hz| {
match &hz.presence {
QTHazPresence::Entire | QTHazPresence::None => {} //non-ignored Entire inclusion are caught by the previous match
QTHazPresence::Partial(partial_hazard) => {
if !irrelevant_hazards.contains(&hz.entity) {
//do intersection test if this shape is not ignored
if partial_hazard.collides_with(entity) {
return Some(&hz.entity);
}
}
QTHazPresence::None => false,
QTHazPresence::Entire => unreachable!("should have been handled above"),
QTHazPresence::Partial(p_haz) => {
!irrelevant_hazards.contains(&hz.entity) &&
p_haz.collides_with(entity)
}
}
}
None
}).map(|hz| &hz.entity)
}
}
}
Expand All @@ -195,9 +192,9 @@ impl QTNode {
for i in 0..4 {
let child = &children[i];
match child.definitely_collides(entity, irrelevant_hazards) {
Tribool::True => return Tribool::True, //If a child for sure collides, we can immediately return Yes
Tribool::Indeterminate => result = Tribool::Indeterminate, //If a child might collide, switch from to Maybe
Tribool::False => {} //If child does not collide, do nothing
Tribool::True => return Tribool::True,
Tribool::Indeterminate => result = Tribool::Indeterminate,
Tribool::False => {}
}
}
result
Expand Down
4 changes: 2 additions & 2 deletions jaguars/src/geometry/fail_fast/sp_surrogate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ impl SPSurrogate {

let relevant_poles_for_piers = &poles[0..config.n_ff_poles+1]; //poi + all poles that will be checked during fail fast are relevant for piers
let piers = piers::generate(simple_poly, config.n_ff_piers, relevant_poles_for_piers);
let ff_poles = 1..config.n_ff_poles+1;
let ff_pole_range = 1..config.n_ff_poles+1;

Self {
convex_hull_indices,
poles,
piers,
poles_bounding_circle,
ff_pole_range: ff_poles
ff_pole_range
}
}

Expand Down

0 comments on commit 47f4b56

Please sign in to comment.