Skip to content

Commit

Permalink
Merge pull request #1717 from hannobraun/operations
Browse files Browse the repository at this point in the history
Move `Insert` trait to new `operations` module; clean it up
  • Loading branch information
hannobraun authored Mar 23, 2023
2 parents 55c83b8 + 604348b commit b9b64f3
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 46 deletions.
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ mod tests {
algorithms::approx::{path::RangeOnPath, Approx, ApproxPoint},
builder::HalfEdgeBuilder,
geometry::{curve::GlobalPath, surface::SurfaceGeometry},
insert::Insert,
objects::Surface,
operations::Insert,
services::Services,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/reverse/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use itertools::Itertools;

use crate::{
insert::Insert,
objects::{Cycle, HalfEdge, Objects},
operations::Insert,
services::Service,
storage::Handle,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/reverse/face.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
insert::Insert,
objects::{Face, Objects},
operations::Insert,
services::Service,
storage::Handle,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
curve::{Curve, GlobalPath},
surface::SurfaceGeometry,
},
insert::Insert,
objects::{Objects, Surface},
operations::Insert,
services::Service,
storage::Handle,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use fj_math::{Point, Scalar, Vector};

use crate::{
builder::HalfEdgeBuilder,
insert::Insert,
objects::{Cycle, Face, HalfEdge, Objects, Surface, Vertex},
operations::Insert,
services::Service,
storage::Handle,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
algorithms::{reverse::Reverse, transform::TransformObject},
builder::CycleBuilder,
geometry::curve::GlobalPath,
insert::Insert,
objects::{Face, Objects, Shell},
operations::Insert,
services::Service,
storage::Handle,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/sketch.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use fj_math::Vector;

use crate::{
insert::Insert,
objects::{Objects, Sketch, Solid},
operations::Insert,
services::Service,
storage::Handle,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use fj_math::Vector;

use crate::{
insert::Insert,
objects::{GlobalEdge, Objects, Vertex},
operations::Insert,
services::Service,
storage::Handle,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use fj_math::{Transform, Vector};
use type_map::TypeMap;

use crate::{
insert::Insert,
objects::Objects,
operations::Insert,
services::Service,
storage::{Handle, ObjectId},
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use itertools::Itertools;

use crate::{
geometry::curve::Curve,
insert::Insert,
objects::{Cycle, HalfEdge, Objects},
operations::Insert,
services::Service,
storage::Handle,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use fj_math::{Arc, Point, Scalar};

use crate::{
geometry::curve::Curve,
insert::Insert,
objects::{GlobalEdge, HalfEdge, Objects, Surface, Vertex},
operations::Insert,
services::Service,
storage::Handle,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/builder/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use fj_interop::{ext::ArrayExt, mesh::Color};
use fj_math::Point;

use crate::{
insert::Insert,
objects::{Cycle, Face, GlobalEdge, Objects, Surface},
operations::Insert,
services::Service,
storage::Handle,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
pub mod algorithms;
pub mod builder;
pub mod geometry;
pub mod insert;
pub mod objects;
pub mod operations;
pub mod services;
pub mod storage;
pub mod validate;
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
//! Convenience trait to insert objects into their respective stores
//!
//! See [`Insert`].
use crate::{
objects::{
Cycle, Face, GlobalEdge, HalfEdge, Objects, Shell, Sketch, Solid,
Surface, Vertex,
},
services::{Service, ServiceObjectsExt},
services::{Operation, Service},
storage::Handle,
validate::Validate,
};

/// Convenience trait to insert objects into their respective stores
pub trait Insert: Sized + Validate {
/// Insert an object into its respective store
///
/// This is the only primitive operation that is directly understood by
/// `Service<Objects>`. All other operations are built on top of it.
pub trait Insert: Sized {
/// Insert the object into its respective store
fn insert(self, objects: &mut Service<Objects>) -> Handle<Self>;
}
Expand All @@ -25,7 +23,8 @@ macro_rules! impl_insert {
fn insert(self, objects: &mut Service<Objects>) -> Handle<Self>
{
let handle = objects.$store.reserve();
objects.insert((handle.clone(), self).into());
let object = (handle.clone(), self).into();
objects.execute(Operation::InsertObject { object });
handle
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/fj-kernel/src/operations/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Operations to update shapes
mod insert;

pub use self::insert::Insert;
5 changes: 1 addition & 4 deletions crates/fj-kernel/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use parking_lot::Mutex;
use crate::objects::Objects;

pub use self::{
objects::{InsertObject, Operation, ServiceObjectsExt},
objects::{InsertObject, Operation},
service::{Service, State},
validation::{Validation, ValidationFailed},
};
Expand All @@ -23,9 +23,6 @@ pub struct Services {
/// The objects service
///
/// Allows for inserting objects into a store after they were created.
///
/// [`ServiceObjectsExt`] is available to provide a convenient API around
/// this service.
pub objects: Service<Objects>,

/// The validation service
Expand Down
17 changes: 1 addition & 16 deletions crates/fj-kernel/src/services/objects.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::objects::{Object, Objects, WithHandle};

use super::{Service, State};
use super::State;

impl State for Objects {
type Command = Operation;
Expand All @@ -23,9 +23,6 @@ pub enum Operation {
///
/// This is the one primitive operation that all other operations are built
/// upon.
///
/// You might prefer to use [`ServiceObjectsExt::insert`], which is a
/// convenient wrapper around `Service<Objects>::execute`.
InsertObject {
/// The object to insert
object: Object<WithHandle>,
Expand All @@ -38,15 +35,3 @@ pub struct InsertObject {
/// The object to insert
pub object: Object<WithHandle>,
}

/// Convenient API for `Service<Objects>`
pub trait ServiceObjectsExt {
/// Insert an object
fn insert(&mut self, object: Object<WithHandle>);
}

impl ServiceObjectsExt for Service<Objects> {
fn insert(&mut self, object: Object<WithHandle>) {
self.execute(Operation::InsertObject { object });
}
}
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/validate/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ mod tests {
use crate::{
assert_contains_err,
builder::{CycleBuilder, FaceBuilder, ShellBuilder},
insert::Insert,
objects::Shell,
operations::Insert,
services::Services,
validate::{shell::ShellValidationError, Validate, ValidationError},
};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-operations/src/difference_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::ops::Deref;
use fj_interop::{debug::DebugInfo, ext::ArrayExt, mesh::Color};
use fj_kernel::{
algorithms::reverse::Reverse,
insert::Insert,
objects::{Face, Objects, Sketch},
operations::Insert,
services::Service,
};
use fj_math::Aabb;
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-operations/src/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::ops::Deref;
use fj_interop::{debug::DebugInfo, mesh::Color};
use fj_kernel::{
builder::{CycleBuilder, HalfEdgeBuilder},
insert::Insert,
objects::{Cycle, Face, Objects, Sketch},
operations::Insert,
services::Service,
};
use fj_math::{Aabb, Point};
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-operations/src/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::ops::Deref;
use fj_interop::debug::DebugInfo;
use fj_kernel::{
algorithms::sweep::Sweep,
insert::Insert,
objects::{Objects, Solid},
operations::Insert,
services::Service,
};
use fj_math::{Aabb, Vector};
Expand Down

0 comments on commit b9b64f3

Please sign in to comment.