Skip to content

Commit

Permalink
Add layer infrastructure for Geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Feb 28, 2024
1 parent da8bd5d commit 0e05227
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
46 changes: 46 additions & 0 deletions crates/fj-core/src/layers/geometry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! Layer infrastructure for [`Geometry`]
use crate::{
geometry::{Geometry, SurfaceGeometry},
objects::Surface,
storage::Handle,
};

use super::{Command, Event, Layer};

impl Layer<Geometry> {
/// Define the geometry of the provided surface
pub fn define_surface(
&mut self,
surface: Handle<Surface>,
geometry: SurfaceGeometry,
) {
let mut events = Vec::new();
self.process(DefineSurface { surface, geometry }, &mut events);
}
}

/// Define the geometry of a surface
pub struct DefineSurface {
surface: Handle<Surface>,
geometry: SurfaceGeometry,
}

impl Command<Geometry> for DefineSurface {
type Result = ();
type Event = Self;

fn decide(
self,
_: &Geometry,
events: &mut Vec<Self::Event>,
) -> Self::Result {
events.push(self);
}
}

impl Event<Geometry> for DefineSurface {
fn evolve(&self, state: &mut Geometry) {
state.define_surface_inner(self.surface.clone(), self.geometry);
}
}
8 changes: 8 additions & 0 deletions crates/fj-core/src/layers/layers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
geometry::Geometry,
objects::Objects,
presentation::Presentation,
validation::{Validation, ValidationConfig},
Expand Down Expand Up @@ -27,6 +28,11 @@ pub struct Layers {
/// shapes.
pub objects: Layer<Objects>,

/// The geometry layer
///
/// Manages geometric information that applies to topological objects.
pub geometry: Layer<Geometry>,

/// The validation layer
///
/// Monitors objects and validates them, as they are inserted.
Expand All @@ -42,9 +48,11 @@ impl Layers {
/// Construct an instance of `Layers`
pub fn new() -> Self {
let objects = Objects::new();
let geometry = Geometry::new(&objects);

Self {
objects: Layer::new(objects),
geometry: Layer::new(geometry),
validation: Layer::default(),
presentation: Layer::default(),
}
Expand Down
1 change: 1 addition & 0 deletions crates/fj-core/src/layers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! See [`Layers`].
pub mod geometry;
pub mod objects;
pub mod presentation;
pub mod validation;
Expand Down

0 comments on commit 0e05227

Please sign in to comment.