#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
pub trait Cursor {
fn team_id(&self) -> u64;
fn x(&self) -> f32;
fn y(&self) -> f32;
fn z(&self) -> f32;
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Cursor2D {
team_id: u64,
x: f32,
y: f32,
}
impl Eq for Cursor2D {}
impl Cursor2D {
pub fn new(team_id: u64, x: f32, y: f32) -> Self {
Self { team_id, x, y }
}
pub fn set_position(&mut self, x: f32, y: f32) {
self.x = x;
self.y = y;
}
}
impl Cursor for Cursor2D {
fn team_id(&self) -> u64 {
self.team_id
}
fn x(&self) -> f32 {
self.x
}
fn y(&self) -> f32 {
self.y
}
fn z(&self) -> f32 {
crate::default_values::DEFAULT_Z
}
}
impl std::fmt::Display for Cursor2D {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Cursor2D(x={:.1}, y={:.1})", self.x, self.y)
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Cursor3D {
team_id: u64,
x: f32,
y: f32,
z: f32,
gradient_index: Option<usize>,
}
impl Eq for Cursor3D {}
impl Cursor3D {
pub fn new(team_id: u64, x: f32, y: f32, z: f32) -> Self {
Self {
team_id,
x,
y,
z,
gradient_index: None,
}
}
pub fn set_position(&mut self, x: f32, y: f32, z: f32) {
self.x = x;
self.y = y;
self.z = z;
self.gradient_index = None; }
pub fn gradient_index(&self) -> Option<usize> {
self.gradient_index
}
pub fn set_gradient_index(&mut self, index: Option<usize>) {
self.gradient_index = index;
}
}
impl Cursor for Cursor3D {
fn team_id(&self) -> u64 {
self.team_id
}
fn x(&self) -> f32 {
self.x
}
fn y(&self) -> f32 {
self.y
}
fn z(&self) -> f32 {
self.z
}
}
impl std::fmt::Display for Cursor3D {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Cursor3D(x={:.1}, y={:.1}, z={:.1})", self.x, self.y, self.z)
}
}