Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build service abstraction around Objects #1392

Merged
merged 3 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions crates/fj-kernel/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,14 @@ mod tests {
insert::Insert,
objects::Objects,
partial::{PartialCurve, PartialSurface},
services::State,
};

use super::CurveApprox;

#[test]
fn approx_line_on_flat_surface() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface =
PartialSurface::from_axes(GlobalPath::x_axis(), [0., 0., 1.])
Expand All @@ -234,7 +235,7 @@ mod tests {
#[test]
fn approx_line_on_curved_surface_but_not_along_curve() -> anyhow::Result<()>
{
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = PartialSurface::from_axes(
GlobalPath::circle_from_radius(1.),
Expand All @@ -258,7 +259,7 @@ mod tests {

#[test]
fn approx_line_on_curved_surface_along_curve() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let path = GlobalPath::circle_from_radius(1.);
let surface = PartialSurface::from_axes(path, [0., 0., 1.])
Expand Down Expand Up @@ -293,7 +294,7 @@ mod tests {

#[test]
fn approx_circle_on_flat_surface() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface =
PartialSurface::from_axes(GlobalPath::x_axis(), [0., 0., 1.])
Expand Down
9 changes: 5 additions & 4 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ mod tests {
builder::{CurveBuilder, HalfEdgeBuilder},
objects::{HalfEdge, Objects},
partial::{HasPartial, PartialCurve},
services::State,
};

use super::CurveEdgeIntersection;

#[test]
fn compute_edge_in_front_of_curve_origin() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();
let mut curve = PartialCurve {
Expand All @@ -110,7 +111,7 @@ mod tests {

#[test]
fn compute_edge_behind_curve_origin() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();
let mut curve = PartialCurve {
Expand Down Expand Up @@ -139,7 +140,7 @@ mod tests {

#[test]
fn compute_edge_parallel_to_curve() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();
let mut curve = PartialCurve {
Expand All @@ -163,7 +164,7 @@ mod tests {

#[test]
fn compute_edge_on_curve() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();
let mut curve = PartialCurve {
Expand Down
3 changes: 2 additions & 1 deletion crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,14 @@ mod tests {
builder::{CurveBuilder, FaceBuilder},
objects::{Face, Objects},
partial::{HasPartial, PartialCurve},
services::State,
};

use super::CurveFaceIntersection;

#[test]
fn compute() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();

Expand Down
8 changes: 5 additions & 3 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use iter_fixed::IntoIteratorFixed;

use crate::{
objects::{Curve, Face, Objects},
services::Service,
storage::Handle,
validate::ValidationError,
};
Expand Down Expand Up @@ -30,7 +31,7 @@ impl FaceFaceIntersection {
/// Compute the intersections between two faces
pub fn compute(
faces: [&Face; 2],
objects: &mut Objects,
objects: &mut Service<Objects>,
) -> Result<Option<Self>, ValidationError> {
let surfaces = faces.map(|face| face.surface().clone());

Expand Down Expand Up @@ -74,14 +75,15 @@ mod tests {
insert::Insert,
objects::{Face, Objects},
partial::{HasPartial, PartialCurve},
services::State,
validate::ValidationError,
};

use super::FaceFaceIntersection;

#[test]
fn compute_no_intersection() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

#[rustfmt::skip]
let points = [
Expand All @@ -108,7 +110,7 @@ mod tests {

#[test]
fn compute_one_intersection() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

#[rustfmt::skip]
let points = [
Expand Down
17 changes: 9 additions & 8 deletions crates/fj-kernel/src/algorithms/intersect/face_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ mod tests {
iter::ObjectIters,
objects::{Face, Objects},
partial::HasPartial,
services::State,
};

#[test]
fn point_is_outside_face() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();
let face = Face::partial()
Expand All @@ -163,7 +164,7 @@ mod tests {

#[test]
fn ray_hits_vertex_while_passing_outside() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();
let face = Face::partial()
Expand All @@ -184,7 +185,7 @@ mod tests {

#[test]
fn ray_hits_vertex_at_cycle_seam() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();
let face = Face::partial()
Expand All @@ -205,7 +206,7 @@ mod tests {

#[test]
fn ray_hits_vertex_while_staying_inside() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();
let face = Face::partial()
Expand All @@ -232,7 +233,7 @@ mod tests {
#[test]
fn ray_hits_parallel_edge_and_leaves_face_at_vertex() -> anyhow::Result<()>
{
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();
let face = Face::partial()
Expand All @@ -259,7 +260,7 @@ mod tests {
#[test]
fn ray_hits_parallel_edge_and_does_not_leave_face_there(
) -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();
let face = Face::partial()
Expand All @@ -286,7 +287,7 @@ mod tests {

#[test]
fn point_is_coincident_with_edge() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();
let face = Face::partial()
Expand Down Expand Up @@ -316,7 +317,7 @@ mod tests {

#[test]
fn point_is_coincident_with_vertex() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let surface = objects.surfaces.xy_plane();
let face = Face::partial()
Expand Down
15 changes: 8 additions & 7 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,12 @@ mod tests {
iter::ObjectIters,
objects::{Face, Objects},
partial::HasPartial,
services::State,
};

#[test]
fn ray_misses_whole_surface() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

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

Expand All @@ -184,7 +185,7 @@ mod tests {

#[test]
fn ray_hits_face() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

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

Expand All @@ -210,7 +211,7 @@ mod tests {

#[test]
fn ray_hits_surface_but_misses_face() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

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

Expand All @@ -233,7 +234,7 @@ mod tests {

#[test]
fn ray_hits_edge() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

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

Expand Down Expand Up @@ -267,7 +268,7 @@ mod tests {

#[test]
fn ray_hits_vertex() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

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

Expand Down Expand Up @@ -299,7 +300,7 @@ mod tests {

#[test]
fn ray_is_parallel_to_surface_and_hits() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

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

Expand All @@ -325,7 +326,7 @@ mod tests {

#[test]
fn ray_is_parallel_to_surface_and_misses() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
geometry::path::{GlobalPath, SurfacePath},
insert::Insert,
objects::{Curve, GlobalCurve, Objects, Surface},
services::Service,
storage::Handle,
validate::ValidationError,
};
Expand All @@ -20,7 +21,7 @@ impl SurfaceSurfaceIntersection {
/// Compute the intersection between two surfaces
pub fn compute(
surfaces: [Handle<Surface>; 2],
objects: &mut Objects,
objects: &mut Service<Objects>,
) -> Result<Option<Self>, ValidationError> {
// Algorithm from Real-Time Collision Detection by Christer Ericson. See
// section 5.4.4, Intersection of Two Planes.
Expand Down Expand Up @@ -92,13 +93,14 @@ mod tests {
use crate::{
algorithms::transform::TransformObject, builder::CurveBuilder,
insert::Insert, objects::Objects, partial::PartialCurve,
services::State,
};

use super::SurfaceSurfaceIntersection;

#[test]
fn plane_plane() -> anyhow::Result<()> {
let mut objects = Objects::new();
let mut objects = Objects::new().into_service();

let xy = objects.surfaces.xy_plane();
let xz = objects.surfaces.xz_plane();
Expand Down
6 changes: 5 additions & 1 deletion crates/fj-kernel/src/algorithms/reverse/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
use crate::{
insert::Insert,
objects::{Cycle, Objects},
services::Service,
storage::Handle,
validate::ValidationError,
};

use super::Reverse;

impl Reverse for Handle<Cycle> {
fn reverse(self, objects: &mut Objects) -> Result<Self, ValidationError> {
fn reverse(
self,
objects: &mut Service<Objects>,
) -> Result<Self, ValidationError> {
let mut edges = self
.half_edges()
.cloned()
Expand Down
6 changes: 5 additions & 1 deletion crates/fj-kernel/src/algorithms/reverse/edge.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
use crate::{
insert::Insert,
objects::{HalfEdge, Objects},
services::Service,
storage::Handle,
validate::ValidationError,
};

use super::Reverse;

impl Reverse for Handle<HalfEdge> {
fn reverse(self, objects: &mut Objects) -> Result<Self, ValidationError> {
fn reverse(
self,
objects: &mut Service<Objects>,
) -> Result<Self, ValidationError> {
let vertices = {
let [a, b] = self.vertices().clone();
[b, a]
Expand Down
6 changes: 5 additions & 1 deletion crates/fj-kernel/src/algorithms/reverse/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ use crate::{
insert::Insert,
objects::{Face, Objects},
partial::HasPartial,
services::Service,
storage::Handle,
validate::ValidationError,
};

use super::Reverse;

impl Reverse for Handle<Face> {
fn reverse(self, objects: &mut Objects) -> Result<Self, ValidationError> {
fn reverse(
self,
objects: &mut Service<Objects>,
) -> Result<Self, ValidationError> {
let exterior = self.exterior().clone().reverse(objects)?;
let interiors = self
.interiors()
Expand Down
Loading