From 8b89dada068932231547c6c11242ea6e1f4d026d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sat, 21 Sep 2024 15:22:33 +0200 Subject: [PATCH] Coords can't be changed after creation --- src/lib.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1874b34..b916656 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,11 +83,11 @@ pub struct Mesh { #[derive(Debug, PartialEq, Clone, Copy)] pub struct Coords { /// The position - pub pos: Vec2, + pos: Vec2, /// The layer /// /// If specified, the point will be searched in that layer only. - pub layer: Option, + layer: Option, /// internal: this coords have been built by a search on the mesh that found the polygon index /// if used for a path, this will be used directly instead of searching for it again in the mesh /// default value is u32::MAX which means it hasn't been searched @@ -105,6 +105,11 @@ impl From for Coords { } impl Coords { + /// A point on the navigation mesh + pub fn on_mesh(pos: Vec2) -> Self { + pos.into() + } + /// A point on the navigation mesh on the specified layer pub fn on_layer(pos: Vec2, layer: u8) -> Self { Coords { @@ -113,6 +118,16 @@ impl Coords { polygon_index: u32::MAX, } } + + /// Position of this point + pub fn position(&self) -> Vec2 { + self.pos + } + + /// Layer of this point, if known + pub fn layer(&self) -> Option { + self.layer + } } impl Display for Coords {