mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-27 10:29:28 +00:00
Merge Curve
into HalfEdge
This commit is contained in:
parent
2322ab9ddc
commit
34d251ce8f
@ -41,7 +41,7 @@ impl Approx for (&Handle<HalfEdge>, &Surface) {
|
|||||||
Some(approx) => approx,
|
Some(approx) => approx,
|
||||||
None => {
|
None => {
|
||||||
let approx = approx_edge(
|
let approx = approx_edge(
|
||||||
&half_edge.curve().path(),
|
&half_edge.curve(),
|
||||||
surface,
|
surface,
|
||||||
range,
|
range,
|
||||||
tolerance,
|
tolerance,
|
||||||
@ -56,7 +56,6 @@ impl Approx for (&Handle<HalfEdge>, &Surface) {
|
|||||||
.map(|point| {
|
.map(|point| {
|
||||||
let point_surface = half_edge
|
let point_surface = half_edge
|
||||||
.curve()
|
.curve()
|
||||||
.path()
|
|
||||||
.point_from_path_coords(point.local_form);
|
.point_from_path_coords(point.local_form);
|
||||||
|
|
||||||
ApproxPoint::new(point_surface, point.global_form)
|
ApproxPoint::new(point_surface, point.global_form)
|
||||||
@ -320,10 +319,8 @@ mod tests {
|
|||||||
.approx(tolerance)
|
.approx(tolerance)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(point_local, _)| {
|
.map(|(point_local, _)| {
|
||||||
let point_surface = half_edge
|
let point_surface =
|
||||||
.curve()
|
half_edge.curve().point_from_path_coords(point_local);
|
||||||
.path()
|
|
||||||
.point_from_path_coords(point_local);
|
|
||||||
let point_global =
|
let point_global =
|
||||||
surface.geometry().point_from_surface_coords(point_surface);
|
surface.geometry().point_from_surface_coords(point_surface);
|
||||||
ApproxPoint::new(point_surface, point_global)
|
ApproxPoint::new(point_surface, point_global)
|
||||||
@ -352,7 +349,7 @@ mod tests {
|
|||||||
let approx = (&half_edge, surface.deref()).approx(tolerance);
|
let approx = (&half_edge, surface.deref()).approx(tolerance);
|
||||||
|
|
||||||
let expected_approx =
|
let expected_approx =
|
||||||
(&half_edge.curve().path(), RangeOnPath::from([[0.], [TAU]]))
|
(&half_edge.curve(), RangeOnPath::from([[0.], [TAU]]))
|
||||||
.approx(tolerance)
|
.approx(tolerance)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(_, point_surface)| {
|
.map(|(_, point_surface)| {
|
||||||
|
@ -35,7 +35,7 @@ impl CurveEdgeIntersection {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let edge_as_segment = {
|
let edge_as_segment = {
|
||||||
let edge_curve_as_line = match half_edge.curve().path() {
|
let edge_curve_as_line = match half_edge.curve() {
|
||||||
SurfacePath::Line(line) => line,
|
SurfacePath::Line(line) => line,
|
||||||
_ => {
|
_ => {
|
||||||
todo!("Curve-edge intersection only supports line segments")
|
todo!("Curve-edge intersection only supports line segments")
|
||||||
|
@ -17,7 +17,7 @@ impl Intersect for (&HorizontalRayToTheRight<2>, &Handle<HalfEdge>) {
|
|||||||
fn intersect(self) -> Option<Self::Intersection> {
|
fn intersect(self) -> Option<Self::Intersection> {
|
||||||
let (ray, edge) = self;
|
let (ray, edge) = self;
|
||||||
|
|
||||||
let line = match edge.curve().path() {
|
let line = match edge.curve() {
|
||||||
SurfacePath::Line(line) => line,
|
SurfacePath::Line(line) => line,
|
||||||
SurfacePath::Circle(_) => {
|
SurfacePath::Circle(_) => {
|
||||||
todo!("Casting rays against circles is not supported yet")
|
todo!("Casting rays against circles is not supported yet")
|
||||||
|
@ -35,8 +35,7 @@ impl Sweep for (Handle<HalfEdge>, &Surface, Color) {
|
|||||||
// we're sweeping.
|
// we're sweeping.
|
||||||
{
|
{
|
||||||
let surface = Partial::from(
|
let surface = Partial::from(
|
||||||
(edge.curve().path(), surface)
|
(edge.curve(), surface).sweep_with_cache(path, cache, objects),
|
||||||
.sweep_with_cache(path, cache, objects),
|
|
||||||
);
|
);
|
||||||
face.surface = surface;
|
face.surface = surface;
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ impl Sweep for Handle<Face> {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(top_cycle.write().half_edges.iter_mut())
|
.zip(top_cycle.write().half_edges.iter_mut())
|
||||||
{
|
{
|
||||||
top.write().curve = Some(bottom.curve().path().into());
|
top.write().curve = Some(bottom.curve().into());
|
||||||
|
|
||||||
let boundary = bottom.boundary();
|
let boundary = bottom.boundary();
|
||||||
|
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
use crate::geometry::path::SurfacePath;
|
|
||||||
|
|
||||||
/// A curve, defined in local surface coordinates
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
|
||||||
pub struct Curve {
|
|
||||||
path: SurfacePath,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Curve {
|
|
||||||
/// Construct a new instance of `Curve`
|
|
||||||
pub fn new(path: SurfacePath) -> Self {
|
|
||||||
Self { path }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Access the path that defines the curve
|
|
||||||
pub fn path(&self) -> SurfacePath {
|
|
||||||
self.path
|
|
||||||
}
|
|
||||||
}
|
|
@ -55,7 +55,7 @@ impl Cycle {
|
|||||||
let [a, b] = first.boundary();
|
let [a, b] = first.boundary();
|
||||||
let edge_direction_positive = a < b;
|
let edge_direction_positive = a < b;
|
||||||
|
|
||||||
let circle = match first.curve().path() {
|
let circle = match first.curve() {
|
||||||
SurfacePath::Circle(circle) => circle,
|
SurfacePath::Circle(circle) => circle,
|
||||||
SurfacePath::Line(_) => unreachable!(
|
SurfacePath::Line(_) => unreachable!(
|
||||||
"Invalid cycle: less than 3 edges, but not all are circles"
|
"Invalid cycle: less than 3 edges, but not all are circles"
|
||||||
|
@ -2,7 +2,8 @@ use fj_interop::ext::ArrayExt;
|
|||||||
use fj_math::Point;
|
use fj_math::Point;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
objects::{Curve, GlobalVertex, SurfaceVertex},
|
geometry::path::SurfacePath,
|
||||||
|
objects::{GlobalVertex, SurfaceVertex},
|
||||||
storage::Handle,
|
storage::Handle,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ use crate::{
|
|||||||
/// <https://github.com/hannobraun/Fornjot/issues/1608>
|
/// <https://github.com/hannobraun/Fornjot/issues/1608>
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
|
||||||
pub struct HalfEdge {
|
pub struct HalfEdge {
|
||||||
curve: Curve,
|
curve: SurfacePath,
|
||||||
boundary: [(Point<1>, Handle<SurfaceVertex>); 2],
|
boundary: [(Point<1>, Handle<SurfaceVertex>); 2],
|
||||||
global_form: Handle<GlobalEdge>,
|
global_form: Handle<GlobalEdge>,
|
||||||
}
|
}
|
||||||
@ -52,7 +53,7 @@ pub struct HalfEdge {
|
|||||||
impl HalfEdge {
|
impl HalfEdge {
|
||||||
/// Create an instance of `HalfEdge`
|
/// Create an instance of `HalfEdge`
|
||||||
pub fn new(
|
pub fn new(
|
||||||
curve: Curve,
|
curve: SurfacePath,
|
||||||
boundary: [(Point<1>, Handle<SurfaceVertex>); 2],
|
boundary: [(Point<1>, Handle<SurfaceVertex>); 2],
|
||||||
global_form: Handle<GlobalEdge>,
|
global_form: Handle<GlobalEdge>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@ -64,7 +65,7 @@ impl HalfEdge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Access the curve that defines the half-edge's geometry
|
/// Access the curve that defines the half-edge's geometry
|
||||||
pub fn curve(&self) -> Curve {
|
pub fn curve(&self) -> SurfacePath {
|
||||||
self.curve
|
self.curve
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
pub mod curve;
|
|
||||||
pub mod cycle;
|
pub mod cycle;
|
||||||
pub mod edge;
|
pub mod edge;
|
||||||
pub mod face;
|
pub mod face;
|
||||||
|
@ -79,7 +79,6 @@ mod stores;
|
|||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
full::{
|
full::{
|
||||||
curve::Curve,
|
|
||||||
cycle::{Cycle, HalfEdgesOfCycle},
|
cycle::{Cycle, HalfEdgesOfCycle},
|
||||||
edge::{GlobalEdge, HalfEdge, VerticesInNormalizedOrder},
|
edge::{GlobalEdge, HalfEdge, VerticesInNormalizedOrder},
|
||||||
face::{Face, FaceSet, Handedness},
|
face::{Face, FaceSet, Handedness},
|
||||||
|
@ -4,9 +4,7 @@ use fj_interop::ext::ArrayExt;
|
|||||||
use fj_math::Point;
|
use fj_math::Point;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
objects::{
|
objects::{GlobalEdge, GlobalVertex, HalfEdge, Objects, SurfaceVertex},
|
||||||
Curve, GlobalEdge, GlobalVertex, HalfEdge, Objects, SurfaceVertex,
|
|
||||||
},
|
|
||||||
partial::{FullToPartialCache, MaybeSurfacePath, Partial, PartialObject},
|
partial::{FullToPartialCache, MaybeSurfacePath, Partial, PartialObject},
|
||||||
services::Service,
|
services::Service,
|
||||||
};
|
};
|
||||||
@ -32,7 +30,7 @@ impl PartialObject for PartialHalfEdge {
|
|||||||
cache: &mut FullToPartialCache,
|
cache: &mut FullToPartialCache,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
curve: Some(half_edge.curve().path().into()),
|
curve: Some(half_edge.curve().into()),
|
||||||
vertices: half_edge
|
vertices: half_edge
|
||||||
.boundary()
|
.boundary()
|
||||||
.zip_ext(half_edge.surface_vertices())
|
.zip_ext(half_edge.surface_vertices())
|
||||||
@ -50,17 +48,13 @@ impl PartialObject for PartialHalfEdge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn build(self, objects: &mut Service<Objects>) -> Self::Full {
|
fn build(self, objects: &mut Service<Objects>) -> Self::Full {
|
||||||
let curve = {
|
let curve = match self.curve.expect("Need path to build curve") {
|
||||||
let path = match self.curve.expect("Need path to build curve") {
|
MaybeSurfacePath::Defined(path) => path,
|
||||||
MaybeSurfacePath::Defined(path) => path,
|
undefined => {
|
||||||
undefined => {
|
panic!(
|
||||||
panic!(
|
|
||||||
"Trying to build curve with undefined path: {undefined:?}"
|
"Trying to build curve with undefined path: {undefined:?}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Curve::new(path)
|
|
||||||
};
|
};
|
||||||
let vertices = self.vertices.map(|vertex| {
|
let vertices = self.vertices.map(|vertex| {
|
||||||
let position_curve = vertex
|
let position_curve = vertex
|
||||||
|
@ -101,10 +101,8 @@ impl CycleValidationError {
|
|||||||
.boundary()
|
.boundary()
|
||||||
.zip_ext([half_edge.start_vertex(), next.start_vertex()]);
|
.zip_ext([half_edge.start_vertex(), next.start_vertex()]);
|
||||||
for (position_on_curve, surface_vertex) in boundary_and_vertices {
|
for (position_on_curve, surface_vertex) in boundary_and_vertices {
|
||||||
let curve_position_on_surface = half_edge
|
let curve_position_on_surface =
|
||||||
.curve()
|
half_edge.curve().point_from_path_coords(position_on_curve);
|
||||||
.path()
|
|
||||||
.point_from_path_coords(position_on_curve);
|
|
||||||
let surface_position_from_vertex = surface_vertex.position();
|
let surface_position_from_vertex = surface_vertex.position();
|
||||||
|
|
||||||
let distance = curve_position_on_surface
|
let distance = curve_position_on_surface
|
||||||
|
Loading…
Reference in New Issue
Block a user