Inline redundant function

This commit is contained in:
Hanno Braun 2025-02-06 20:54:41 +01:00
parent ec835ebf13
commit 4246a2169f
2 changed files with 24 additions and 31 deletions

View File

@ -1,4 +1,4 @@
use crate::geometry::Handle; use crate::{geometry::Handle, math::Plane};
use super::{face::Face, solid::Solid}; use super::{face::Face, solid::Solid};
@ -24,6 +24,27 @@ pub trait ConnectExt {
impl ConnectExt for Handle<Face> { impl ConnectExt for Handle<Face> {
fn connect(self, other: Handle<Face>) -> Solid { fn connect(self, other: Handle<Face>) -> Solid {
Solid::connect_faces([self, other]) assert_eq!(
self.vertices().count(),
other.vertices().count(),
"Can only connect faces that have the same number of vertices.",
);
let side_faces = self
.half_edges()
.zip(other.half_edges())
.map(|([q, r], [t, s])| {
let surface = Handle::new(Plane::from_points(
[q, r, s].map(|vertex| vertex.point),
));
let face = Face::new(
surface,
[q, r, s, t].map(|vertex| vertex.clone()),
);
Handle::new(face)
})
.collect::<Vec<_>>();
Solid::new([self, other].into_iter().chain(side_faces))
} }
} }

View File

@ -1,9 +1,6 @@
use std::fmt; use std::fmt;
use crate::{ use crate::geometry::{AnyOp, Handle, Operation, TriMesh};
geometry::{AnyOp, Handle, Operation, TriMesh},
math::Plane,
};
use super::face::Face; use super::face::Face;
@ -17,31 +14,6 @@ impl Solid {
faces: faces.into_iter().collect(), faces: faces.into_iter().collect(),
} }
} }
pub fn connect_faces([a, b]: [Handle<Face>; 2]) -> Self {
assert_eq!(
a.vertices().count(),
b.vertices().count(),
"Can only connect faces that have the same number of vertices.",
);
let side_faces = a
.half_edges()
.zip(b.half_edges())
.map(|([q, r], [t, s])| {
let surface = Handle::new(Plane::from_points(
[q, r, s].map(|vertex| vertex.point),
));
let face = Face::new(
surface,
[q, r, s, t].map(|vertex| vertex.clone()),
);
Handle::new(face)
})
.collect::<Vec<_>>();
Solid::new([a, b].into_iter().chain(side_faces))
}
} }
impl Operation for Solid { impl Operation for Solid {