Add infrastructure for defining half-edge geometry

This commit is contained in:
Hanno Braun 2024-03-14 13:57:15 +01:00
parent 987ddd7e50
commit 03a7cd1ad0
2 changed files with 51 additions and 2 deletions

View File

@ -56,6 +56,14 @@ impl Geometry {
self_ self_
} }
pub(crate) fn define_half_edge_inner(
&mut self,
half_edge: Handle<HalfEdge>,
geometry: HalfEdgeGeometry,
) {
self.half_edge.insert(half_edge, geometry);
}
pub(crate) fn define_surface_inner( pub(crate) fn define_surface_inner(
&mut self, &mut self,
surface: Handle<Surface>, surface: Handle<Surface>,

View File

@ -1,14 +1,30 @@
//! Layer infrastructure for [`Geometry`] //! Layer infrastructure for [`Geometry`]
use crate::{ use crate::{
geometry::{Geometry, SurfaceGeometry}, geometry::{Geometry, HalfEdgeGeometry, SurfaceGeometry},
objects::Surface, objects::{HalfEdge, Surface},
storage::Handle, storage::Handle,
}; };
use super::{Command, Event, Layer}; use super::{Command, Event, Layer};
impl Layer<Geometry> { impl Layer<Geometry> {
/// Define the geometry of the provided half-edge
pub fn define_half_edge(
&mut self,
half_edge: Handle<HalfEdge>,
geometry: HalfEdgeGeometry,
) {
let mut events = Vec::new();
self.process(
DefineHalfEdge {
half_edge,
geometry,
},
&mut events,
);
}
/// Define the geometry of the provided surface /// Define the geometry of the provided surface
pub fn define_surface( pub fn define_surface(
&mut self, &mut self,
@ -20,6 +36,31 @@ impl Layer<Geometry> {
} }
} }
/// Define the geometry of a half-edge
pub struct DefineHalfEdge {
half_edge: Handle<HalfEdge>,
geometry: HalfEdgeGeometry,
}
impl Command<Geometry> for DefineHalfEdge {
type Result = ();
type Event = Self;
fn decide(
self,
_: &Geometry,
events: &mut Vec<Self::Event>,
) -> Self::Result {
events.push(self);
}
}
impl Event<Geometry> for DefineHalfEdge {
fn evolve(&self, state: &mut Geometry) {
state.define_half_edge_inner(self.half_edge.clone(), self.geometry);
}
}
/// Define the geometry of a surface /// Define the geometry of a surface
pub struct DefineSurface { pub struct DefineSurface {
surface: Handle<Surface>, surface: Handle<Surface>,