mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-07 11:28:28 +00:00
Prepare SurfaceGeom
for better geometry repr
This commit is contained in:
parent
0aac52a0f2
commit
0dade0ea96
@ -48,7 +48,7 @@ fn approx_curve(
|
|||||||
boundary: CurveBoundary<Point<1>>,
|
boundary: CurveBoundary<Point<1>>,
|
||||||
tolerance: impl Into<Tolerance>,
|
tolerance: impl Into<Tolerance>,
|
||||||
) -> CurveApprox {
|
) -> CurveApprox {
|
||||||
let SurfaceGeom { u, .. } = surface;
|
let SurfaceGeom::Basic { u, .. } = surface;
|
||||||
let points = match (path, u) {
|
let points = match (path, u) {
|
||||||
(SurfacePath::Circle(_), GlobalPath::Circle(_)) => {
|
(SurfacePath::Circle(_), GlobalPath::Circle(_)) => {
|
||||||
approx_circle_on_curved_surface()
|
approx_circle_on_curved_surface()
|
||||||
@ -111,7 +111,7 @@ fn approx_line_on_any_surface(
|
|||||||
.map(|point_curve| [line.point_from_line_coords(point_curve).u]),
|
.map(|point_curve| [line.point_from_line_coords(point_curve).u]),
|
||||||
);
|
);
|
||||||
|
|
||||||
let SurfaceGeom { u, .. } = surface;
|
let SurfaceGeom::Basic { u, .. } = surface;
|
||||||
let approx_u = match u {
|
let approx_u = match u {
|
||||||
GlobalPath::Circle(circle) => approx_circle(circle, range_u, tolerance),
|
GlobalPath::Circle(circle) => approx_circle(circle, range_u, tolerance),
|
||||||
GlobalPath::Line(line) => approx_line(line),
|
GlobalPath::Line(line) => approx_line(line),
|
||||||
@ -216,7 +216,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn approx_line_on_curved_surface_but_not_along_curve() {
|
fn approx_line_on_curved_surface_but_not_along_curve() {
|
||||||
let surface = SurfaceGeom {
|
let surface = SurfaceGeom::Basic {
|
||||||
u: GlobalPath::circle_from_radius(1.),
|
u: GlobalPath::circle_from_radius(1.),
|
||||||
v: Vector::from([0., 0., 1.]),
|
v: Vector::from([0., 0., 1.]),
|
||||||
};
|
};
|
||||||
@ -236,7 +236,7 @@ mod tests {
|
|||||||
|
|
||||||
let circle = Circle::from_center_and_radius(Point::origin(), 1.);
|
let circle = Circle::from_center_and_radius(Point::origin(), 1.);
|
||||||
let global_path = GlobalPath::Circle(circle);
|
let global_path = GlobalPath::Circle(circle);
|
||||||
let surface_geom = SurfaceGeom {
|
let surface_geom = SurfaceGeom::Basic {
|
||||||
u: global_path,
|
u: global_path,
|
||||||
v: Vector::from([0., 0., 1.]),
|
v: Vector::from([0., 0., 1.]),
|
||||||
};
|
};
|
||||||
|
@ -14,7 +14,7 @@ impl super::BoundingVolume<3> for &Face {
|
|||||||
.map(|aabb2| {
|
.map(|aabb2| {
|
||||||
let surface = geometry.of_surface(self.surface());
|
let surface = geometry.of_surface(self.surface());
|
||||||
|
|
||||||
let SurfaceGeom { u, v } = surface;
|
let SurfaceGeom::Basic { u, v } = surface;
|
||||||
match u {
|
match u {
|
||||||
GlobalPath::Circle(circle) => {
|
GlobalPath::Circle(circle) => {
|
||||||
// This is not the most precise way to calculate the
|
// This is not the most precise way to calculate the
|
||||||
|
@ -42,21 +42,21 @@ impl Geometry {
|
|||||||
|
|
||||||
self_.define_surface_inner(
|
self_.define_surface_inner(
|
||||||
self_.xy_plane.clone(),
|
self_.xy_plane.clone(),
|
||||||
SurfaceGeom {
|
SurfaceGeom::Basic {
|
||||||
u: GlobalPath::x_axis(),
|
u: GlobalPath::x_axis(),
|
||||||
v: Vector::unit_y(),
|
v: Vector::unit_y(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self_.define_surface_inner(
|
self_.define_surface_inner(
|
||||||
self_.xz_plane.clone(),
|
self_.xz_plane.clone(),
|
||||||
SurfaceGeom {
|
SurfaceGeom::Basic {
|
||||||
u: GlobalPath::x_axis(),
|
u: GlobalPath::x_axis(),
|
||||||
v: Vector::unit_z(),
|
v: Vector::unit_z(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self_.define_surface_inner(
|
self_.define_surface_inner(
|
||||||
self_.yz_plane.clone(),
|
self_.yz_plane.clone(),
|
||||||
SurfaceGeom {
|
SurfaceGeom::Basic {
|
||||||
u: GlobalPath::y_axis(),
|
u: GlobalPath::y_axis(),
|
||||||
v: Vector::unit_z(),
|
v: Vector::unit_z(),
|
||||||
},
|
},
|
||||||
|
@ -6,12 +6,23 @@ use super::GlobalPath;
|
|||||||
|
|
||||||
/// The geometry that defines a surface
|
/// The geometry that defines a surface
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
||||||
pub struct SurfaceGeom {
|
pub enum SurfaceGeom {
|
||||||
/// The u-axis of the surface
|
/// # Basic definition of surface geometry
|
||||||
pub u: GlobalPath,
|
///
|
||||||
|
/// ## Implementation Note
|
||||||
|
///
|
||||||
|
/// At the time of writing, this is the sole variant of `SurfaceGeom`.
|
||||||
|
/// `SurfaceGeom` simply used to be a struct, identical to this variant.
|
||||||
|
///
|
||||||
|
/// This was changed as part of a transition to a new, less basic and more
|
||||||
|
/// flexible, representation of surface geometry.
|
||||||
|
Basic {
|
||||||
|
/// The u-axis of the surface
|
||||||
|
u: GlobalPath,
|
||||||
|
|
||||||
/// The v-axis of the surface
|
/// The v-axis of the surface
|
||||||
pub v: Vector<3>,
|
v: Vector<3>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SurfaceGeom {
|
impl SurfaceGeom {
|
||||||
@ -21,7 +32,7 @@ impl SurfaceGeom {
|
|||||||
point: impl Into<Point<2>>,
|
point: impl Into<Point<2>>,
|
||||||
) -> Point<3> {
|
) -> Point<3> {
|
||||||
let point = point.into();
|
let point = point.into();
|
||||||
let Self { u, .. } = self;
|
let Self::Basic { u, .. } = self;
|
||||||
u.point_from_path_coords([point.u])
|
u.point_from_path_coords([point.u])
|
||||||
+ self.path_to_line().vector_from_line_coords([point.v])
|
+ self.path_to_line().vector_from_line_coords([point.v])
|
||||||
}
|
}
|
||||||
@ -32,19 +43,19 @@ impl SurfaceGeom {
|
|||||||
vector: impl Into<Vector<2>>,
|
vector: impl Into<Vector<2>>,
|
||||||
) -> Vector<3> {
|
) -> Vector<3> {
|
||||||
let vector = vector.into();
|
let vector = vector.into();
|
||||||
let Self { u, .. } = self;
|
let Self::Basic { u, .. } = self;
|
||||||
u.vector_from_path_coords([vector.u])
|
u.vector_from_path_coords([vector.u])
|
||||||
+ self.path_to_line().vector_from_line_coords([vector.v])
|
+ self.path_to_line().vector_from_line_coords([vector.v])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path_to_line(&self) -> Line<3> {
|
fn path_to_line(&self) -> Line<3> {
|
||||||
let Self { u, v } = self;
|
let Self::Basic { u, v } = self;
|
||||||
Line::from_origin_and_direction(u.origin(), *v)
|
Line::from_origin_and_direction(u.origin(), *v)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Project the global point into the surface
|
/// Project the global point into the surface
|
||||||
pub fn project_global_point(&self, point: impl Into<Point<3>>) -> Point<2> {
|
pub fn project_global_point(&self, point: impl Into<Point<3>>) -> Point<2> {
|
||||||
let Self { u, v } = self;
|
let Self::Basic { u, v } = self;
|
||||||
|
|
||||||
let GlobalPath::Line(line) = u else {
|
let GlobalPath::Line(line) = u else {
|
||||||
todo!("Projecting point into non-plane surface is not supported")
|
todo!("Projecting point into non-plane surface is not supported")
|
||||||
@ -57,11 +68,11 @@ impl SurfaceGeom {
|
|||||||
/// Transform the surface geometry
|
/// Transform the surface geometry
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn transform(self, transform: &Transform) -> Self {
|
pub fn transform(self, transform: &Transform) -> Self {
|
||||||
let Self { u, v } = self;
|
let Self::Basic { u, v } = self;
|
||||||
|
|
||||||
let u = u.transform(transform);
|
let u = u.transform(transform);
|
||||||
let v = transform.transform_vector(&v);
|
let v = transform.transform_vector(&v);
|
||||||
Self { u, v }
|
Self::Basic { u, v }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +85,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn point_from_surface_coords() {
|
fn point_from_surface_coords() {
|
||||||
let surface = SurfaceGeom {
|
let surface = SurfaceGeom::Basic {
|
||||||
u: GlobalPath::Line(Line::from_origin_and_direction(
|
u: GlobalPath::Line(Line::from_origin_and_direction(
|
||||||
Point::from([1., 1., 1.]),
|
Point::from([1., 1., 1.]),
|
||||||
Vector::from([0., 2., 0.]),
|
Vector::from([0., 2., 0.]),
|
||||||
@ -90,7 +101,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn vector_from_surface_coords() {
|
fn vector_from_surface_coords() {
|
||||||
let surface = SurfaceGeom {
|
let surface = SurfaceGeom::Basic {
|
||||||
u: GlobalPath::Line(Line::from_origin_and_direction(
|
u: GlobalPath::Line(Line::from_origin_and_direction(
|
||||||
Point::from([1., 0., 0.]),
|
Point::from([1., 0., 0.]),
|
||||||
Vector::from([0., 2., 0.]),
|
Vector::from([0., 2., 0.]),
|
||||||
|
@ -35,7 +35,7 @@ pub trait BuildSurface {
|
|||||||
core: &mut Core,
|
core: &mut Core,
|
||||||
) -> Handle<Surface> {
|
) -> Handle<Surface> {
|
||||||
Self::from_geometry(
|
Self::from_geometry(
|
||||||
SurfaceGeom {
|
SurfaceGeom::Basic {
|
||||||
u: u.into(),
|
u: u.into(),
|
||||||
v: v.into(),
|
v: v.into(),
|
||||||
},
|
},
|
||||||
|
@ -39,7 +39,7 @@ impl SweepSurfacePath for SurfacePath {
|
|||||||
path: impl Into<Vector<3>>,
|
path: impl Into<Vector<3>>,
|
||||||
core: &mut Core,
|
core: &mut Core,
|
||||||
) -> Handle<Surface> {
|
) -> Handle<Surface> {
|
||||||
let SurfaceGeom { u, .. } = surface;
|
let SurfaceGeom::Basic { u, .. } = surface;
|
||||||
match u {
|
match u {
|
||||||
GlobalPath::Circle(_) => {
|
GlobalPath::Circle(_) => {
|
||||||
// Sweeping a `Curve` creates a `Surface`. The u-axis of that
|
// Sweeping a `Curve` creates a `Surface`. The u-axis of that
|
||||||
|
@ -45,7 +45,7 @@ impl SweepSketch for Sketch {
|
|||||||
.winding(&core.layers.geometry, self.surface())
|
.winding(&core.layers.geometry, self.surface())
|
||||||
.is_ccw());
|
.is_ccw());
|
||||||
|
|
||||||
let SurfaceGeom { u, v } =
|
let SurfaceGeom::Basic { u, v } =
|
||||||
core.layers.geometry.of_surface(&surface);
|
core.layers.geometry.of_surface(&surface);
|
||||||
|
|
||||||
let is_negative_sweep = {
|
let is_negative_sweep = {
|
||||||
|
Loading…
Reference in New Issue
Block a user