1use std::{
2 fmt::Display,
3 time::{Duration, Instant},
4};
5
6pub use camloc_common::{hosts::constants::MAIN_PORT, Position};
7
8mod calc;
9pub mod compass;
10pub mod extrapolations;
11pub mod service;
12
13#[derive(Clone, Copy)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub enum MotionHint {
16 MovingForwards,
17 MovingBackwards,
18 Stationary,
19}
20
21#[derive(Debug, PartialEq, Clone, Copy)]
22#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23pub struct PlacedCamera {
24 pub fov: f64,
26 pub position: Position,
27}
28
29impl PlacedCamera {
30 pub fn new(position: Position, fov: f64) -> Self {
31 Self { position, fov }
32 }
33}
34
35#[derive(Debug, Clone, Copy)]
36pub struct TimedPosition {
37 pub position: Position,
38 start_time: Instant,
39 pub time: Instant,
40
41 pub extrapolated_by: Option<Duration>,
44}
45
46impl Display for TimedPosition {
47 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48 let pos = &self.position;
49 let t = self.time - self.start_time;
50
51 if let Some(from) = self.extrapolated_by {
52 write!(f, "[{pos} @ {from:.2?} -> {t:.2?}]")
53 } else {
54 write!(f, "[{pos} @ {t:.2?}]")
55 }
56 }
57}