From 1a7df74b75659ca4e455a9c1b28e5bb8430f2b16 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Tue, 16 Jan 2024 12:18:18 +0000 Subject: [PATCH] Fix missing data when writing mesh file --- src/input/polyanya_file.rs | 3 ++- src/primitives.rs | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/input/polyanya_file.rs b/src/input/polyanya_file.rs index 865a20b..98fcc51 100644 --- a/src/input/polyanya_file.rs +++ b/src/input/polyanya_file.rs @@ -105,9 +105,10 @@ impl PolyanyaFile { for vertex in &self.vertices { bytes.extend_from_slice( format!( - "{} {} {}\n", + "{:.06} {:.06} {} {}\n", vertex.coords.x, vertex.coords.y, + vertex.polygons.len(), vertex .polygons .iter() diff --git a/src/primitives.rs b/src/primitives.rs index 6987853..f6c1f79 100644 --- a/src/primitives.rs +++ b/src/primitives.rs @@ -65,12 +65,14 @@ impl Polygon { } pub(crate) fn using(nb: usize, data: Vec) -> Self { - assert!(data.len() == nb * 2); let (vertices, neighbours) = data.split_at(nb); let vertices = vertices.iter().copied().map(|v| v as u32).collect(); let neighbours = neighbours.to_vec(); let mut found_trav = false; - let mut is_one_way = true; + // Hack to handle case where there are no neighbours in the file. In + // this case we want to assume it is not a one way. The correct fix is + // to update the polyanya file format to include the neighbours. + let mut is_one_way = !neighbours.is_empty(); for neighbour in &neighbours { if *neighbour != -1 { if found_trav {