Skip to content

Commit

Permalink
Merge pull request #2247 from hannobraun/geometry
Browse files Browse the repository at this point in the history
Make minor cleanups related to the geometry layer
  • Loading branch information
hannobraun authored Feb 28, 2024
2 parents f2eb656 + a6923b3 commit 911cd73
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
4 changes: 2 additions & 2 deletions crates/fj-core/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ mod tests {
let (surface_path, boundary) =
SurfacePath::line_from_points([[1., 1.], [2., 1.]]);
let boundary = CurveBoundary::from(boundary);
let surface = core.layers.objects.surfaces.xz_plane().geometry();
let surface = core.layers.geometry.xz_plane();

let tolerance = 1.;
let approx = (&curve, surface_path, &surface, boundary)
Expand Down Expand Up @@ -274,7 +274,7 @@ mod tests {
let surface_path =
SurfacePath::circle_from_center_and_radius([0., 0.], 1.);
let boundary = CurveBoundary::from([[0.], [TAU]]);
let surface = core.layers.objects.surfaces.xz_plane().geometry();
let surface = core.layers.geometry.xz_plane();

let tolerance = 1.;
let approx = (&curve, surface_path, &surface, boundary)
Expand Down
44 changes: 39 additions & 5 deletions crates/fj-core/src/geometry/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,40 @@ use super::{GlobalPath, SurfaceGeometry};

/// Geometric data that is associated with topological objects
pub struct Geometry {
/// The geometry of surfaces
pub surface: BTreeMap<HandleWrapper<Surface>, SurfaceGeometry>,
surface: BTreeMap<HandleWrapper<Surface>, SurfaceGeometry>,

xy_plane: Handle<Surface>,
xz_plane: Handle<Surface>,
yz_plane: Handle<Surface>,
}

impl Geometry {
/// Create a new instance of `Geometry`
pub fn new(objects: &Objects) -> Self {
let mut self_ = Self {
surface: BTreeMap::new(),

xy_plane: objects.surfaces.xy_plane(),
xz_plane: objects.surfaces.xz_plane(),
yz_plane: objects.surfaces.yz_plane(),
};

self_.define_surface_inner(
objects.surfaces.xy_plane(),
self_.xy_plane.clone(),
SurfaceGeometry {
u: GlobalPath::x_axis(),
v: Vector::unit_y(),
},
);
self_.define_surface_inner(
objects.surfaces.xz_plane(),
self_.xz_plane.clone(),
SurfaceGeometry {
u: GlobalPath::x_axis(),
v: Vector::unit_z(),
},
);
self_.define_surface_inner(
objects.surfaces.yz_plane(),
self_.yz_plane.clone(),
SurfaceGeometry {
u: GlobalPath::y_axis(),
v: Vector::unit_z(),
Expand All @@ -54,4 +61,31 @@ impl Geometry {
) {
self.surface.insert(surface.clone().into(), geometry);
}

/// # Access the geometry of the provided surface
///
/// ## Panics
///
/// Panics, if the geometry of surface is not defined.
pub fn of_surface(&self, surface: &Handle<Surface>) -> SurfaceGeometry {
self.surface
.get(&surface.clone().into())
.copied()
.expect("Expected geometry of surface to be defined")
}

/// Access the geometry of the xy-plane
pub fn xy_plane(&self) -> SurfaceGeometry {
self.of_surface(&self.xy_plane)
}

/// Access the geometry of the xz-plane
pub fn xz_plane(&self) -> SurfaceGeometry {
self.of_surface(&self.xz_plane)
}

/// Access the geometry of the yz-plane
pub fn yz_plane(&self) -> SurfaceGeometry {
self.of_surface(&self.yz_plane)
}
}
4 changes: 2 additions & 2 deletions crates/fj-core/src/objects/any_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ macro_rules! any_object {

/// Validate the object with a pre-defined validation configuration
pub fn validate(&self,
config: &ValidationConfig,
errors: &mut Vec<ValidationError>
config: &ValidationConfig,
errors: &mut Vec<ValidationError>,
) {
match self {
$(
Expand Down

0 comments on commit 911cd73

Please sign in to comment.