From 68a72735be76a8782e03c986849da47cd2601f13 Mon Sep 17 00:00:00 2001 From: Charlotte Pabst Date: Sun, 24 Mar 2024 16:52:24 +0100 Subject: cleanup --- src/obj_import.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/obj_import.rs') diff --git a/src/obj_import.rs b/src/obj_import.rs index 577fa1e..339c502 100644 --- a/src/obj_import.rs +++ b/src/obj_import.rs @@ -4,16 +4,16 @@ use obj::raw::object::RawObj; #[derive(Debug, Error)] pub enum ObjImportError { - #[error("vertex position index out of bounds")] - InvalidPositionIndex, + #[error("vertex {0} position index out of bounds")] + InvalidPositionIndex(usize), #[error("half-edge between vertices {0} and {1} appears twice")] SameHalfEdge(usize, usize), #[error("half-edge between vertices {0} and {1} does not have a twin")] UnclaimedHalfEdge(usize, usize), #[error("empty face")] EmptyFace, - #[error("vertex is not connected to any edges")] - StandaloneVertex, + #[error("vertex {0} is not connected to any edges")] + StandaloneVertex(usize), } use ObjImportError::*; @@ -95,9 +95,7 @@ impl<'tok, 'brand, 'arena, V> ObjImport<'tok, 'brand, 'arena, V> { } } - fn iter_polygon( - p: &obj::raw::object::Polygon, - ) -> impl Iterator + DoubleEndedIterator + '_ { + fn iter_polygon(p: &obj::raw::object::Polygon) -> impl DoubleEndedIterator + '_ { use either::{Left, Right}; use obj::raw::object::Polygon::*; @@ -122,12 +120,13 @@ impl<'tok, 'brand, 'arena, V> ObjImport<'tok, 'brand, 'arena, V> { if let Some((k, _)) = self.half_edges.iter().find(|(_, v)| v.is_some()) { Err(UnclaimedHalfEdge(k.1 + 1, k.0 + 1)) - } else if self + } else if let Some((i, _)) = self .vertices .iter() - .any(|x| x.maybe_outgoing(self.dcel).is_none()) + .enumerate() + .find(|(_, x)| x.maybe_outgoing(self.dcel).is_none()) { - Err(StandaloneVertex) + Err(StandaloneVertex(i + 1)) } else { Ok(()) } @@ -142,7 +141,7 @@ impl<'tok, 'brand, 'arena, V> ObjImport<'tok, 'brand, 'arena, V> { use std::collections::hash_map::Entry::*; let [a, b] = vertices; - let v = *self.vertices.get(a).ok_or(InvalidPositionIndex)?; + let v = *self.vertices.get(a).ok_or(InvalidPositionIndex(a + 1))?; let he = match self.half_edges.entry((a, b)) { Occupied(mut e) => e.get_mut().take().ok_or(SameHalfEdge(a + 1, b + 1))?, -- cgit v1.2.3