Skip to content

Commit

Permalink
Merge pull request #1151 from hannobraun/ready/transform
Browse files Browse the repository at this point in the history
Clean up `algorithms::transform`
  • Loading branch information
hannobraun authored Sep 28, 2022
2 parents 0efdf87 + f36ce31 commit d7c2c32
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 250 deletions.
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 @@ -95,7 +95,7 @@ impl Sweep for (HalfEdge, Color) {
let global = bottom_edge
.curve()
.global_form()
.clone_object()
.clone()
.translate(path, stores);

// Please note that creating a line here is correct, even if the
Expand Down
249 changes: 0 additions & 249 deletions crates/fj-kernel/src/algorithms/transform.rs

This file was deleted.

28 changes: 28 additions & 0 deletions crates/fj-kernel/src/algorithms/transform/curve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use fj_math::Transform;

use crate::{
objects::{Curve, GlobalCurve},
stores::{Handle, Stores},
};

use super::TransformObject;

impl TransformObject for Curve {
fn transform(self, transform: &Transform, stores: &Stores) -> Self {
let surface = self.surface().transform(transform, stores);
let global_form =
self.global_form().clone().transform(transform, stores);

// Don't need to transform `self.path`, as that's defined in surface
// coordinates, and thus transforming `surface` takes care of it.
Self::new(surface, self.path(), global_form)
}
}

impl TransformObject for Handle<GlobalCurve> {
fn transform(self, transform: &Transform, stores: &Stores) -> Self {
stores.global_curves.insert(GlobalCurve::from_path(
self.path().transform(transform, stores),
))
}
}
15 changes: 15 additions & 0 deletions crates/fj-kernel/src/algorithms/transform/cycle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use fj_math::Transform;

use crate::{objects::Cycle, stores::Stores};

use super::TransformObject;

impl TransformObject for Cycle {
fn transform(self, transform: &Transform, stores: &Stores) -> Self {
Self::new(
self.surface().transform(transform, stores),
self.into_half_edges()
.map(|edge| edge.transform(transform, stores)),
)
}
}
33 changes: 33 additions & 0 deletions crates/fj-kernel/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use fj_math::Transform;

use crate::{
objects::{GlobalEdge, HalfEdge},
stores::Stores,
};

use super::TransformObject;

impl TransformObject for HalfEdge {
fn transform(self, transform: &Transform, stores: &Stores) -> Self {
let curve = self.curve().clone().transform(transform, stores);
let vertices = self
.vertices()
.clone()
.map(|vertex| vertex.transform(transform, stores));
let global_form =
self.global_form().clone().transform(transform, stores);

Self::new(curve, vertices, global_form)
}
}

impl TransformObject for GlobalEdge {
fn transform(self, transform: &Transform, stores: &Stores) -> Self {
let curve = self.curve().clone().transform(transform, stores);
let vertices = self
.vertices()
.map(|vertex| vertex.transform(transform, stores));

Self::new(curve, vertices)
}
}
34 changes: 34 additions & 0 deletions crates/fj-kernel/src/algorithms/transform/face.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use fj_math::Transform;

use crate::{
objects::{Face, Faces},
stores::Stores,
};

use super::TransformObject;

impl TransformObject for Face {
fn transform(self, transform: &Transform, stores: &Stores) -> Self {
let exterior = self.exterior().clone().transform(transform, stores);
let interiors = self
.interiors()
.map(|cycle| cycle.clone().transform(transform, stores));

let color = self.color();

Face::from_exterior(exterior)
.with_interiors(interiors)
.with_color(color)
}
}

impl TransformObject for Faces {
fn transform(self, transform: &Transform, stores: &Stores) -> Self {
let mut faces = Faces::new();
faces.extend(
self.into_iter()
.map(|face| face.transform(transform, stores)),
);
faces
}
}
Loading

0 comments on commit d7c2c32

Please sign in to comment.