rapier2d/counters/
collision_detection_counters.rs1use crate::counters::Timer;
2use std::fmt::{Display, Formatter, Result};
3
4#[derive(Default, Clone, Copy)]
6pub struct CollisionDetectionCounters {
7 pub ncontact_pairs: usize,
9 pub broad_phase_time: Timer,
11 pub final_broad_phase_time: Timer,
14 pub narrow_phase_time: Timer,
16}
17
18impl CollisionDetectionCounters {
19 pub fn new() -> Self {
21 CollisionDetectionCounters {
22 ncontact_pairs: 0,
23 broad_phase_time: Timer::new(),
24 final_broad_phase_time: Timer::new(),
25 narrow_phase_time: Timer::new(),
26 }
27 }
28
29 pub fn reset(&mut self) {
31 self.ncontact_pairs = 0;
32 self.broad_phase_time.reset();
33 self.final_broad_phase_time.reset();
34 self.narrow_phase_time.reset();
35 }
36}
37
38impl Display for CollisionDetectionCounters {
39 fn fmt(&self, f: &mut Formatter) -> Result {
40 writeln!(f, "Number of contact pairs: {}", self.ncontact_pairs)?;
41 writeln!(f, "Broad-phase time: {}", self.broad_phase_time)?;
42 writeln!(f, "Final broad-phase time: {}", self.final_broad_phase_time)?;
43 writeln!(f, "Narrow-phase time: {}", self.narrow_phase_time)
44 }
45}