mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-06 10:58:28 +00:00
Merge GlobalPath
into Path
This commit is contained in:
parent
485c67adad
commit
f5fc4991f9
@ -3,7 +3,7 @@ use std::collections::BTreeMap;
|
|||||||
use fj_math::{Circle, Line, Point};
|
use fj_math::{Circle, Line, Point};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
geometry::{CurveBoundary, Geometry, GlobalPath, Path, SurfaceGeom},
|
geometry::{CurveBoundary, Geometry, Path, SurfaceGeom},
|
||||||
storage::Handle,
|
storage::Handle,
|
||||||
topology::{Curve, Surface},
|
topology::{Curve, Surface},
|
||||||
};
|
};
|
||||||
@ -50,10 +50,8 @@ fn approx_curve(
|
|||||||
) -> CurveApprox {
|
) -> CurveApprox {
|
||||||
let SurfaceGeom { u, .. } = surface;
|
let SurfaceGeom { u, .. } = surface;
|
||||||
let points = match (path, u) {
|
let points = match (path, u) {
|
||||||
(Path::Circle(_), GlobalPath::Circle(_)) => {
|
(Path::Circle(_), Path::Circle(_)) => approx_circle_on_curved_surface(),
|
||||||
approx_circle_on_curved_surface()
|
(Path::Circle(circle), Path::Line(_)) => {
|
||||||
}
|
|
||||||
(Path::Circle(circle), GlobalPath::Line(_)) => {
|
|
||||||
approx_circle_on_straight_surface(
|
approx_circle_on_straight_surface(
|
||||||
circle, boundary, surface, tolerance,
|
circle, boundary, surface, tolerance,
|
||||||
)
|
)
|
||||||
@ -118,8 +116,8 @@ fn approx_line_on_any_surface(
|
|||||||
|
|
||||||
let SurfaceGeom { u, .. } = surface;
|
let SurfaceGeom { u, .. } = surface;
|
||||||
let approx_u = match u {
|
let approx_u = match u {
|
||||||
GlobalPath::Circle(circle) => approx_circle(circle, range_u, tolerance),
|
Path::Circle(circle) => approx_circle(circle, range_u, tolerance),
|
||||||
GlobalPath::Line(line) => approx_line(line),
|
Path::Line(line) => approx_line(line),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut points = Vec::new();
|
let mut points = Vec::new();
|
||||||
@ -199,7 +197,7 @@ mod tests {
|
|||||||
algorithms::approx::{
|
algorithms::approx::{
|
||||||
circle::approx_circle, curve::approx_curve, ApproxPoint,
|
circle::approx_circle, curve::approx_curve, ApproxPoint,
|
||||||
},
|
},
|
||||||
geometry::{CurveBoundary, GlobalPath, Path, SurfaceGeom},
|
geometry::{CurveBoundary, Path, SurfaceGeom},
|
||||||
operations::build::BuildSurface,
|
operations::build::BuildSurface,
|
||||||
topology::Surface,
|
topology::Surface,
|
||||||
Core,
|
Core,
|
||||||
@ -210,7 +208,8 @@ mod tests {
|
|||||||
let core = Core::new();
|
let core = Core::new();
|
||||||
|
|
||||||
let surface = core.layers.geometry.xz_plane();
|
let surface = core.layers.geometry.xz_plane();
|
||||||
let (path, boundary) = Path::line_from_points([[1., 1.], [2., 1.]]);
|
let (path, boundary) =
|
||||||
|
Path::<2>::line_from_points([[1., 1.], [2., 1.]]);
|
||||||
let boundary = CurveBoundary::from(boundary);
|
let boundary = CurveBoundary::from(boundary);
|
||||||
|
|
||||||
let tolerance = 1.;
|
let tolerance = 1.;
|
||||||
@ -222,10 +221,11 @@ 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 {
|
||||||
u: GlobalPath::circle_from_radius(1.),
|
u: Path::circle_from_radius(1.),
|
||||||
v: Vector::from([0., 0., 1.]),
|
v: Vector::from([0., 0., 1.]),
|
||||||
};
|
};
|
||||||
let (path, boundary) = Path::line_from_points([[1., 1.], [2., 1.]]);
|
let (path, boundary) =
|
||||||
|
Path::<2>::line_from_points([[1., 1.], [2., 1.]]);
|
||||||
let boundary = CurveBoundary::from(boundary);
|
let boundary = CurveBoundary::from(boundary);
|
||||||
|
|
||||||
let tolerance = 1.;
|
let tolerance = 1.;
|
||||||
@ -239,7 +239,7 @@ mod tests {
|
|||||||
let mut core = Core::new();
|
let mut core = Core::new();
|
||||||
|
|
||||||
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 = Path::Circle(circle);
|
||||||
let surface_geom = SurfaceGeom {
|
let surface_geom = SurfaceGeom {
|
||||||
u: global_path,
|
u: global_path,
|
||||||
v: Vector::from([0., 0., 1.]),
|
v: Vector::from([0., 0., 1.]),
|
||||||
|
@ -4,7 +4,7 @@ use fj_math::{Aabb, Vector};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
algorithms::approx::Tolerance,
|
algorithms::approx::Tolerance,
|
||||||
geometry::{Geometry, GlobalPath, SurfaceGeom},
|
geometry::{Geometry, Path, SurfaceGeom},
|
||||||
topology::Face,
|
topology::Face,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ impl super::BoundingVolume<3> for &Face {
|
|||||||
|
|
||||||
let SurfaceGeom { u, v } = surface;
|
let SurfaceGeom { u, v } = surface;
|
||||||
match u {
|
match u {
|
||||||
GlobalPath::Circle(circle) => {
|
Path::Circle(circle) => {
|
||||||
// This is not the most precise way to calculate the
|
// This is not the most precise way to calculate the
|
||||||
// AABB, doing it for the whole circle, but it should
|
// AABB, doing it for the whole circle, but it should
|
||||||
// do.
|
// do.
|
||||||
@ -30,7 +30,7 @@ impl super::BoundingVolume<3> for &Face {
|
|||||||
|
|
||||||
aabb_bottom.merged(&aabb_top)
|
aabb_bottom.merged(&aabb_top)
|
||||||
}
|
}
|
||||||
GlobalPath::Line(_) => {
|
Path::Line(_) => {
|
||||||
// A bounding volume must include the body it bounds,
|
// A bounding volume must include the body it bounds,
|
||||||
// but does not need to match it precisely. So it's
|
// but does not need to match it precisely. So it's
|
||||||
// okay, if it's a bit larger.
|
// okay, if it's a bit larger.
|
||||||
|
@ -8,8 +8,8 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
vertex::LocalVertexGeom, CurveGeom, GlobalPath, LocalCurveGeom,
|
vertex::LocalVertexGeom, CurveGeom, LocalCurveGeom, Path, SurfaceGeom,
|
||||||
SurfaceGeom, VertexGeom,
|
VertexGeom,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Geometric data that is associated with topological objects
|
/// Geometric data that is associated with topological objects
|
||||||
@ -43,21 +43,21 @@ impl Geometry {
|
|||||||
self_.define_surface_inner(
|
self_.define_surface_inner(
|
||||||
self_.xy_plane.clone(),
|
self_.xy_plane.clone(),
|
||||||
SurfaceGeom {
|
SurfaceGeom {
|
||||||
u: GlobalPath::x_axis(),
|
u: Path::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 {
|
||||||
u: GlobalPath::x_axis(),
|
u: Path::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 {
|
||||||
u: GlobalPath::y_axis(),
|
u: Path::y_axis(),
|
||||||
v: Vector::unit_z(),
|
v: Vector::unit_z(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -11,7 +11,7 @@ pub use self::{
|
|||||||
boundary::{CurveBoundary, CurveBoundaryElement},
|
boundary::{CurveBoundary, CurveBoundaryElement},
|
||||||
curve::{CurveGeom, LocalCurveGeom},
|
curve::{CurveGeom, LocalCurveGeom},
|
||||||
geometry::Geometry,
|
geometry::Geometry,
|
||||||
path::{GlobalPath, Path},
|
path::Path,
|
||||||
surface::SurfaceGeom,
|
surface::SurfaceGeom,
|
||||||
vertex::{LocalVertexGeom, VertexGeom},
|
vertex::{LocalVertexGeom, VertexGeom},
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Paths through 2D and 3D space
|
//! Paths through 2D and 3D space
|
||||||
//!
|
//!
|
||||||
//! See [`Path`] and [`GlobalPath`].
|
//! See [`Path`].
|
||||||
|
|
||||||
use fj_math::{Circle, Line, Point, Scalar, Transform, Vector};
|
use fj_math::{Circle, Line, Point, Scalar, Transform, Vector};
|
||||||
|
|
||||||
@ -79,17 +79,7 @@ impl Path<2> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A path through global (3D) space
|
impl Path<3> {
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
|
||||||
pub enum GlobalPath {
|
|
||||||
/// A circle
|
|
||||||
Circle(Circle<3>),
|
|
||||||
|
|
||||||
/// A line
|
|
||||||
Line(Line<3>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GlobalPath {
|
|
||||||
/// Construct a `GlobalPath` that represents the x-axis
|
/// Construct a `GlobalPath` that represents the x-axis
|
||||||
pub fn x_axis() -> Self {
|
pub fn x_axis() -> Self {
|
||||||
Self::Line(Line::from_origin_and_direction(
|
Self::Line(Line::from_origin_and_direction(
|
||||||
|
@ -4,13 +4,13 @@ use fj_math::{Point, Scalar, Transform, Triangle, Vector};
|
|||||||
|
|
||||||
use crate::algorithms::approx::{PathApproxParams, Tolerance};
|
use crate::algorithms::approx::{PathApproxParams, Tolerance};
|
||||||
|
|
||||||
use super::GlobalPath;
|
use super::Path;
|
||||||
|
|
||||||
/// 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 struct SurfaceGeom {
|
||||||
/// The u-axis of the surface
|
/// The u-axis of the surface
|
||||||
pub u: GlobalPath,
|
pub u: Path<3>,
|
||||||
|
|
||||||
/// The v-axis of the surface
|
/// The v-axis of the surface
|
||||||
pub v: Vector<3>,
|
pub v: Vector<3>,
|
||||||
@ -21,8 +21,8 @@ impl SurfaceGeom {
|
|||||||
pub fn origin(&self) -> Point<3> {
|
pub fn origin(&self) -> Point<3> {
|
||||||
let Self { u, .. } = self;
|
let Self { u, .. } = self;
|
||||||
match u {
|
match u {
|
||||||
GlobalPath::Circle(circle) => circle.center(),
|
Path::Circle(circle) => circle.center(),
|
||||||
GlobalPath::Line(line) => line.origin(),
|
Path::Line(line) => line.origin(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ impl SurfaceGeom {
|
|||||||
|
|
||||||
let Self { u, v } = self;
|
let Self { u, v } = self;
|
||||||
match u {
|
match u {
|
||||||
GlobalPath::Circle(circle) => {
|
Path::Circle(circle) => {
|
||||||
let params = PathApproxParams::for_circle(circle, tolerance);
|
let params = PathApproxParams::for_circle(circle, tolerance);
|
||||||
|
|
||||||
let a = point_surface.u - params.increment();
|
let a = point_surface.u - params.increment();
|
||||||
@ -93,7 +93,7 @@ impl SurfaceGeom {
|
|||||||
|
|
||||||
(triangle, barycentric_coords)
|
(triangle, barycentric_coords)
|
||||||
}
|
}
|
||||||
GlobalPath::Line(line) => {
|
Path::Line(line) => {
|
||||||
let a = line.direction();
|
let a = line.direction();
|
||||||
let b = *v;
|
let b = *v;
|
||||||
|
|
||||||
@ -152,13 +152,13 @@ mod tests {
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
algorithms::approx::Tolerance,
|
algorithms::approx::Tolerance,
|
||||||
geometry::{GlobalPath, SurfaceGeom},
|
geometry::{Path, SurfaceGeom},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn point_from_surface_coords() {
|
fn point_from_surface_coords() {
|
||||||
let surface = SurfaceGeom {
|
let surface = SurfaceGeom {
|
||||||
u: GlobalPath::Line(Line::from_origin_and_direction(
|
u: Path::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.]),
|
||||||
)),
|
)),
|
||||||
@ -177,7 +177,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn vector_from_surface_coords() {
|
fn vector_from_surface_coords() {
|
||||||
let surface = SurfaceGeom {
|
let surface = SurfaceGeom {
|
||||||
u: GlobalPath::Line(Line::from_origin_and_direction(
|
u: Path::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.]),
|
||||||
)),
|
)),
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use fj_math::{Point, Scalar, Vector};
|
use fj_math::{Point, Scalar, Vector};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
geometry::{GlobalPath, SurfaceGeom},
|
geometry::{Path, SurfaceGeom},
|
||||||
operations::insert::Insert,
|
operations::insert::Insert,
|
||||||
storage::Handle,
|
storage::Handle,
|
||||||
topology::Surface,
|
topology::Surface,
|
||||||
@ -30,7 +30,7 @@ pub trait BuildSurface {
|
|||||||
|
|
||||||
/// Build a surface from the provided `u` and `v`
|
/// Build a surface from the provided `u` and `v`
|
||||||
fn from_uv(
|
fn from_uv(
|
||||||
u: impl Into<GlobalPath>,
|
u: impl Into<Path<3>>,
|
||||||
v: impl Into<Vector<3>>,
|
v: impl Into<Vector<3>>,
|
||||||
core: &mut Core,
|
core: &mut Core,
|
||||||
) -> Handle<Surface> {
|
) -> Handle<Surface> {
|
||||||
@ -50,7 +50,7 @@ pub trait BuildSurface {
|
|||||||
) -> (Handle<Surface>, [Point<2>; 3]) {
|
) -> (Handle<Surface>, [Point<2>; 3]) {
|
||||||
let [a, b, c] = points.map(Into::into);
|
let [a, b, c] = points.map(Into::into);
|
||||||
|
|
||||||
let (u, u_line) = GlobalPath::line_from_points([a, b]);
|
let (u, u_line) = Path::<3>::line_from_points([a, b]);
|
||||||
let v = c - a;
|
let v = c - a;
|
||||||
|
|
||||||
let surface = Surface::from_uv(u, v, core);
|
let surface = Surface::from_uv(u, v, core);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use fj_math::{Circle, Line, Vector};
|
use fj_math::{Circle, Line, Vector};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
geometry::{GlobalPath, Path, SurfaceGeom},
|
geometry::{Path, SurfaceGeom},
|
||||||
operations::build::BuildSurface,
|
operations::build::BuildSurface,
|
||||||
storage::Handle,
|
storage::Handle,
|
||||||
topology::Surface,
|
topology::Surface,
|
||||||
@ -41,7 +41,7 @@ impl SweepSurfacePath for Path<2> {
|
|||||||
) -> Handle<Surface> {
|
) -> Handle<Surface> {
|
||||||
let SurfaceGeom { u, .. } = surface;
|
let SurfaceGeom { u, .. } = surface;
|
||||||
match u {
|
match u {
|
||||||
GlobalPath::Circle(_) => {
|
Path::Circle(_) => {
|
||||||
// Sweeping a `Curve` creates a `Surface`. The u-axis of that
|
// Sweeping a `Curve` creates a `Surface`. The u-axis of that
|
||||||
// `Surface` is a `GlobalPath`, which we are computing below.
|
// `Surface` is a `GlobalPath`, which we are computing below.
|
||||||
// That computation might or might not work with an arbitrary
|
// That computation might or might not work with an arbitrary
|
||||||
@ -58,7 +58,7 @@ impl SweepSurfacePath for Path<2> {
|
|||||||
not supported yet."
|
not supported yet."
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
GlobalPath::Line(_) => {
|
Path::Line(_) => {
|
||||||
// We're sweeping from a curve on a flat surface, which is
|
// We're sweeping from a curve on a flat surface, which is
|
||||||
// supported. Carry on.
|
// supported. Carry on.
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ impl SweepSurfacePath for Path<2> {
|
|||||||
|
|
||||||
let circle = Circle::new(center, a, b);
|
let circle = Circle::new(center, a, b);
|
||||||
|
|
||||||
GlobalPath::Circle(circle)
|
Path::Circle(circle)
|
||||||
}
|
}
|
||||||
Path::Line(line) => {
|
Path::Line(line) => {
|
||||||
let origin = surface
|
let origin = surface
|
||||||
@ -89,7 +89,7 @@ impl SweepSurfacePath for Path<2> {
|
|||||||
|
|
||||||
let line = Line::from_origin_and_direction(origin, direction);
|
let line = Line::from_origin_and_direction(origin, direction);
|
||||||
|
|
||||||
GlobalPath::Line(line)
|
Path::Line(line)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user