Skip to content

Commit

Permalink
Merge pull request #1779 from hannobraun/polygon
Browse files Browse the repository at this point in the history
Generalize `Triangle` into `Polygon`
  • Loading branch information
hannobraun authored Apr 21, 2023
2 parents 2af2116 + 8d389c8 commit d4fb4bb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
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

0 comments on commit d4fb4bb

Please sign in to comment.