Skip to content

Commit

Permalink
Remove SlotStorage and only require Clone for graph data.
Browse files Browse the repository at this point in the history
  • Loading branch information
olson-sean-k committed Dec 9, 2020
1 parent 1c96f40 commit d33539c
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 250 deletions.
1 change: 0 additions & 1 deletion plexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ decorum = "^0.3.1"
derivative = "^2.1.1"
itertools = "^0.9.0"
num = "^0.3.0"
slotmap = "^0.4.0"
smallvec = "^1.0.0"
thiserror = "^1.0.3"
typenum = "^1.10.0"
Expand Down
2 changes: 1 addition & 1 deletion plexus/src/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait Lifetime {}
#[cfg(all(nightly, feature = "unstable"))]
impl<T> Lifetime for T {}

pub trait Entity: Copy + Lifetime + Sized {
pub trait Entity: Lifetime + Sized {
type Key: Key;
type Storage: Default + Dispatch<Self> + Storage<Self>;
}
Expand Down
2 changes: 0 additions & 2 deletions plexus/src/entity/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
mod hash;
mod slot;

use std::hash::Hash;

use crate::entity::{Entity, Payload};

pub use crate::entity::storage::hash::HashStorage;
pub use crate::entity::storage::slot::SlotStorage;

pub mod prelude {
pub use crate::entity::storage::{Enumerate, Get, Insert, InsertWithKey, Remove};
Expand Down
179 changes: 0 additions & 179 deletions plexus/src/entity/storage/slot.rs

This file was deleted.

22 changes: 8 additions & 14 deletions plexus/src/graph/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ use crate::entity::Lifetime;

pub type Data<M> = <M as Parametric>::Data;

pub trait EntityData: Copy + Lifetime {}

impl<T> EntityData for T where T: Copy + Lifetime {}

// TODO: Require `Clone` instead of `Copy` once non-`Copy` types are supported
// by the slotmap crate. See https://github.com/orlp/slotmap/issues/27
/// Graph data.
///
/// Specifies the types used to represent data in vertices, arcs, edges, and
Expand Down Expand Up @@ -71,10 +65,10 @@ impl<T> EntityData for T where T: Copy + Lifetime {}
/// [`AsPosition`]: crate::geometry::AsPosition
/// [`MeshGraph`]: crate::graph::MeshGraph
pub trait GraphData: Lifetime + Sized {
type Vertex: EntityData;
type Arc: EntityData + Default;
type Edge: EntityData + Default;
type Face: EntityData + Default;
type Vertex: Clone + Lifetime;
type Arc: Clone + Default + Lifetime;
type Edge: Clone + Default + Lifetime;
type Face: Clone + Default + Lifetime;
}

impl GraphData for () {
Expand All @@ -86,7 +80,7 @@ impl GraphData for () {

impl<T> GraphData for (T, T)
where
T: EntityData,
T: Clone + Lifetime,
{
type Vertex = Self;
type Arc = ();
Expand All @@ -96,7 +90,7 @@ where

impl<T> GraphData for (T, T, T)
where
T: EntityData,
T: Clone + Lifetime,
{
type Vertex = Self;
type Arc = ();
Expand All @@ -106,7 +100,7 @@ where

impl<T> GraphData for [T; 2]
where
T: EntityData,
T: Clone + Lifetime,
{
type Vertex = Self;
type Arc = ();
Expand All @@ -116,7 +110,7 @@ where

impl<T> GraphData for [T; 3]
where
T: EntityData,
T: Clone + Lifetime,
{
type Vertex = Self;
type Arc = ();
Expand Down
12 changes: 6 additions & 6 deletions plexus/src/graph/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ where
// reason, `Arc` has no fields representing its source and destination vertices
// nor its opposite arc; such fields would be redundant.
/// Arc entity.
#[derivative(Clone, Copy, Debug, Hash)]
#[derivative(Debug, Hash)]
#[derive(Derivative)]
pub struct Arc<G>
where
Expand Down Expand Up @@ -738,13 +738,13 @@ where
pub fn split_at_midpoint(self) -> VertexView<&'a mut M>
where
G: EdgeMidpoint,
G::Vertex: AsPositionMut,
G::Vertex: AsPositionMut + Clone,
{
let mut geometry = self.source_vertex().data;
let mut data = self.source_vertex().get().clone();
let midpoint = self.midpoint();
self.split_with(move || {
*geometry.as_position_mut() = midpoint;
geometry
*data.as_position_mut() = midpoint;
data
})
}

Expand Down Expand Up @@ -1214,7 +1214,7 @@ where
}

/// Edge entity.
#[derivative(Clone, Copy, Debug, Hash)]
#[derivative(Debug, Hash)]
#[derive(Derivative)]
pub struct Edge<G>
where
Expand Down
29 changes: 17 additions & 12 deletions plexus/src/graph/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ where
}

/// Face entity.
#[derivative(Clone, Copy, Debug, Hash)]
#[derivative(Debug, Hash)]
#[derive(Derivative)]
pub struct Face<G>
where
Expand Down Expand Up @@ -638,16 +638,18 @@ where
})
.map(|arc| arc.key())
.ok_or(GraphError::TopologyNotFound)?;
let geometry = self.data;
// TODO: Batch this operation by using the mutation API instead.
// TODO: `Clone` should not be needed here. Consolidate this using the
// mutation API and move the necessary face data instead of
// cloning it.
let data = self.get().clone();
let arc: ArcView<_> = self.rebind(ab).expect_consistent();
Ok(arc
.remove()
// Removing an edge between faces must yield a vertex.
.expect_consistent()
.into_outgoing_arc()
.into_ring()
.get_or_insert_face_with(|| geometry))
.get_or_insert_face_with(|| data))
}

/// Connects faces with equal arity with faces inserted along their
Expand Down Expand Up @@ -753,11 +755,11 @@ where
G: FaceCentroid,
G::Vertex: AsPositionMut,
{
let mut geometry = self.arc().source_vertex().data;
let mut data = self.arc().source_vertex().get().clone();
let centroid = self.centroid();
self.poke_with(move || {
*geometry.as_position_mut() = centroid;
geometry
*data.as_position_mut() = centroid;
data
})
}

Expand Down Expand Up @@ -803,11 +805,11 @@ where
G::Vertex: AsPositionMut,
VertexPosition<G>: EuclideanSpace,
{
let mut geometry = self.arc().source_vertex().data;
let mut data = self.arc().source_vertex().get().clone();
let position = self.centroid() + (self.normal()? * offset.into());
Ok(self.poke_with(move || {
*geometry.as_position_mut() = position;
geometry
*data.as_position_mut() = position;
data
}))
}

Expand Down Expand Up @@ -840,15 +842,18 @@ where
G::Vertex: AsPositionMut,
VertexPosition<G>: EuclideanSpace,
{
self.extrude_with(|geometry| geometry.map_position(|position| *position + translation))
self.extrude_with(|data| {
data.clone()
.map_position(|position| *position + translation)
})
}

/// Extrudes a face using the given vertex data.
///
/// Returns the extruded face.
pub fn extrude_with<F>(self, f: F) -> FaceView<&'a mut M>
where
F: Fn(G::Vertex) -> G::Vertex,
F: Fn(&G::Vertex) -> G::Vertex,
{
// This should never fail here.
let cache = FaceExtrudeCache::from_face(self.to_ref()).expect_consistent();
Expand Down
Loading

0 comments on commit d33539c

Please sign in to comment.