added normalized boxes for communication

This commit is contained in:
Nickiel12 2024-09-08 20:39:59 +00:00
parent a701721338
commit ffe25b54d2
2 changed files with 69 additions and 0 deletions

57
src/boxes.rs Normal file
View file

@ -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
)
}
}

View file

@ -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<String>),
ChangeTrackingID(u16),
TrackingBoxes(Vec<NormalizedBoxCoords>),
ManualMovementOverride((i32, i32)),
WebRTCPacket(RTCSessionDescription),
WebRTCIceCandidate(RTCIceCandidate),
WebRTCIceCandidateInit(RTCIceCandidateInit),