Skip to content

Commit

Permalink
Add edge validation code
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Mar 8, 2022
1 parent 068d099 commit f48b882
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/kernel/shape/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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<Edge> {
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();

Expand Down
1 change: 1 addition & 0 deletions src/kernel/shape/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl Shape {
pub fn edges(&mut self) -> Edges {
Edges {
curves: Curves,
vertices: &mut self.vertices,
edges: &mut self.edges,
}
}
Expand Down

0 comments on commit f48b882

Please sign in to comment.