Merge pull request #1313 from hannobraun/transform

Simplify `GlobalPath` transforms
This commit is contained in:
Hanno Braun 2022-11-06 09:04:14 +01:00 committed by GitHub
commit b7e48f4669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 25 deletions

View File

@ -4,7 +4,6 @@ mod curve;
mod cycle;
mod edge;
mod face;
mod path;
mod shell;
mod sketch;
mod solid;

View File

@ -1,22 +0,0 @@
use fj_math::Transform;
use crate::{objects::Objects, path::GlobalPath, validate::ValidationError};
use super::TransformObject;
impl TransformObject for GlobalPath {
fn transform(
self,
transform: &Transform,
_: &Objects,
) -> Result<Self, ValidationError> {
match self {
Self::Circle(curve) => {
Ok(Self::Circle(transform.transform_circle(&curve)))
}
Self::Line(curve) => {
Ok(Self::Line(transform.transform_line(&curve)))
}
}
}
}

View File

@ -15,7 +15,7 @@ impl TransformObject for Handle<Surface> {
objects: &Objects,
) -> Result<Self, ValidationError> {
Ok(objects.surfaces.insert(Surface::new(
self.u().transform(transform, objects)?,
self.u().transform(transform),
transform.transform_vector(&self.v()),
))?)
}

View File

@ -22,7 +22,7 @@
//! [`Surface`]: crate::objects::Surface
//! [#1021]: https://github.com/hannobraun/Fornjot/issues/1021
use fj_math::{Circle, Line, Point, Scalar, Vector};
use fj_math::{Circle, Line, Point, Scalar, Transform, Vector};
/// A path through surface (2D) space
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
@ -141,4 +141,15 @@ impl GlobalPath {
Self::Line(line) => line.vector_from_line_coords(vector),
}
}
/// Transform the path
#[must_use]
pub fn transform(self, transform: &Transform) -> Self {
match self {
Self::Circle(curve) => {
Self::Circle(transform.transform_circle(&curve))
}
Self::Line(curve) => Self::Line(transform.transform_line(&curve)),
}
}
}