diff --git a/src/boxes.rs b/src/boxes.rs new file mode 100644 index 0000000..b424b42 --- /dev/null +++ b/src/boxes.rs @@ -0,0 +1,57 @@ +use std::fmt::Display; +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Copy)] +pub struct BoxCoords { + pub id: u32, + pub x1: u32, + pub y1: u32, + pub x2: u32, + pub y2: u32, +} + +impl Display for BoxCoords { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "Absolute Box {}, x1: {}, y1: {}, x2: {}, y2: {}", + self.id, self.x1, self.y1, self.x2, self.y2 + ) + } +} + + +#[derive(Serialize, Deserialize, Debug, Clone, Copy)] +pub struct NormalizedBoxCoords { + pub id: u32, + pub x1: f32, + pub y1: f32, + pub x2: f32, + pub y2: f32, +} + +impl NormalizedBoxCoords { + fn absolute_coords(&self, width: i32, height: i32) -> BoxCoords { + BoxCoords { + id: self.id, + x1: (self.x1 * width as f32) as u32, + y1: (self.y1 * height as f32) as u32, + x2: (self.x2 * width as f32) as u32, + y2: (self.y2 * height as f32) as u32, + } + } + + fn area(&self) -> f32 { + (self.x2 - self.x1) * (self.y2 - self.y1) + } +} + +impl Display for NormalizedBoxCoords { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "Normalized Box {}, x1: {}, y1: {}, x2: {}, y2: {}", + self.id, self.x1, self.y1, self.x2, self.y2 + ) + } +} diff --git a/src/lib.rs b/src/lib.rs index 538dabe..760260a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,13 @@ use tracing::{error, info, debug, instrument}; use webrtc::peer_connection::sdp::session_description::RTCSessionDescription; use webrtc::ice_transport::ice_candidate::{RTCIceCandidate, RTCIceCandidateInit}; +mod boxes; +use boxes::NormalizedBoxCoords; + +pub mod types { + pub use crate::boxes::NormalizedBoxCoords; +} + static MAX_MESSAGE: usize = 50; /// Standardized messages that can be sent between the controller @@ -23,6 +30,11 @@ pub enum ApplicationMessage { /// Ask for the satellite's name. If it is None, it is a name request /// if it is Some, it is a response to a name request NameRequest(Option), + + ChangeTrackingID(u16), + TrackingBoxes(Vec), + ManualMovementOverride((i32, i32)), + WebRTCPacket(RTCSessionDescription), WebRTCIceCandidate(RTCIceCandidate), WebRTCIceCandidateInit(RTCIceCandidateInit),