Skip to content

Commit

Permalink
Merge pull request #1200 from hannobraun/planes
Browse files Browse the repository at this point in the history
Provide access to default planes through `Objects`
  • Loading branch information
hannobraun authored Oct 11, 2022
2 parents e02c595 + fe5e0b4 commit 4ba6a22
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 98 deletions.
10 changes: 5 additions & 5 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ mod tests {
use fj_math::Point;

use crate::{
objects::{Curve, HalfEdge, Objects, Surface},
objects::{Curve, HalfEdge, Objects},
partial::HasPartial,
storage::Handle,
};
Expand All @@ -86,7 +86,7 @@ mod tests {
fn compute_edge_in_front_of_curve_origin() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
Expand All @@ -110,7 +110,7 @@ mod tests {
fn compute_edge_behind_curve_origin() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
Expand All @@ -134,7 +134,7 @@ mod tests {
fn compute_edge_parallel_to_curve() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
Expand All @@ -153,7 +153,7 @@ mod tests {
fn compute_edge_on_curve() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ where
#[cfg(test)]
mod tests {
use crate::{
objects::{Curve, Face, Objects, Surface},
objects::{Curve, Face, Objects},
partial::HasPartial,
storage::Handle,
};
Expand All @@ -167,7 +167,7 @@ mod tests {
fn compute() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();

let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
Expand Down
11 changes: 5 additions & 6 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod tests {

use crate::{
algorithms::intersect::CurveFaceIntersection,
objects::{Curve, Face, Objects, Surface},
objects::{Curve, Face, Objects},
partial::HasPartial,
storage::Handle,
};
Expand All @@ -82,9 +82,8 @@ mod tests {
[2., 2.],
[1., 2.],
];
let [a, b] =
[Surface::xy_plane(), Surface::xz_plane()].map(|surface| {
let surface = objects.surfaces.insert(surface);
let [a, b] = [objects.surfaces.xy_plane(), objects.surfaces.xz_plane()]
.map(|surface| {
Face::builder(&objects, surface)
.with_exterior_polygon_from_points(points)
.build()
Expand All @@ -106,8 +105,8 @@ mod tests {
[ 1., 1.],
[-1., 1.],
];
let surfaces = [Surface::xy_plane(), Surface::xz_plane()]
.map(|surface| objects.surfaces.insert(surface));
let surfaces =
[objects.surfaces.xy_plane(), objects.surfaces.xz_plane()];
let [a, b] = surfaces.clone().map(|surface| {
Face::builder(&objects, surface)
.with_exterior_polygon_from_points(points)
Expand Down
18 changes: 9 additions & 9 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ mod tests {
use crate::{
algorithms::intersect::{face_point::FacePointIntersection, Intersect},
iter::ObjectIters,
objects::{Face, Objects, Surface},
objects::{Face, Objects},
};

#[test]
fn point_is_outside_face() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([[0., 0.], [1., 1.], [0., 2.]])
.build();
Expand All @@ -155,7 +155,7 @@ mod tests {
fn ray_hits_vertex_while_passing_outside() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([[0., 0.], [2., 1.], [0., 2.]])
.build();
Expand All @@ -172,7 +172,7 @@ mod tests {
fn ray_hits_vertex_at_cycle_seam() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([[4., 2.], [0., 4.], [0., 0.]])
.build();
Expand All @@ -189,7 +189,7 @@ mod tests {
fn ray_hits_vertex_while_staying_inside() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([
[0., 0.],
Expand All @@ -211,7 +211,7 @@ mod tests {
fn ray_hits_parallel_edge_and_leaves_face_at_vertex() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([
[0., 0.],
Expand All @@ -233,7 +233,7 @@ mod tests {
fn ray_hits_parallel_edge_and_does_not_leave_face_there() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([
[0., 0.],
Expand All @@ -256,7 +256,7 @@ mod tests {
fn point_is_coincident_with_edge() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([[0., 0.], [2., 0.], [0., 1.]])
.build();
Expand All @@ -282,7 +282,7 @@ mod tests {
fn point_is_coincident_with_vertex() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]])
.build();
Expand Down
16 changes: 8 additions & 8 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ mod tests {
transform::TransformObject,
},
iter::ObjectIters,
objects::{Face, Objects, Surface},
objects::{Face, Objects},
};

#[test]
Expand All @@ -161,7 +161,7 @@ mod tests {

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

let surface = objects.surfaces.insert(Surface::yz_plane());
let surface = objects.surfaces.yz_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([
[-1., -1.],
Expand All @@ -181,7 +181,7 @@ mod tests {

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

let surface = objects.surfaces.insert(Surface::yz_plane());
let surface = objects.surfaces.yz_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([
[-1., -1.],
Expand All @@ -204,7 +204,7 @@ mod tests {

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

let surface = objects.surfaces.insert(Surface::yz_plane());
let surface = objects.surfaces.yz_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([
[-1., -1.],
Expand All @@ -224,7 +224,7 @@ mod tests {

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

let surface = objects.surfaces.insert(Surface::yz_plane());
let surface = objects.surfaces.yz_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([
[-1., -1.],
Expand Down Expand Up @@ -255,7 +255,7 @@ mod tests {

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

let surface = objects.surfaces.insert(Surface::yz_plane());
let surface = objects.surfaces.yz_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([
[-1., -1.],
Expand Down Expand Up @@ -284,7 +284,7 @@ mod tests {

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

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([
[-1., -1.],
Expand All @@ -306,7 +306,7 @@ mod tests {

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

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([
[-1., -1.],
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/intersect/surface_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mod tests {

use crate::{
algorithms::transform::TransformObject,
objects::{Curve, Objects, Surface},
objects::{Curve, Objects},
partial::HasPartial,
storage::Handle,
};
Expand All @@ -99,8 +99,8 @@ mod tests {
fn plane_plane() {
let objects = Objects::new();

let xy = objects.surfaces.insert(Surface::xy_plane());
let xz = objects.surfaces.insert(Surface::xz_plane());
let xy = objects.surfaces.xy_plane();
let xz = objects.surfaces.xz_plane();

// Coincident and parallel planes don't have an intersection curve.
assert_eq!(
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ mod tests {

use crate::{
algorithms::{reverse::Reverse, sweep::Sweep},
objects::{Cycle, Face, HalfEdge, Objects, Surface},
objects::{Cycle, Face, HalfEdge, Objects},
partial::HasPartial,
};

Expand All @@ -197,14 +197,14 @@ mod tests {
let objects = Objects::new();

let half_edge = HalfEdge::partial()
.with_surface(Some(objects.surfaces.insert(Surface::xy_plane())))
.with_surface(Some(objects.surfaces.xy_plane()))
.as_line_segment_from_points([[0., 0.], [1., 0.]])
.build(&objects);

let face = (half_edge, Color::default()).sweep([0., 0., 1.], &objects);

let expected_face = {
let surface = objects.surfaces.insert(Surface::xz_plane());
let surface = objects.surfaces.xz_plane();

let bottom = HalfEdge::partial()
.with_surface(Some(surface.clone()))
Expand Down
14 changes: 5 additions & 9 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod tests {

use crate::{
algorithms::{reverse::Reverse, transform::TransformObject},
objects::{Face, HalfEdge, Objects, Sketch, Surface},
objects::{Face, HalfEdge, Objects, Sketch},
partial::HasPartial,
};

Expand All @@ -95,7 +95,7 @@ mod tests {
fn sweep_up() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let solid = Sketch::builder(&objects, surface.clone())
.build_polygon_from_points(TRIANGLE)
.sweep(UP, &objects);
Expand All @@ -119,9 +119,7 @@ mod tests {
let [a, b] = [window[0], window[1]];

let half_edge = HalfEdge::partial()
.with_surface(Some(
objects.surfaces.insert(Surface::xy_plane()),
))
.with_surface(Some(objects.surfaces.xy_plane()))
.as_line_segment_from_points([a, b])
.build(&objects);
(half_edge, Color::default()).sweep(UP, &objects)
Expand All @@ -134,7 +132,7 @@ mod tests {
fn sweep_down() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let solid = Sketch::builder(&objects, surface.clone())
.build_polygon_from_points(TRIANGLE)
.sweep(DOWN, &objects);
Expand All @@ -159,9 +157,7 @@ mod tests {
let [a, b] = [window[0], window[1]];

let half_edge = HalfEdge::partial()
.with_surface(Some(
objects.surfaces.insert(Surface::xy_plane()),
))
.with_surface(Some(objects.surfaces.xy_plane()))
.as_line_segment_from_points([a, b])
.build(&objects)
.reverse();
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ mod tests {

use crate::{
algorithms::sweep::Sweep,
objects::{Curve, HalfEdge, Objects, Surface, Vertex},
objects::{Curve, HalfEdge, Objects, Vertex},
partial::HasPartial,
storage::Handle,
};
Expand All @@ -163,7 +163,7 @@ mod tests {
fn vertex_surface() {
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::xz_plane());
let surface = objects.surfaces.xz_plane();
let curve = Handle::<Curve>::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/algorithms/triangulate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ mod tests {

use crate::{
algorithms::approx::{Approx, Tolerance},
objects::{Face, Objects, Surface},
objects::{Face, Objects},
};

use super::Triangulate;
Expand All @@ -98,7 +98,7 @@ mod tests {
let c = [2., 2.];
let d = [0., 1.];

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface)
.with_exterior_polygon_from_points([a, b, c, d])
.build();
Expand Down Expand Up @@ -132,7 +132,7 @@ mod tests {
let g = [3., 3.];
let h = [3., 1.];

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface.clone())
.with_exterior_polygon_from_points([a, b, c, d])
.with_interior_polygon_from_points([e, f, g, h])
Expand Down Expand Up @@ -192,7 +192,7 @@ mod tests {
let d = [0.1, 0.1];
let e = [0., 0.8];

let surface = objects.surfaces.insert(Surface::xy_plane());
let surface = objects.surfaces.xy_plane();
let face = Face::builder(&objects, surface.clone())
.with_exterior_polygon_from_points([a, b, c, d, e])
.build();
Expand Down
Loading

0 comments on commit 4ba6a22

Please sign in to comment.