rapier3d/counters/
collision_detection_counters.rs

1use crate::counters::Timer;
2use std::fmt::{Display, Formatter, Result};
3
4/// Performance counters related to collision detection.
5#[derive(Default, Clone, Copy)]
6pub struct CollisionDetectionCounters {
7    /// Number of contact pairs detected.
8    pub ncontact_pairs: usize,
9    /// Time spent for the broad-phase of the collision detection.
10    pub broad_phase_time: Timer,
11    /// Time spent for the narrow-phase of the collision detection.
12    pub narrow_phase_time: Timer,
13}
14
15impl CollisionDetectionCounters {
16    /// Creates a new counter initialized to zero.
17    pub fn new() -> Self {
18        CollisionDetectionCounters {
19            ncontact_pairs: 0,
20            broad_phase_time: Timer::new(),
21            narrow_phase_time: Timer::new(),
22        }
23    }
24
25    /// Resets all the counters and timers.
26    pub fn reset(&mut self) {
27        self.ncontact_pairs = 0;
28        self.broad_phase_time.reset();
29        self.narrow_phase_time.reset();
30    }
31}
32
33impl Display for CollisionDetectionCounters {
34    fn fmt(&self, f: &mut Formatter) -> Result {
35        writeln!(f, "Number of contact pairs: {}", self.ncontact_pairs)?;
36        writeln!(f, "Broad-phase time: {}", self.broad_phase_time)?;
37        writeln!(f, "Narrow-phase time: {}", self.narrow_phase_time)
38    }
39}