Skip to content

Commit

Permalink
performance optimization for shallow quadtrees
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenGar committed Feb 12, 2024
1 parent d0d9a3f commit 6ac1032
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions jaguars/src/collision_detection/quadtree/qt_partial_hazard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ impl QTPartialHazard {
}

}

pub const BBOX_CHECK_THRESHOLD: usize = 4;
impl CollidesWith<Edge> for QTPartialHazard {
fn collides_with(&self, edge: &Edge) -> bool {
let shape = self.shape.upgrade().expect("polygon reference should be alive");
Expand All @@ -79,9 +81,16 @@ impl CollidesWith<Edge> for QTPartialHazard {
}
},
EdgeIndices::Some(indices) => {
indices.iter().any(|&i| {
edge.collides_with(&shape.get_edge(i))
})
match indices.len(){
0 => unreachable!("edge indices should not be empty"),
1..=BBOX_CHECK_THRESHOLD => indices.iter().any(|&i| edge.collides_with(&shape.get_edge(i))),
BBOX_CHECK_THRESHOLD.. => {
match shape.bbox().collides_with(edge) {
false => false,
true => indices.iter().any(|&i| edge.collides_with(&shape.get_edge(i)))
}
}
}
}
}
}
Expand All @@ -100,9 +109,16 @@ impl CollidesWith<Circle> for QTPartialHazard {
}
},
EdgeIndices::Some(indices) => {
indices.iter().any(|&i| {
circle.collides_with(&shape.get_edge(i))
})
match indices.len(){
0 => unreachable!("edge indices should not be empty"),
1..=BBOX_CHECK_THRESHOLD => indices.iter().any(|&i| circle.collides_with(&shape.get_edge(i))),
BBOX_CHECK_THRESHOLD.. => {
match circle.collides_with(&shape.bbox()) {
false => false,
true => indices.iter().any(|&i| circle.collides_with(&shape.get_edge(i)))
}
}
}
}
}
}
Expand Down

0 comments on commit 6ac1032

Please sign in to comment.