Skip to content

Commit

Permalink
Added slicing methods for easy access of underlying Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
gammelalf committed Sep 11, 2022
1 parent 8094a7e commit 5f21d84
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::BezierCurve;
use nalgebra::allocator::Allocator;
use nalgebra::default_allocator::DefaultAllocator;
use nalgebra::dimension::{Const, Dim, Dynamic};
use nalgebra::{OMatrix, Vector2};
use nalgebra::{MatrixSlice, MatrixSliceMut, OMatrix, Vector2};

/// Bezier Curve of arbitrary degree which stores cubic curves and lower degrees on the stack.
pub enum SimpleCurve {
Expand All @@ -28,6 +28,26 @@ pub enum SimpleCurve {
}

impl SimpleCurve {
/// Expose the underlying matrix through a slice
pub fn slice(&self) -> MatrixSlice<f64, Const<2>, Dynamic> {
match self {
SimpleCurve::Linear(BezierCurve(matrix)) => matrix.into(),
SimpleCurve::Quadratic(BezierCurve(matrix)) => matrix.into(),
SimpleCurve::Cubic(BezierCurve(matrix)) => matrix.into(),
SimpleCurve::Higher(BezierCurve(matrix)) => matrix.into(),
}
}

/// Expose the underlying matrix through a mutable slice
pub fn slice_mut(&mut self) -> MatrixSliceMut<f64, Const<2>, Dynamic> {
match self {
SimpleCurve::Linear(BezierCurve(matrix)) => matrix.into(),
SimpleCurve::Quadratic(BezierCurve(matrix)) => matrix.into(),
SimpleCurve::Cubic(BezierCurve(matrix)) => matrix.into(),
SimpleCurve::Higher(BezierCurve(matrix)) => matrix.into(),
}
}

/// Splits a curve into two parts
///
/// The first part is the same shape as the original curve between 0 and t and the second
Expand Down

0 comments on commit 5f21d84

Please sign in to comment.