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

View File

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