From f48b882c48a20b2efbc63548cc738e55c9bc66f2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 8 Mar 2022 16:55:33 +0100 Subject: [PATCH] Add edge validation code --- src/kernel/shape/edges.rs | 12 +++++++++++- src/kernel/shape/mod.rs | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/kernel/shape/edges.rs b/src/kernel/shape/edges.rs index 8fb86d03d..f6fe7ff93 100644 --- a/src/kernel/shape/edges.rs +++ b/src/kernel/shape/edges.rs @@ -9,12 +9,13 @@ use crate::{ use super::{ curves::Curves, handle::{Handle, Storage}, - EdgesInner, + EdgesInner, VerticesInner, }; /// The edges of a shape pub struct Edges<'r> { pub(super) curves: Curves, + pub(super) vertices: &'r mut VerticesInner, pub(super) edges: &'r mut EdgesInner, } @@ -34,6 +35,15 @@ impl Edges<'_> { /// the future, it can add the edge to the proper internal data structures, /// and validate any constraints that apply to edge creation. pub fn add(&mut self, edge: Edge) -> Handle { + for vertices in &edge.vertices { + for vertex in vertices { + assert!( + self.vertices.contains(vertex.storage()), + "Edge validation failed: {vertex:?} is not part of shape", + ); + } + } + let storage = Storage::new(edge); let handle = storage.handle(); diff --git a/src/kernel/shape/mod.rs b/src/kernel/shape/mod.rs index 83d4ccbef..454eebbaf 100644 --- a/src/kernel/shape/mod.rs +++ b/src/kernel/shape/mod.rs @@ -86,6 +86,7 @@ impl Shape { pub fn edges(&mut self) -> Edges { Edges { curves: Curves, + vertices: &mut self.vertices, edges: &mut self.edges, } }