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

Generalize Triangle into Polygon #1779

Merged
merged 3 commits into from
Apr 21, 2023
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
24 changes: 14 additions & 10 deletions crates/fj-kernel/src/operations/build/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub trait BuildFace {
fn triangle(
points: [impl Into<Point<3>>; 3],
objects: &mut Service<Objects>,
) -> Triangle {
) -> Polygon<3> {
let [a, b, c] = points.map(Into::into);

let surface = Surface::plane_from_points([a, b, c]).insert(objects);
Expand All @@ -39,7 +39,7 @@ pub trait BuildFace {

let face = Face::new(surface, exterior, [], None);

Triangle {
Polygon {
face,
edges,
vertices,
Expand All @@ -49,16 +49,20 @@ pub trait BuildFace {

impl BuildFace for Face {}

/// A triangle
/// A polygon
///
/// Returned by [`BuildFace::triangle`].
pub struct Triangle {
/// The face that forms the triangle
/// # Implementation Note
///
/// Currently code that deals with `Polygon` might assume that the polygon has
/// no holes. Unless you create a `Polygon` yourself, or modify a `Polygon`'s
/// `face` field to have interior cycles, this should not affect you.
pub struct Polygon<const D: usize> {
/// The face that forms the polygon
pub face: Face,

/// The edges of the triangle
pub edges: [Handle<HalfEdge>; 3],
/// The edges of the polygon
pub edges: [Handle<HalfEdge>; D],

/// The vertices of the triangle
pub vertices: [Handle<Vertex>; 3],
/// The vertices of the polygon
pub vertices: [Handle<Vertex>; D],
}
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/operations/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod surface;
pub use self::{
cycle::BuildCycle,
edge::BuildHalfEdge,
face::{BuildFace, Triangle},
face::{BuildFace, Polygon},
shell::{BuildShell, Tetrahedron},
surface::BuildSurface,
};
10 changes: 5 additions & 5 deletions crates/fj-kernel/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
storage::Handle,
};

use super::{BuildFace, Triangle};
use super::{BuildFace, Polygon};

/// Build a [`Shell`]
pub trait BuildShell {
Expand Down Expand Up @@ -35,19 +35,19 @@ pub trait BuildShell {
) -> Tetrahedron {
let [a, b, c, d] = points.map(Into::into);

let [Triangle {
let [Polygon {
face: face_abc,
edges: [ab, bc, ca],
vertices: [a, b, c],
}, Triangle {
}, Polygon {
face: face_bad,
edges: [ba, ad, db],
vertices: [_, _, d],
}, Triangle {
}, Polygon {
face: face_dac,
edges: [da, ac, cd],
..
}, Triangle {
}, Polygon {
face: face_cbd,
edges: [cb, bd, dc],
..
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod update;
pub use self::{
build::{
BuildCycle, BuildFace, BuildHalfEdge, BuildShell, BuildSurface,
Tetrahedron, Triangle,
Polygon, Tetrahedron,
},
insert::Insert,
update::{UpdateCycle, UpdateFace, UpdateHalfEdge, UpdateShell},
Expand Down