use crate::Vec3;
use slotmap::new_key_type;
use std::cmp::Ordering;
new_key_type! {
pub struct AscendingKey;
}
pub type Index = AscendingKey;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Default)]
pub struct DrawOrder {
pub order_layer: u32,
pub alpha: bool,
pub x: u32,
pub y: u32,
pub z: u32,
}
impl PartialOrd for DrawOrder {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for DrawOrder {
fn cmp(&self, other: &Self) -> Ordering {
self.order_layer
.cmp(&other.order_layer)
.then(self.alpha.cmp(&other.alpha))
.then(self.y.cmp(&other.y).reverse())
.then(self.x.cmp(&other.x))
.then(self.z.cmp(&other.z).reverse())
}
}
impl DrawOrder {
pub fn new(alpha: bool, pos: Vec3, order_layer: u32) -> Self {
Self {
order_layer,
alpha,
x: (pos.x * 10000.0) as u32,
y: (pos.y * 10000.0) as u32,
z: (pos.z * 10000.0) as u32,
}
}
pub fn set_pos(&mut self, pos: Vec3) {
self.x = (pos.x * 10000.0) as u32;
self.y = (pos.y * 10000.0) as u32;
self.z = (pos.z * 10000.0) as u32;
}
}