Simplify intersection test result

This commit is contained in:
Hanno Braun 2023-02-24 14:01:59 +01:00
parent 550360c070
commit 879e005ab9
2 changed files with 9 additions and 26 deletions

View File

@ -36,9 +36,7 @@ impl FaceFaceIntersection {
let intersection_curves =
match SurfaceSurfaceIntersection::compute(surfaces, objects) {
Some(intersection) => {
intersection.intersection_curves.map(|curve| curve.path())
}
Some(intersection) => intersection.intersection_curves,
None => return None,
};

View File

@ -2,8 +2,7 @@ use fj_math::{Line, Plane, Point, Scalar};
use crate::{
geometry::path::{GlobalPath, SurfacePath},
insert::Insert,
objects::{Curve, Objects, Surface},
objects::{Objects, Surface},
services::Service,
storage::Handle,
};
@ -12,14 +11,14 @@ use crate::{
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct SurfaceSurfaceIntersection {
/// The intersection curves
pub intersection_curves: [Handle<Curve>; 2],
pub intersection_curves: [SurfacePath; 2],
}
impl SurfaceSurfaceIntersection {
/// Compute the intersection between two surfaces
pub fn compute(
surfaces: [Handle<Surface>; 2],
objects: &mut Service<Objects>,
_: &mut Service<Objects>,
) -> Option<Self> {
// Algorithm from Real-Time Collision Detection by Christer Ericson. See
// section 5.4.4, Intersection of Two Planes.
@ -53,10 +52,8 @@ impl SurfaceSurfaceIntersection {
let line = Line::from_origin_and_direction(origin, direction);
let curves = planes.map(|plane| {
let path = SurfacePath::Line(plane.project_line(&line));
Curve::new(path).insert(objects)
});
let curves =
planes.map(|plane| SurfacePath::Line(plane.project_line(&line)));
Some(Self {
intersection_curves: curves,
@ -83,10 +80,7 @@ mod tests {
use pretty_assertions::assert_eq;
use crate::{
algorithms::transform::TransformObject,
builder::CurveBuilder,
insert::Insert,
partial::{PartialCurve, PartialObject},
algorithms::transform::TransformObject, geometry::path::SurfacePath,
services::Services,
};
@ -114,17 +108,8 @@ mod tests {
None,
);
let mut expected_xy = PartialCurve::default();
expected_xy.update_as_u_axis();
let expected_xy = expected_xy
.build(&mut services.objects)
.insert(&mut services.objects);
let mut expected_xz = PartialCurve::default();
expected_xz.update_as_u_axis();
let expected_xz = expected_xz
.build(&mut services.objects)
.insert(&mut services.objects);
let expected_xy = SurfacePath::u_axis();
let expected_xz = SurfacePath::u_axis();
assert_eq!(
SurfaceSurfaceIntersection::compute(