-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1949 from hannobraun/queries
Add infrastructure for non-trivial object queries
- Loading branch information
Showing
5 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::{ | ||
objects::Vertex, | ||
storage::{Handle, HandleWrapper}, | ||
}; | ||
|
||
/// The bounding vertices of an edge | ||
#[derive(Eq, PartialEq)] | ||
pub struct BoundingVertices { | ||
/// The bounding vertices | ||
pub inner: [HandleWrapper<Vertex>; 2], | ||
} | ||
|
||
impl From<[Handle<Vertex>; 2]> for BoundingVertices { | ||
fn from(vertices: [Handle<Vertex>; 2]) -> Self { | ||
Self { | ||
inner: vertices.map(Into::into), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
//! Types that are tied to objects, but aren't objects themselves | ||
mod boundary; | ||
mod bounding_vertices; | ||
mod path; | ||
mod surface; | ||
|
||
pub use self::{ | ||
boundary::BoundaryOnCurve, | ||
bounding_vertices::BoundingVertices, | ||
path::{GlobalPath, SurfacePath}, | ||
surface::SurfaceGeometry, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//! Queries about objects | ||
//! | ||
//! Objects have methods that provide access to anything that the object itself | ||
//! has direct access to. However, not all potentially interesting information | ||
//! can be accessed that way. An example are the bounding vertices of an edge: | ||
//! `HalfEdge` only stores its starting vertex, so you need a `Cycle` to get | ||
//! both vertices. | ||
//! | ||
//! This module provides traits express such non-trivial queries, and implements | ||
//! them for various objects that have the information to answer the query. | ||
use crate::{ | ||
geometry::BoundingVertices, | ||
objects::{Cycle, Face, HalfEdge, Region, Shell}, | ||
storage::Handle, | ||
}; | ||
|
||
/// Determine the bounding vertices of an edge | ||
pub trait BoundingVerticesOfEdge { | ||
/// Determine the bounding vertices of an edge | ||
/// | ||
/// Returns `None`, if the provided edge is not part of the object this | ||
/// method is called on. | ||
fn bounding_vertices_of_edge( | ||
&self, | ||
edge: &Handle<HalfEdge>, | ||
) -> Option<BoundingVertices>; | ||
} | ||
|
||
impl BoundingVerticesOfEdge for Cycle { | ||
fn bounding_vertices_of_edge( | ||
&self, | ||
edge: &Handle<HalfEdge>, | ||
) -> Option<BoundingVertices> { | ||
let start = edge.start_vertex().clone(); | ||
let end = self.half_edge_after(edge)?.start_vertex().clone(); | ||
|
||
Some(BoundingVertices::from([start, end])) | ||
} | ||
} | ||
|
||
impl BoundingVerticesOfEdge for Region { | ||
fn bounding_vertices_of_edge( | ||
&self, | ||
edge: &Handle<HalfEdge>, | ||
) -> Option<BoundingVertices> { | ||
for cycle in self.all_cycles() { | ||
if let Some(vertices) = cycle.bounding_vertices_of_edge(edge) { | ||
return Some(vertices); | ||
} | ||
} | ||
|
||
None | ||
} | ||
} | ||
|
||
impl BoundingVerticesOfEdge for Face { | ||
fn bounding_vertices_of_edge( | ||
&self, | ||
edge: &Handle<HalfEdge>, | ||
) -> Option<BoundingVertices> { | ||
self.region().bounding_vertices_of_edge(edge) | ||
} | ||
} | ||
|
||
impl BoundingVerticesOfEdge for Shell { | ||
fn bounding_vertices_of_edge( | ||
&self, | ||
edge: &Handle<HalfEdge>, | ||
) -> Option<BoundingVertices> { | ||
for face in self.faces() { | ||
if let Some(vertices) = face.bounding_vertices_of_edge(edge) { | ||
return Some(vertices); | ||
} | ||
} | ||
|
||
None | ||
} | ||
} |