Skip to content

Commit

Permalink
Implement replace traits for bare objects
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Nov 14, 2023
1 parent 4205f1e commit af03504
Show file tree
Hide file tree
Showing 3 changed files with 362 additions and 40 deletions.
135 changes: 121 additions & 14 deletions crates/fj-core/src/operations/replace/curve.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Deref;

use crate::{
objects::{Curve, Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid},
operations::{insert::Insert, update::UpdateHalfEdge},
Expand Down Expand Up @@ -26,8 +28,8 @@ pub trait ReplaceCurve: Sized {
) -> ReplaceOutput<Self, Self::BareObject>;
}

impl ReplaceCurve for Handle<HalfEdge> {
type BareObject = HalfEdge;
impl ReplaceCurve for HalfEdge {
type BareObject = Self;

fn replace_curve(
&self,
Expand All @@ -43,8 +45,8 @@ impl ReplaceCurve for Handle<HalfEdge> {
}
}

impl ReplaceCurve for Handle<Cycle> {
type BareObject = Cycle;
impl ReplaceCurve for Cycle {
type BareObject = Self;

fn replace_curve(
&self,
Expand Down Expand Up @@ -77,8 +79,8 @@ impl ReplaceCurve for Handle<Cycle> {
}
}

impl ReplaceCurve for Handle<Region> {
type BareObject = Region;
impl ReplaceCurve for Region {
type BareObject = Self;

fn replace_curve(
&self,
Expand Down Expand Up @@ -121,8 +123,8 @@ impl ReplaceCurve for Handle<Region> {
}
}

impl ReplaceCurve for Handle<Sketch> {
type BareObject = Sketch;
impl ReplaceCurve for Sketch {
type BareObject = Self;

fn replace_curve(
&self,
Expand Down Expand Up @@ -152,8 +154,8 @@ impl ReplaceCurve for Handle<Sketch> {
}
}

impl ReplaceCurve for Handle<Face> {
type BareObject = Face;
impl ReplaceCurve for Face {
type BareObject = Self;

fn replace_curve(
&self,
Expand All @@ -177,8 +179,8 @@ impl ReplaceCurve for Handle<Face> {
}
}

impl ReplaceCurve for Handle<Shell> {
type BareObject = Shell;
impl ReplaceCurve for Shell {
type BareObject = Self;

fn replace_curve(
&self,
Expand Down Expand Up @@ -207,8 +209,8 @@ impl ReplaceCurve for Handle<Shell> {
}
}

impl ReplaceCurve for Handle<Solid> {
type BareObject = Solid;
impl ReplaceCurve for Solid {
type BareObject = Self;

fn replace_curve(
&self,
Expand Down Expand Up @@ -237,3 +239,108 @@ impl ReplaceCurve for Handle<Solid> {
}
}
}

impl ReplaceCurve for Handle<HalfEdge> {
type BareObject = HalfEdge;

fn replace_curve(
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.map_original(|_| self.clone())
}
}

impl ReplaceCurve for Handle<Cycle> {
type BareObject = Cycle;

fn replace_curve(
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.map_original(|_| self.clone())
}
}

impl ReplaceCurve for Handle<Region> {
type BareObject = Region;

fn replace_curve(
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.map_original(|_| self.clone())
}
}

impl ReplaceCurve for Handle<Sketch> {
type BareObject = Sketch;

fn replace_curve(
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.map_original(|_| self.clone())
}
}

impl ReplaceCurve for Handle<Face> {
type BareObject = Face;

fn replace_curve(
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.map_original(|_| self.clone())
}
}

impl ReplaceCurve for Handle<Shell> {
type BareObject = Shell;

fn replace_curve(
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.map_original(|_| self.clone())
}
}

impl ReplaceCurve for Handle<Solid> {
type BareObject = Solid;

fn replace_curve(
&self,
original: &Handle<Curve>,
replacement: Handle<Curve>,
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_curve(original, replacement, services)
.map_original(|_| self.clone())
}
}
116 changes: 104 additions & 12 deletions crates/fj-core/src/operations/replace/half_edge.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Deref;

use crate::{
objects::{Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid},
operations::insert::Insert,
Expand Down Expand Up @@ -26,8 +28,8 @@ pub trait ReplaceHalfEdge: Sized {
) -> ReplaceOutput<Self, Self::BareObject>;
}

impl ReplaceHalfEdge for Handle<Cycle> {
type BareObject = Cycle;
impl ReplaceHalfEdge for Cycle {
type BareObject = Self;

fn replace_half_edge<const N: usize>(
&self,
Expand All @@ -45,8 +47,8 @@ impl ReplaceHalfEdge for Handle<Cycle> {
}
}

impl ReplaceHalfEdge for Handle<Region> {
type BareObject = Region;
impl ReplaceHalfEdge for Region {
type BareObject = Self;

fn replace_half_edge<const N: usize>(
&self,
Expand Down Expand Up @@ -92,8 +94,8 @@ impl ReplaceHalfEdge for Handle<Region> {
}
}

impl ReplaceHalfEdge for Handle<Sketch> {
type BareObject = Sketch;
impl ReplaceHalfEdge for Sketch {
type BareObject = Self;

fn replace_half_edge<const N: usize>(
&self,
Expand Down Expand Up @@ -126,8 +128,8 @@ impl ReplaceHalfEdge for Handle<Sketch> {
}
}

impl ReplaceHalfEdge for Handle<Face> {
type BareObject = Face;
impl ReplaceHalfEdge for Face {
type BareObject = Self;

fn replace_half_edge<const N: usize>(
&self,
Expand All @@ -152,8 +154,8 @@ impl ReplaceHalfEdge for Handle<Face> {
}
}

impl ReplaceHalfEdge for Handle<Shell> {
type BareObject = Shell;
impl ReplaceHalfEdge for Shell {
type BareObject = Self;

fn replace_half_edge<const N: usize>(
&self,
Expand Down Expand Up @@ -185,8 +187,8 @@ impl ReplaceHalfEdge for Handle<Shell> {
}
}

impl ReplaceHalfEdge for Handle<Solid> {
type BareObject = Solid;
impl ReplaceHalfEdge for Solid {
type BareObject = Self;

fn replace_half_edge<const N: usize>(
&self,
Expand Down Expand Up @@ -218,3 +220,93 @@ impl ReplaceHalfEdge for Handle<Solid> {
}
}
}

impl ReplaceHalfEdge for Handle<Cycle> {
type BareObject = Cycle;

fn replace_half_edge<const N: usize>(
&self,
original: &Handle<HalfEdge>,
replacements: [Handle<HalfEdge>; N],
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_half_edge(original, replacements, services)
.map_original(|_| self.clone())
}
}

impl ReplaceHalfEdge for Handle<Region> {
type BareObject = Region;

fn replace_half_edge<const N: usize>(
&self,
original: &Handle<HalfEdge>,
replacements: [Handle<HalfEdge>; N],
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_half_edge(original, replacements, services)
.map_original(|_| self.clone())
}
}

impl ReplaceHalfEdge for Handle<Sketch> {
type BareObject = Sketch;

fn replace_half_edge<const N: usize>(
&self,
original: &Handle<HalfEdge>,
replacements: [Handle<HalfEdge>; N],
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_half_edge(original, replacements, services)
.map_original(|_| self.clone())
}
}

impl ReplaceHalfEdge for Handle<Face> {
type BareObject = Face;

fn replace_half_edge<const N: usize>(
&self,
original: &Handle<HalfEdge>,
replacements: [Handle<HalfEdge>; N],
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_half_edge(original, replacements, services)
.map_original(|_| self.clone())
}
}

impl ReplaceHalfEdge for Handle<Shell> {
type BareObject = Shell;

fn replace_half_edge<const N: usize>(
&self,
original: &Handle<HalfEdge>,
replacements: [Handle<HalfEdge>; N],
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_half_edge(original, replacements, services)
.map_original(|_| self.clone())
}
}

impl ReplaceHalfEdge for Handle<Solid> {
type BareObject = Solid;

fn replace_half_edge<const N: usize>(
&self,
original: &Handle<HalfEdge>,
replacements: [Handle<HalfEdge>; N],
services: &mut Services,
) -> ReplaceOutput<Self, Self::BareObject> {
self.deref()
.replace_half_edge(original, replacements, services)
.map_original(|_| self.clone())
}
}
Loading

0 comments on commit af03504

Please sign in to comment.