Skip to content

Commit

Permalink
Merge pull request #1599 from hannobraun/surface
Browse files Browse the repository at this point in the history
Start moving reference to `Surface` from `Cycle` to `Face`
  • Loading branch information
hannobraun authored Feb 17, 2023
2 parents 06950a8 + a7365e6 commit 0fd4db6
Show file tree
Hide file tree
Showing 18 changed files with 342 additions and 310 deletions.
12 changes: 5 additions & 7 deletions crates/fj-kernel/src/algorithms/approx/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
//!
//! See [`CycleApprox`].
use std::ops::Deref;

use fj_math::Segment;

use crate::objects::Cycle;
use crate::objects::{Cycle, Surface};

use super::{
curve::CurveCache, edge::HalfEdgeApprox, Approx, ApproxPoint, Tolerance,
};

impl Approx for &Cycle {
impl Approx for (&Cycle, &Surface) {
type Approximation = CycleApprox;
type Cache = CurveCache;

Expand All @@ -21,13 +19,13 @@ impl Approx for &Cycle {
tolerance: impl Into<Tolerance>,
cache: &mut Self::Cache,
) -> Self::Approximation {
let (cycle, surface) = self;
let tolerance = tolerance.into();

let half_edges = self
let half_edges = cycle
.half_edges()
.map(|half_edge| {
(half_edge, self.surface().deref())
.approx_with_cache(tolerance, cache)
(half_edge, surface).approx_with_cache(tolerance, cache)
})
.collect();

Expand Down
8 changes: 5 additions & 3 deletions crates/fj-kernel/src/algorithms/approx/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! See [`FaceApprox`].
use std::collections::BTreeSet;
use std::{collections::BTreeSet, ops::Deref};

use fj_interop::mesh::Color;

Expand Down Expand Up @@ -87,11 +87,13 @@ impl Approx for &Face {
// would need to provide its own approximation, as the edges that bound
// it have nothing to do with its curvature.

let exterior = self.exterior().approx_with_cache(tolerance, cache);
let exterior = (self.exterior().deref(), self.surface().deref())
.approx_with_cache(tolerance, cache);

let mut interiors = BTreeSet::new();
for cycle in self.interiors() {
let cycle = cycle.approx_with_cache(tolerance, cache);
let cycle = (cycle.deref(), self.surface().deref())
.approx_with_cache(tolerance, cache);
interiors.insert(cycle);
}

Expand Down
5 changes: 4 additions & 1 deletion crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ mod tests {
];

let face = {
let mut face = PartialFace::default();
let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior
.write()
Expand Down
10 changes: 8 additions & 2 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ mod tests {
services.objects.surfaces.xz_plane(),
]
.map(|surface| {
let mut face = PartialFace::default();
let mut face = PartialFace {
surface: Partial::from(surface.clone()),
..Default::default()
};
face.exterior.write().surface = Partial::from(surface);
face.exterior.write().update_as_polygon_from_points(points);

Expand Down Expand Up @@ -122,7 +125,10 @@ mod tests {
services.objects.surfaces.xz_plane(),
];
let [a, b] = surfaces.clone().map(|surface| {
let mut face = PartialFace::default();
let mut face = PartialFace {
surface: Partial::from(surface.clone()),
..Default::default()
};
face.exterior.write().surface = Partial::from(surface);
face.exterior.write().update_as_polygon_from_points(points);

Expand Down
80 changes: 56 additions & 24 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,13 @@ mod tests {
fn point_is_outside_face() {
let mut services = Services::new();

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[1., 1.],
Expand All @@ -169,9 +173,13 @@ mod tests {
fn ray_hits_vertex_while_passing_outside() {
let mut services = Services::new();

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[2., 1.],
Expand All @@ -193,9 +201,13 @@ mod tests {
fn ray_hits_vertex_at_cycle_seam() {
let mut services = Services::new();

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[4., 2.],
[0., 4.],
Expand All @@ -217,9 +229,13 @@ mod tests {
fn ray_hits_vertex_while_staying_inside() {
let mut services = Services::new();

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[2., 1.],
Expand All @@ -242,9 +258,13 @@ mod tests {
fn ray_hits_parallel_edge_and_leaves_face_at_vertex() {
let mut services = Services::new();

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[2., 1.],
Expand All @@ -267,9 +287,13 @@ mod tests {
fn ray_hits_parallel_edge_and_does_not_leave_face_there() {
let mut services = Services::new();

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[2., 1.],
Expand All @@ -293,9 +317,13 @@ mod tests {
fn point_is_coincident_with_edge() {
let mut services = Services::new();

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[2., 0.],
Expand Down Expand Up @@ -326,9 +354,13 @@ mod tests {
fn point_is_coincident_with_vertex() {
let mut services = Services::new();

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[0., 0.],
[1., 0.],
Expand Down
70 changes: 49 additions & 21 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,13 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.yz_plane());
let surface = Partial::from(services.objects.surfaces.yz_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand All @@ -186,9 +190,13 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.yz_plane());
let surface = Partial::from(services.objects.surfaces.yz_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand All @@ -212,9 +220,13 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.yz_plane());
let surface = Partial::from(services.objects.surfaces.yz_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand All @@ -235,9 +247,13 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.yz_plane());
let surface = Partial::from(services.objects.surfaces.yz_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand Down Expand Up @@ -269,9 +285,13 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.yz_plane());
let surface = Partial::from(services.objects.surfaces.yz_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand Down Expand Up @@ -303,9 +323,13 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand All @@ -328,9 +352,13 @@ mod tests {

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);

let mut face = PartialFace::default();
face.exterior.write().surface =
Partial::from(services.objects.surfaces.xy_plane());
let surface = Partial::from(services.objects.surfaces.xy_plane());

let mut face = PartialFace {
surface: surface.clone(),
..Default::default()
};
face.exterior.write().surface = surface;
face.exterior.write().update_as_polygon_from_points([
[-1., -1.],
[1., -1.],
Expand Down
20 changes: 4 additions & 16 deletions crates/fj-kernel/src/algorithms/reverse/face.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
insert::Insert,
objects::{Face, Objects},
partial::{FullToPartialCache, Partial, PartialFace, PartialObject},
services::Service,
storage::Handle,
};
Expand All @@ -10,24 +9,13 @@ use super::Reverse;

impl Reverse for Handle<Face> {
fn reverse(self, objects: &mut Service<Objects>) -> Self {
let mut cache = FullToPartialCache::default();

let exterior = Partial::from_full(
self.exterior().clone().reverse(objects),
&mut cache,
);
let exterior = self.exterior().clone().reverse(objects);
let interiors = self
.interiors()
.map(|cycle| {
Partial::from_full(cycle.clone().reverse(objects), &mut cache)
})
.map(|cycle| cycle.clone().reverse(objects))
.collect::<Vec<_>>();

let face = PartialFace {
exterior,
interiors,
color: Some(self.color()),
};
face.build(objects).insert(objects)
Face::new(self.surface().clone(), exterior, interiors, self.color())
.insert(objects)
}
}
Loading

0 comments on commit 0fd4db6

Please sign in to comment.