Skip to content

Commit

Permalink
Merge pull request #1423 from hannobraun/partial
Browse files Browse the repository at this point in the history
Shuffle around some things in partial object API
  • Loading branch information
hannobraun authored Dec 6, 2022
2 parents 475e709 + 095779e commit 8c7dbc3
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 192 deletions.
13 changes: 5 additions & 8 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ mod tests {
builder::HalfEdgeBuilder,
insert::Insert,
objects::{Cycle, Face, HalfEdge},
partial::{HasPartial, PartialSurfaceVertex, PartialVertex, Replace},
partial::{HasPartial, PartialSurfaceVertex, PartialVertex},
services::Services,
};

Expand All @@ -216,14 +216,13 @@ mod tests {

let bottom = HalfEdge::partial()
.update_as_line_segment_from_points(
surface.clone(),
surface,
[[0., 0.], [1., 0.]],
)
.build(&mut services.objects)
.insert(&mut services.objects);
let side_up = {
let mut side_up = HalfEdge::partial();
side_up.replace(surface.clone());
let side_up = HalfEdge::partial();
side_up
.with_back_vertex(PartialVertex {
surface_form: bottom
Expand All @@ -246,8 +245,7 @@ mod tests {
.insert(&mut services.objects)
};
let top = {
let mut top = HalfEdge::partial();
top.replace(surface.clone());
let top = HalfEdge::partial();
top.with_back_vertex(PartialVertex {
surface_form: PartialSurfaceVertex {
position: Some([0., 1.].into()),
Expand All @@ -266,8 +264,7 @@ mod tests {
.reverse(&mut services.objects)
};
let side_down = {
let mut side_down = HalfEdge::partial();
side_down.replace(surface);
let side_down = HalfEdge::partial();
side_down
.with_back_vertex(PartialVertex {
surface_form: bottom
Expand Down
157 changes: 1 addition & 156 deletions crates/fj-kernel/src/partial/maybe_partial.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
use fj_math::Point;

use crate::{
geometry::{path::SurfacePath, surface::SurfaceGeometry},
get::Get,
insert::Insert,
objects::{
Curve, Cycle, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects,
Surface, SurfaceVertex, Vertex,
},
objects::Objects,
services::Service,
storage::Handle,
validate::{Validate, ValidationError},
Expand Down Expand Up @@ -156,152 +150,3 @@ where

// Unfortunately, we can't add a blanket implementation from `T::Partial` for
// `MaybePartial<T>`, as that would conflict.

impl MaybePartial<Curve> {
/// Access the path
pub fn path(&self) -> Option<SurfacePath> {
match self {
Self::Full(full) => Some(full.path()),
Self::Partial(partial) => partial.path,
}
}

/// Access the surface
pub fn surface(&self) -> Option<Handle<Surface>> {
match self {
Self::Full(full) => Some(full.surface().clone()),
Self::Partial(partial) => partial.surface.clone(),
}
}

/// Access the global form
pub fn global_form(&self) -> MaybePartial<GlobalCurve> {
match self {
Self::Full(full) => full.global_form().clone().into(),
Self::Partial(partial) => partial.global_form.clone(),
}
}
}

impl MaybePartial<Cycle> {
/// Access the surface
pub fn surface(&self) -> Option<Handle<Surface>> {
match self {
Self::Full(full) => full.surface().clone().into(),
Self::Partial(partial) => partial.surface(),
}
}
}

impl MaybePartial<GlobalEdge> {
/// Access the curve
pub fn curve(&self) -> MaybePartial<GlobalCurve> {
match self {
Self::Full(full) => full.curve().clone().into(),
Self::Partial(partial) => partial.curve.clone(),
}
}

/// Access the vertices
pub fn vertices(&self) -> [MaybePartial<GlobalVertex>; 2] {
match self {
Self::Full(full) => {
full.vertices().access_in_normalized_order().map(Into::into)
}
Self::Partial(partial) => partial.vertices.clone(),
}
}
}

impl MaybePartial<GlobalVertex> {
/// Access the position
pub fn position(&self) -> Option<Point<3>> {
match self {
Self::Full(full) => Some(full.position()),
Self::Partial(partial) => partial.position,
}
}
}

impl MaybePartial<HalfEdge> {
/// Access the curve
pub fn curve(&self) -> MaybePartial<Curve> {
match self {
Self::Full(full) => full.curve().clone().into(),
Self::Partial(partial) => partial.curve(),
}
}

/// Access the front vertex
pub fn front(&self) -> MaybePartial<Vertex> {
match self {
Self::Full(full) => full.front().clone().into(),
Self::Partial(partial) => {
let [_, front] = &partial.vertices;
front.clone()
}
}
}

/// Access the vertices
pub fn vertices(&self) -> [MaybePartial<Vertex>; 2] {
match self {
Self::Full(full) => full.vertices().clone().map(Into::into),
Self::Partial(partial) => partial.vertices.clone(),
}
}
}

impl MaybePartial<Surface> {
/// Access the geometry
pub fn geometry(&self) -> Option<SurfaceGeometry> {
match self {
Self::Full(full) => Some(full.geometry()),
Self::Partial(partial) => partial.geometry,
}
}
}

impl MaybePartial<SurfaceVertex> {
/// Access the position
pub fn position(&self) -> Option<Point<2>> {
match self {
Self::Full(full) => Some(full.position()),
Self::Partial(partial) => partial.position,
}
}

/// Access the surface
pub fn surface(&self) -> Option<Handle<Surface>> {
match self {
Self::Full(full) => Some(full.surface().clone()),
Self::Partial(partial) => partial.surface.clone(),
}
}

/// Access the global form
pub fn global_form(&self) -> MaybePartial<GlobalVertex> {
match self {
Self::Full(full) => full.global_form().clone().into(),
Self::Partial(partial) => partial.global_form.clone(),
}
}
}

impl MaybePartial<Vertex> {
/// Access the curve
pub fn curve(&self) -> MaybePartial<Curve> {
match self {
Self::Full(full) => full.curve().clone().into(),
Self::Partial(partial) => partial.curve.clone(),
}
}

/// Access the surface form
pub fn surface_form(&self) -> MaybePartial<SurfaceVertex> {
match self {
Self::Full(full) => full.surface_form().clone().into(),
Self::Partial(partial) => partial.surface_form.clone(),
}
}
}
26 changes: 26 additions & 0 deletions crates/fj-kernel/src/partial/objects/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ impl From<&Curve> for PartialCurve {
}
}

impl MaybePartial<Curve> {
/// Access the path
pub fn path(&self) -> Option<SurfacePath> {
match self {
Self::Full(full) => Some(full.path()),
Self::Partial(partial) => partial.path,
}
}

/// Access the surface
pub fn surface(&self) -> Option<Handle<Surface>> {
match self {
Self::Full(full) => Some(full.surface().clone()),
Self::Partial(partial) => partial.surface.clone(),
}
}

/// Access the global form
pub fn global_form(&self) -> MaybePartial<GlobalCurve> {
match self {
Self::Full(full) => full.global_form().clone().into(),
Self::Partial(partial) => partial.global_form.clone(),
}
}
}

/// A partial [`GlobalCurve`]
///
/// This struct might seem unnecessary. [`GlobalCurve`] literally has nothing in
Expand Down
10 changes: 10 additions & 0 deletions crates/fj-kernel/src/partial/objects/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,13 @@ impl From<&Cycle> for PartialCycle {
}
}
}

impl MaybePartial<Cycle> {
/// Access the surface
pub fn surface(&self) -> Option<Handle<Surface>> {
match self {
Self::Full(full) => full.surface().clone().into(),
Self::Partial(partial) => partial.surface(),
}
}
}
65 changes: 51 additions & 14 deletions crates/fj-kernel/src/partial/objects/edge.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::{
builder::GlobalEdgeBuilder,
objects::{
Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects,
Surface, Vertex,
Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects, Vertex,
},
partial::{MaybePartial, MergeWith, PartialCurve, PartialVertex, Replace},
partial::{MaybePartial, MergeWith, PartialCurve, PartialVertex},
services::Service,
storage::Handle,
};

/// A partial [`HalfEdge`]
Expand Down Expand Up @@ -73,16 +71,6 @@ impl MergeWith for PartialHalfEdge {
}
}

impl Replace<Surface> for PartialHalfEdge {
fn replace(&mut self, surface: Handle<Surface>) -> &mut Self {
for vertex in &mut self.vertices {
vertex.replace(surface.clone());
}

self
}
}

impl From<&HalfEdge> for PartialHalfEdge {
fn from(half_edge: &HalfEdge) -> Self {
let [back_vertex, front_vertex] =
Expand All @@ -95,6 +83,35 @@ impl From<&HalfEdge> for PartialHalfEdge {
}
}

impl MaybePartial<HalfEdge> {
/// Access the curve
pub fn curve(&self) -> MaybePartial<Curve> {
match self {
Self::Full(full) => full.curve().clone().into(),
Self::Partial(partial) => partial.curve(),
}
}

/// Access the front vertex
pub fn front(&self) -> MaybePartial<Vertex> {
match self {
Self::Full(full) => full.front().clone().into(),
Self::Partial(partial) => {
let [_, front] = &partial.vertices;
front.clone()
}
}
}

/// Access the vertices
pub fn vertices(&self) -> [MaybePartial<Vertex>; 2] {
match self {
Self::Full(full) => full.vertices().clone().map(Into::into),
Self::Partial(partial) => partial.vertices.clone(),
}
}
}

/// A partial [`GlobalEdge`]
///
/// See [`crate::partial`] for more information.
Expand Down Expand Up @@ -141,3 +158,23 @@ impl From<&GlobalEdge> for PartialGlobalEdge {
}
}
}

impl MaybePartial<GlobalEdge> {
/// Access the curve
pub fn curve(&self) -> MaybePartial<GlobalCurve> {
match self {
Self::Full(full) => full.curve().clone().into(),
Self::Partial(partial) => partial.curve.clone(),
}
}

/// Access the vertices
pub fn vertices(&self) -> [MaybePartial<GlobalVertex>; 2] {
match self {
Self::Full(full) => {
full.vertices().access_in_normalized_order().map(Into::into)
}
Self::Partial(partial) => partial.vertices.clone(),
}
}
}
12 changes: 11 additions & 1 deletion crates/fj-kernel/src/partial/objects/surface.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
geometry::surface::SurfaceGeometry,
objects::{Objects, Surface},
partial::MergeWith,
partial::{MaybePartial, MergeWith},
};

/// A partial [`Surface`]
Expand Down Expand Up @@ -41,3 +41,13 @@ impl From<&Surface> for PartialSurface {
}
}
}

impl MaybePartial<Surface> {
/// Access the geometry
pub fn geometry(&self) -> Option<SurfaceGeometry> {
match self {
Self::Full(full) => Some(full.geometry()),
Self::Partial(partial) => partial.geometry,
}
}
}
Loading

0 comments on commit 8c7dbc3

Please sign in to comment.