nphysics2d/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
26impl Display for CollisionDetectionCounters {
27    fn fmt(&self, f: &mut Formatter) -> Result {
28        writeln!(f, "Number of contact pairs: {}", self.ncontact_pairs)?;
29        writeln!(f, "Broad-phase time: {}", self.broad_phase_time)?;
30        writeln!(f, "Narrow-phase time: {}", self.narrow_phase_time)
31    }
32}