Bézier-rs: Add ids to manipulator groups (#1054)

* Add ids to manipulator groups

* Fix tests

* Rename trait from ManipulatorGroupId to Identifier

* Rename EmptyManipulatorGroupId to EmptyId
This commit is contained in:
0HyperCube
2023-02-25 16:23:58 +00:00
committed by GitHub
parent 065db23e87
commit d3038665ac
8 changed files with 93 additions and 27 deletions
+8 -8
View File
@@ -12,19 +12,19 @@ use std::ops::{Index, IndexMut};
/// Structure used to represent a path composed of [Bezier] curves.
#[derive(Clone, PartialEq)]
pub struct Subpath {
manipulator_groups: Vec<ManipulatorGroup>,
pub struct Subpath<ManipulatorGroupId: crate::Identifier> {
manipulator_groups: Vec<ManipulatorGroup<ManipulatorGroupId>>,
closed: bool,
}
/// Iteration structure for iterating across each curve of a `Subpath`, using an intermediate `Bezier` representation.
pub struct SubpathIter<'a> {
pub struct SubpathIter<'a, ManipulatorGroupId: crate::Identifier> {
index: usize,
sub_path: &'a Subpath,
sub_path: &'a Subpath<ManipulatorGroupId>,
}
impl Index<usize> for Subpath {
type Output = ManipulatorGroup;
impl<ManipulatorGroupId: crate::Identifier> Index<usize> for Subpath<ManipulatorGroupId> {
type Output = ManipulatorGroup<ManipulatorGroupId>;
fn index(&self, index: usize) -> &Self::Output {
assert!(index < self.len(), "Index out of bounds in trait Index of SubPath.");
@@ -32,14 +32,14 @@ impl Index<usize> for Subpath {
}
}
impl IndexMut<usize> for Subpath {
impl<ManipulatorGroupId: crate::Identifier> IndexMut<usize> for Subpath<ManipulatorGroupId> {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
assert!(index < self.len(), "Index out of bounds in trait IndexMut of SubPath.");
&mut self.manipulator_groups[index]
}
}
impl Iterator for SubpathIter<'_> {
impl<ManipulatorGroupId: crate::Identifier> Iterator for SubpathIter<'_, ManipulatorGroupId> {
type Item = Bezier;
// Returns the Bezier representation of each `Subpath` segment, defined between a pair of adjacent manipulator points.