Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up algorithms::transform #1151

Merged
merged 14 commits into from
Sep 28, 2022
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