Track curves through Shape API

This commit is contained in:
Hanno Braun 2022-03-08 15:28:27 +01:00
parent a88476d3e6
commit 21d5f62aa5
5 changed files with 45 additions and 19 deletions

View File

@ -44,6 +44,9 @@ pub fn transform_face(
let mut edges = Vec::new();
for edge in &cycle.edges {
let curve =
shape.curves().add(edge.curve.transform(transform));
let vertices = edge.vertices.clone().map(|vertices| {
vertices.map(|vertex| {
let point =
@ -53,10 +56,7 @@ pub fn transform_face(
})
});
let edge = Edge {
curve: edge.curve.transform(transform),
vertices,
};
let edge = Edge { curve, vertices };
let edge = shape.edges().add(edge);
edges.push(edge);

View File

@ -0,0 +1,13 @@
use crate::kernel::geometry::Curve;
use super::handle::{Handle, Storage};
/// API to access the curves of a shape
pub struct Curves;
impl Curves {
/// Add a curve to the shape
pub fn add(&mut self, curve: Curve) -> Handle<Curve> {
Storage::new(curve).handle()
}
}

View File

@ -1,15 +1,20 @@
use crate::{
kernel::{
geometry::{Curve, Line, Circle},
geometry::{Circle, Curve, Line},
topology::{edges::Edge, vertices::Vertex},
},
math::{Scalar, Vector, Point},
math::{Point, Scalar, Vector},
};
use super::handle::{Handle, Storage};
use super::{
curves::Curves,
handle::{Handle, Storage},
};
/// The edges of a shape
pub struct Edges;
pub struct Edges {
pub(super) curves: Curves,
}
impl Edges {
/// Add an edge to the shape
@ -35,11 +40,12 @@ impl Edges {
/// Calls [`Edges::add`] internally, and is subject to the same
/// restrictions.
pub fn add_circle(&mut self, radius: Scalar) -> Handle<Edge> {
let curve = self.curves.add(Curve::Circle(Circle {
center: Point::origin(),
radius: Vector::from([radius, Scalar::ZERO]),
}));
self.add(Edge {
curve: Curve::Circle(Circle {
center: Point::origin(),
radius: Vector::from([radius, Scalar::ZERO]),
}),
curve,
vertices: None,
})
}
@ -52,10 +58,11 @@ impl Edges {
&mut self,
vertices: [Handle<Vertex>; 2],
) -> Handle<Edge> {
let curve = self.curves.add(Curve::Line(Line::from_points(
vertices.clone().map(|vertex| vertex.point()),
)));
self.add(Edge {
curve: Curve::Line(Line::from_points(
vertices.clone().map(|vertex| vertex.point()),
)),
curve,
vertices: Some(vertices),
})
}

View File

@ -1,3 +1,4 @@
pub mod curves;
pub mod cycles;
pub mod edges;
pub mod faces;
@ -10,8 +11,8 @@ use crate::math::Scalar;
use super::topology::{edges::Cycle, faces::Face, vertices::Vertex};
use self::{
cycles::Cycles, edges::Edges, faces::Faces, handle::Storage,
surfaces::Surfaces, vertices::Vertices,
curves::Curves, cycles::Cycles, edges::Edges, faces::Faces,
handle::Storage, surfaces::Surfaces, vertices::Vertices,
};
/// The boundary representation of a shape
@ -57,6 +58,11 @@ impl Shape {
self
}
/// Access the shape's curves
pub fn curves(&mut self) -> Curves {
Curves
}
/// Access the shape's surfaces
pub fn surfaces(&mut self) -> Surfaces {
Surfaces
@ -72,7 +78,7 @@ impl Shape {
/// Access the shape's edges
pub fn edges(&mut self) -> Edges {
Edges
Edges { curves: Curves }
}
/// Access the shape's cycles

View File

@ -20,7 +20,7 @@ pub struct Edge {
/// The edge can be a segment of the curve that is bounded by two vertices,
/// or if the curve is continuous (i.e. connects to itself), the edge could
/// be defined by the whole curve, and have no bounding vertices.
pub curve: Curve,
pub curve: Handle<Curve>,
/// Access the vertices that bound the edge on the curve
///