-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1406 from hannobraun/transform
Simplify transform code by using cache instead of partial objects
- Loading branch information
Showing
13 changed files
with
224 additions
and
197 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,47 @@ | ||
use fj_math::Transform; | ||
|
||
use crate::{ | ||
objects::Objects, | ||
partial::{PartialCurve, PartialGlobalCurve}, | ||
objects::{Curve, GlobalCurve, Objects}, | ||
services::Service, | ||
}; | ||
|
||
use super::TransformObject; | ||
use super::{TransformCache, TransformObject}; | ||
|
||
impl TransformObject for PartialGlobalCurve { | ||
fn transform(self, _: &Transform, _: &mut Service<Objects>) -> Self { | ||
// `GlobalCurve` doesn't contain any internal geometry. If it did, that | ||
// would just be redundant with the geometry of other objects, and this | ||
// other geometry is already being transformed by other implementations | ||
// of this trait. | ||
self | ||
} | ||
} | ||
|
||
impl TransformObject for PartialCurve { | ||
fn transform( | ||
impl TransformObject for Curve { | ||
fn transform_with_cache( | ||
self, | ||
transform: &Transform, | ||
objects: &mut Service<Objects>, | ||
cache: &mut TransformCache, | ||
) -> Self { | ||
// Don't need to transform path, as that's defined in surface | ||
// coordinates, and thus transforming `surface` takes care of it. | ||
let path = self.path(); | ||
|
||
let surface = self | ||
.surface | ||
.map(|surface| surface.transform(transform, objects)); | ||
let global_form = self.global_form.transform(transform, objects); | ||
.surface() | ||
.clone() | ||
.transform_with_cache(transform, objects, cache); | ||
let global_form = self | ||
.global_form() | ||
.clone() | ||
.transform_with_cache(transform, objects, cache); | ||
|
||
// Don't need to transform `self.path`, as that's defined in surface | ||
// coordinates, and thus transforming `surface` takes care of it. | ||
PartialCurve { | ||
path: self.path, | ||
surface, | ||
global_form, | ||
} | ||
Self::new(surface, path, global_form) | ||
} | ||
} | ||
|
||
impl TransformObject for GlobalCurve { | ||
fn transform_with_cache( | ||
self, | ||
_: &Transform, | ||
_: &mut Service<Objects>, | ||
_: &mut TransformCache, | ||
) -> Self { | ||
// `GlobalCurve` doesn't contain any internal geometry. If it did, that | ||
// would just be redundant with the geometry of other objects, and this | ||
// other geometry is already being transformed by other implementations | ||
// of this trait. | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
use fj_math::Transform; | ||
|
||
use crate::{objects::Objects, partial::PartialCycle, services::Service}; | ||
use crate::{ | ||
objects::{Cycle, Objects}, | ||
services::Service, | ||
}; | ||
|
||
use super::TransformObject; | ||
use super::{TransformCache, TransformObject}; | ||
|
||
impl TransformObject for PartialCycle { | ||
fn transform( | ||
impl TransformObject for Cycle { | ||
fn transform_with_cache( | ||
self, | ||
transform: &Transform, | ||
objects: &mut Service<Objects>, | ||
cache: &mut TransformCache, | ||
) -> Self { | ||
let half_edges = self | ||
.half_edges() | ||
.map(|edge| edge.into_partial().transform(transform, objects)); | ||
let half_edges = self.half_edges().map(|half_edge| { | ||
half_edge | ||
.clone() | ||
.transform_with_cache(transform, objects, cache) | ||
}); | ||
|
||
Self::default().with_half_edges(half_edges) | ||
Self::new(half_edges) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,47 @@ | ||
use fj_math::Transform; | ||
|
||
use crate::{ | ||
objects::Objects, | ||
partial::{PartialGlobalEdge, PartialHalfEdge}, | ||
objects::{GlobalEdge, HalfEdge, Objects}, | ||
services::Service, | ||
}; | ||
|
||
use super::TransformObject; | ||
use super::{TransformCache, TransformObject}; | ||
|
||
impl TransformObject for PartialHalfEdge { | ||
fn transform( | ||
impl TransformObject for HalfEdge { | ||
fn transform_with_cache( | ||
self, | ||
transform: &Transform, | ||
objects: &mut Service<Objects>, | ||
cache: &mut TransformCache, | ||
) -> Self { | ||
let curve = self.curve.transform(transform, objects); | ||
let vertices = self | ||
.vertices | ||
.map(|vertex| vertex.transform(transform, objects)); | ||
let global_form = self.global_form.transform(transform, objects); | ||
let vertices = self.vertices().clone().map(|vertex| { | ||
vertex.transform_with_cache(transform, objects, cache) | ||
}); | ||
let global_form = self | ||
.global_form() | ||
.clone() | ||
.transform_with_cache(transform, objects, cache); | ||
|
||
Self { | ||
curve, | ||
vertices, | ||
global_form, | ||
} | ||
Self::new(vertices, global_form) | ||
} | ||
} | ||
|
||
impl TransformObject for PartialGlobalEdge { | ||
fn transform( | ||
impl TransformObject for GlobalEdge { | ||
fn transform_with_cache( | ||
self, | ||
transform: &Transform, | ||
objects: &mut Service<Objects>, | ||
cache: &mut TransformCache, | ||
) -> Self { | ||
let curve = self.curve.transform(transform, objects); | ||
let vertices = self | ||
.vertices | ||
.map(|vertex| vertex.transform(transform, objects)); | ||
let curve = self | ||
.curve() | ||
.clone() | ||
.transform_with_cache(transform, objects, cache); | ||
let vertices = | ||
self.vertices().access_in_normalized_order().map(|vertex| { | ||
vertex.transform_with_cache(transform, objects, cache) | ||
}); | ||
|
||
Self { curve, vertices } | ||
Self::new(curve, vertices) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.