diff --git a/Cargo.lock b/Cargo.lock index 173ebe04..2a69b044 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -403,6 +403,27 @@ dependencies = [ "syn 2.0.106", ] +[[package]] +name = "derive_more" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb" +dependencies = [ + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.106", +] + [[package]] name = "digest" version = "0.10.7" @@ -468,11 +489,13 @@ version = "0.1.0" dependencies = [ "bumpalo", "bytemuck", + "derive_more", "dreammaker", "either", "foldhash", "gfx_core", "gif", + "glam", "indexmap", "inflate", "lodepng", @@ -530,6 +553,7 @@ dependencies = [ "foldhash", "get-size", "get-size-derive", + "glam", "indexmap", "interval-tree", "lodepng", @@ -777,6 +801,12 @@ dependencies = [ "url", ] +[[package]] +name = "glam" +version = "0.30.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19fc433e8437a212d1b6f1e68c7824af3aed907da60afa994e7f542d18d12aa9" + [[package]] name = "hashbrown" version = "0.15.5" @@ -1507,6 +1537,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustls" version = "0.23.31" @@ -1563,6 +1602,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + [[package]] name = "serde" version = "1.0.219" diff --git a/crates/dmm-tools/Cargo.toml b/crates/dmm-tools/Cargo.toml index 31fdc979..1890e48c 100644 --- a/crates/dmm-tools/Cargo.toml +++ b/crates/dmm-tools/Cargo.toml @@ -13,6 +13,8 @@ lodepng = "3.10.7" indexmap = "2.6.0" foldhash = "0.2.0" either = "1.13.0" +glam = "0.30" +derive_more = {version = "2.1.1", features = ["deref"]} [dependencies.bytemuck] version = "1.19.0" diff --git a/crates/dmm-tools/src/dmm.rs b/crates/dmm-tools/src/dmm.rs index 39a42c4a..492dfe63 100644 --- a/crates/dmm-tools/src/dmm.rs +++ b/crates/dmm-tools/src/dmm.rs @@ -4,7 +4,9 @@ use std::fs::File; use std::io; use std::path::Path; +use derive_more::Deref; use foldhash::fast::RandomState; +use glam::{IVec2, IVec3}; use indexmap::IndexMap; use ndarray::{self, Array3, Axis}; @@ -28,36 +30,25 @@ pub struct Key(KeyType); /// An XY coordinate pair in the BYOND coordinate system. /// /// The lower-left corner is `{ x: 1, y: 1 }`. -#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] -pub struct Coord2 { - pub x: i32, - pub y: i32, -} +#[derive(Deref)] +pub struct Coord2(IVec2); impl Coord2 { - #[inline] - pub fn new(x: i32, y: i32) -> Coord2 { - Coord2 { x, y } - } - #[inline] pub fn z(self, z: i32) -> Coord3 { - Coord3 { - x: self.x, - y: self.y, - z, - } + self.extend(z).into() } + #[inline] fn to_raw(self, (dim_y, dim_x): (usize, usize)) -> (usize, usize) { assert!( - self.x >= 1 && self.x <= dim_x as i32, + (1..=(dim_x as i32)).contains(&self.x), "x={} not in [1, {}]", self.x, dim_x ); assert!( - self.y >= 1 && self.y <= dim_y as i32, + (1..=(dim_y as i32)).contains(&self.y), "y={} not in [1, {}]", self.y, dim_y @@ -65,11 +56,9 @@ impl Coord2 { (dim_y - self.y as usize, self.x as usize - 1) } + #[inline] fn from_raw((y, x): (usize, usize), (dim_y, _dim_x): (usize, usize)) -> Coord2 { - Coord2 { - x: x as i32 + 1, - y: (dim_y - y) as i32, - } + Coord2(IVec2::new(x as i32 + 1, (dim_y - y) as i32)) } } @@ -77,11 +66,13 @@ impl std::ops::Add