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

Make minor cleanups related to the geometry layer #2247

Merged
merged 4 commits into from
Feb 28, 2024
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
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