From 3c3c1d9b427da58dbd85bec0391ffee04881d47f Mon Sep 17 00:00:00 2001 From: Ellen Emilia Anna Zscheile Date: Thu, 30 Jan 2025 15:34:06 +0100 Subject: [PATCH] feat(layout): center_of_high_level_node (for topological navmesh generation) --- src/layout/layout.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/layout/layout.rs b/src/layout/layout.rs index 2b5d58c..67efdec 100644 --- a/src/layout/layout.rs +++ b/src/layout/layout.rs @@ -336,6 +336,37 @@ impl Layout { } } + /// Checks if a node is "high-level", and if yes, returns its center + pub fn center_of_high_level_node(&self, node: NodeIndex) -> Option { + match node { + NodeIndex::Primitive(primitive) => { + use crate::drawing::{ + graph::MakePrimitive, + primitive::{GetWeight, Primitive}, + }; + use crate::geometry::{compound::ManageCompounds, GetSetPos}; + if self + .drawing() + .geometry() + .compounds(GenericIndex::<()>::new(primitive.petgraph_index())) + .next() + .is_some() + { + return None; + } + match primitive.primitive(self.drawing()) { + Primitive::FixedDot(dot) => Some(dot.weight().pos()), + // Primitive::LooseDot(dot) => Some(dot.weight().pos()), + _ => None, + } + } + NodeIndex::Compound(cwidx) => { + use crate::geometry::shape::AccessShape; + Some(self.node_shape(node).center()) + } + } + } + pub fn rules(&self) -> &R { self.drawing.rules() }