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

Clean up Face #855

Merged
merged 26 commits into from
Jul 20, 2022
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Convert Face into a struct
  • Loading branch information
hannobraun committed Jul 20, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 8a4d18ff1a25239d6cdf3d5183e5dd40b885f774
44 changes: 21 additions & 23 deletions crates/fj-kernel/src/objects/face.rs
Original file line number Diff line number Diff line change
@@ -7,20 +7,8 @@ use super::{Cycle, Surface};

/// A face of a shape
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum Face {
/// A face of a shape
///
/// A face is defined by a surface, and is bounded by edges that lie in that
/// surface.
BRep(FaceBRep),

/// The triangles of the face
///
/// Representing faces as a collection of triangles is a temporary state.
/// The plan is to eventually represent faces as a geometric surface,
/// bounded by edges. While the transition is being made, this variant is
/// still required.
TriRep(TriRep),
pub struct Face {
representation: Representation,
}

impl Face {
@@ -34,17 +22,21 @@ impl Face {
let exteriors = exteriors.into_iter().collect();
let interiors = interiors.into_iter().collect();

Self::BRep(FaceBRep {
surface,
exteriors,
interiors,
color,
})
Self {
representation: Representation::BRep(FaceBRep {
surface,
exteriors,
interiors,
color,
}),
}
}

/// Contact an instance that uses triangle representation
pub fn from_triangles(triangles: TriRep) -> Self {
Self::TriRep(triangles)
Self {
representation: Representation::TriRep(triangles),
}
}

/// Build a face using the [`FaceBuilder`] API
@@ -88,7 +80,7 @@ impl Face {
/// will. This method exists as a workaround, while the transition is still
/// in progress.
pub fn triangles(&self) -> Option<&TriRep> {
if let Self::TriRep(triangles) = self {
if let Representation::TriRep(triangles) = &self.representation {
return Some(triangles);
}

@@ -97,7 +89,7 @@ impl Face {

/// Access the boundary representation of the face
fn brep(&self) -> &FaceBRep {
if let Self::BRep(face) = self {
if let Representation::BRep(face) = &self.representation {
return face;
}

@@ -107,6 +99,12 @@ impl Face {
}
}

#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
enum Representation {
BRep(FaceBRep),
TriRep(TriRep),
}

/// The boundary representation of a face
///
/// This type exists to ease the handling of faces that use boundary