[−][src]Struct truck_modeling::geometry::KnotVec
knot vector
Implementations
impl KnotVec
[src]
pub const fn new() -> KnotVec
[src]
empty constructor
pub fn range_length(&self) -> f64
[src]
Returns the length of range.
Examples
use truck_geometry::*; let knot_vec = KnotVec::from(vec![0.0, 6.0]); assert_eq!(knot_vec.range_length(), 6.0);
pub fn same_range(&self, other: &KnotVec) -> bool
[src]
Returns whether two knot vectors have the same range.
Examples
use truck_geometry::*; let knot_vec0 = KnotVec::new(); // empty knot vector let knot_vec1 = KnotVec::from(vec![0.0, 0.0, 1.0, 1.0]); let knot_vec2 = KnotVec::from(vec![0.0, 0.5, 1.0]); let knot_vec3 = KnotVec::from(vec![0.0, 0.0, 2.0, 2.0]); assert!(knot_vec0.same_range(&KnotVec::new())); // both empty knot vector assert!(!knot_vec0.same_range(&knot_vec1)); assert!(knot_vec1.same_range(&knot_vec2)); // the range of both knot vector is [0, 1]. assert!(!knot_vec1.same_range(&knot_vec3));
pub fn remove(&mut self, idx: usize) -> f64
[src]
Removes one item.
pub fn floor(&self, x: f64) -> Option<usize>
[src]
Returns the maximum index i
of self[i] <= x
Return None
if x < self[0] or self.len() == 0
.
Examples
use truck_geometry::KnotVec; let mut knot_vec = KnotVec::from(vec![0.0, 0.0, 1.0, 2.0, 3.0, 3.0]); let idx = knot_vec.floor(1.5).unwrap(); assert_eq!(idx, 2);
pub fn multiplicity(&self, i: usize) -> usize
[src]
the multiplicity of the i
th knot
Examples
use truck_geometry::KnotVec; let knot_vec = KnotVec::from(vec![0.0, 0.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0]); assert_eq!(knot_vec.multiplicity(5), 3);
pub fn add_knot(&mut self, knot: f64) -> usize
[src]
add a knot and return the index of the added knot.
Examples
use truck_geometry::KnotVec; let mut knot_vec = KnotVec::from(vec![0.0, 0.0, 1.0, 2.0, 3.0, 3.0]); let idx0 = knot_vec.add_knot(1.5); assert_eq!(idx0, 3); let idx1 = knot_vec.add_knot(-1.0); assert_eq!(idx1, 0); let ansvec = KnotVec::from(vec![-1.0, 0.0, 0.0, 1.0, 1.5, 2.0, 3.0, 3.0]); assert_eq!(knot_vec, ansvec);
pub fn bspline_basis_functions(&self, degree: usize, t: f64) -> Vec<f64, Global>ⓘ
[src]
Calculate B-spline basis functions at t
with degree degree
.
Panics
If the length of self
is not more than degree
, panic occurs.
Remarks
In this package, the B-spline basis function is based on the characteristic function of the right-open intervals [s, t). So, the value corresponding to the end point t = t_n is always 0.0.
Examples
use truck_geometry::{Tolerance, KnotVec}; const N : usize = 100; // sample size in tests // B-spline basis functions is a partition of unity in (t_k, t_{n - k}). let vec = vec![0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]; let knot_vec = KnotVec::from(vec); let degree = 2; for i in 0..N { let t = 2.0 + 4.0 / (N as f64) * (i as f64); let res = knot_vec.bspline_basis_functions(degree, t); let sum = res.iter().fold(0.0, |sum, a| sum + a); f64::assert_near2(&sum, &1.0); }
use truck_geometry::{Tolerance, KnotVec}; const N : usize = 100; // sample size in tests // In some case, B-spline basis functions coincide with Bernstein polynomials. let vec = vec![0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0]; let knot_vec = KnotVec::from(vec); let degree = 3; for i in 0..=N { let t = 1.0 / (N as f64) * (i as f64); let res = knot_vec.bspline_basis_functions(degree, t); let ans = [ 1.0 * (1.0 - t) * (1.0 - t) * (1.0 - t), 3.0 * t * (1.0 - t) * (1.0 - t), 3.0 * t * t * (1.0 - t), 1.0 * t * t * t, ]; for i in 0..4 { f64::assert_near2(&res[i], &ans[i]); } }
pub fn try_bspline_basis_functions(
&self,
degree: usize,
t: f64
) -> Result<Vec<f64, Global>, Error>
[src]
&self,
degree: usize,
t: f64
) -> Result<Vec<f64, Global>, Error>
Calculate B-spline basis functions at t
with degree degree
.
Failures
- If the range of the knot vector is zero, returns
Error::ZeroRange
. - If the length of
self
is not more thandegree
, returnsError::TooLargeDegree(length, degree)
.
Remarks
In this package, the B-spline basis function is based on the characteristic function of the right-open intervals [s, t). So, the value corresponding to the end point t = t_n is always 0.0.
Examples
use truck_geometry::{Tolerance, KnotVec}; const N : usize = 100; // sample size in tests // B-spline basis functions is a partition of unity in (t_k, t_{n - k}). let vec = vec![0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]; let knot_vec = KnotVec::from(vec); let degree = 2; for i in 0..N { let t = 2.0 + 4.0 / (N as f64) * (i as f64); let res = knot_vec.try_bspline_basis_functions(degree, t).unwrap(); let sum = res.iter().fold(0.0, |sum, a| sum + a); f64::assert_near2(&sum, &1.0); }
use truck_geometry::{Tolerance, KnotVec}; const N : usize = 100; // sample size in tests // In some case, B-spline basis functions coincide with Bernstein polynomials. let vec = vec![0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0]; let knot_vec = KnotVec::from(vec); let degree = 3; for i in 0..=N { let t = i as f64 / N as f64; let res = knot_vec.try_bspline_basis_functions(degree, t).unwrap(); let ans = [ 1.0 * (1.0 - t) * (1.0 - t) * (1.0 - t), 3.0 * t * (1.0 - t) * (1.0 - t), 3.0 * t * t * (1.0 - t), 1.0 * t * t * t, ]; println!("{:?}", res); for i in 0..4 { f64::assert_near2(&res[i], &ans[i]); } }
pub fn try_normalize(&mut self) -> Result<&mut KnotVec, Error>
[src]
Normalizes the knot vector i.e. makes the first value 0 and the last value 1.
Failures
Returns Error::ZeroRange
if the range of the knot vector is so small.
Examples
use truck_geometry::KnotVec; let mut knot_vec = KnotVec::from(vec![1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 5.0]); knot_vec.try_normalize().unwrap(); let res : Vec<f64> = knot_vec.into(); assert_eq!(res, vec![0.0, 0.0, 0.25, 0.5, 0.75, 1.0, 1.0]);
pub fn normalize(&mut self) -> &mut KnotVec
[src]
Normalizes the knot vector i.e. makes the first value 0 and the last value 1.
Panics
Panic occurs if the range of the knot vector is so small.
Examples
use truck_geometry::KnotVec; let mut knot_vec = KnotVec::from(vec![1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 5.0]); knot_vec.normalize(); let res : Vec<f64> = knot_vec.into(); assert_eq!(res, vec![0.0, 0.0, 0.25, 0.5, 0.75, 1.0, 1.0]);
pub fn translate(&mut self, x: f64) -> &mut KnotVec
[src]
translate the knot vector
Example
use std::vec::Vec; use truck_geometry::KnotVec; let mut knot_vec = KnotVec::from(vec![1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 5.0]); knot_vec.translate(3.0); let res : Vec<f64> = knot_vec.into(); assert_eq!(res, vec![4.0, 4.0, 5.0, 6.0, 7.0, 8.0, 8.0]);
pub fn invert(&mut self) -> &mut KnotVec
[src]
Inverts the knot vector
Example
use std::vec::Vec; use truck_geometry::KnotVec; let mut knot_vec = KnotVec::from(vec![1.0, 1.0, 1.0, 3.0, 5.0, 6.0]); knot_vec.invert(); let res : Vec<f64> = knot_vec.into(); assert_eq!(res, vec![1.0, 2.0, 4.0, 6.0, 6.0, 6.0]);
pub fn is_clamped(&self, degree: usize) -> bool
[src]
determine the knot vector is clamped for the given degree.
Examples
use truck_geometry::KnotVec; let knot_vec = KnotVec::from(vec![0.0, 0.0, 0.0, 0.25, 0.5, 0.75, 1.0, 1.0, 1.0]); assert!(knot_vec.is_clamped(2)); assert!(!knot_vec.is_clamped(3));
pub fn try_concat(
&mut self,
other: &KnotVec,
degree: usize
) -> Result<&mut KnotVec, Error>
[src]
&mut self,
other: &KnotVec,
degree: usize
) -> Result<&mut KnotVec, Error>
Concats two knot vectors.
Examples
use truck_geometry::KnotVec; let mut knot_vec0 = KnotVec::from(vec![0.0, 0.0, 0.0, 1.0, 1.0, 1.0]); let knot_vec1 = KnotVec::from(vec![1.0, 1.0, 1.0, 2.0, 2.0, 2.0]); knot_vec0.try_concat(&knot_vec1, 2).unwrap(); assert_eq!(knot_vec0.as_slice(), &[0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0]);
Failures
- If at least one of
self
orother
is not clamped, returnsError::NotClampedKnotVector
- If the last knot of
self
and the first knot ofother
are different, returnsError::DifferentBackFront(self.last, other.first)
.
pub fn concat(&mut self, other: &KnotVec, degree: usize) -> &mut KnotVec
[src]
Concats two knot vectors.
Examples
use truck_geometry::KnotVec; let mut knot_vec0 = KnotVec::from(vec![0.0, 0.0, 0.0, 1.0, 1.0, 1.0]); let knot_vec1 = KnotVec::from(vec![1.0, 1.0, 1.0, 2.0, 2.0, 2.0]); knot_vec0.concat(&knot_vec1, 2); assert_eq!(knot_vec0.as_slice(), &[0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0]);
Panics
Panic occurs if:
- At least one of
self
orother
is not clamped. - The last knot of
self
and the first knot ofother
are different.
pub fn sub_vec<I>(&self, range: I) -> KnotVec where
I: SliceIndex<[f64], Output = [f64]>,
[src]
I: SliceIndex<[f64], Output = [f64]>,
Returns trimmed vector by the specified range.
Examples
use truck_geometry::*; let knot_vec = KnotVec::from(vec![0.0, 1.0, 2.0, 3.0, 4.0, 5.0]); let sub_vec = knot_vec.sub_vec(1..3); assert_eq!(sub_vec, KnotVec::from(vec![1.0, 2.0]));
pub fn to_single_multi(&self) -> (Vec<f64, Global>, Vec<usize, Global>)
[src]
To single-multi discription. i.e. decompose the unique vector of knots and the vector of multiplicity of knots.
Examples
use truck_geometry::KnotVec; let knot_vec = KnotVec::from(vec![0.0, 0.0, 0.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0]); let (knots, mults) = knot_vec.to_single_multi(); assert_eq!(knots, vec![0.0, 1.0, 2.0, 3.0]); assert_eq!(mults, vec![3, 1, 4, 2]);
pub fn from_single_multi(
knots: Vec<f64, Global>,
mults: Vec<usize, Global>
) -> Result<KnotVec, Error>
[src]
knots: Vec<f64, Global>,
mults: Vec<usize, Global>
) -> Result<KnotVec, Error>
construct from single-multi description.
Examples
use truck_geometry::KnotVec; let knots = vec![0.0, 1.0, 2.0, 3.0]; let mults = vec![3, 1, 4, 2]; let knot_vec = KnotVec::from_single_multi(knots, mults).unwrap(); assert_eq!(knot_vec, KnotVec::from(vec![0.0, 0.0, 0.0, 1.0, 2.0, 2.0, 2.0, 2.0, 3.0, 3.0]));
pub fn try_from(vec: Vec<f64, Global>) -> Result<KnotVec, Error>
[src]
construct from Vec<f64>
. do not sort, only check sorted.
pub fn bezier_knot(degree: usize) -> KnotVec
[src]
Constructs the knot vector for the bezier spline.
Examples
use truck_geometry::*; assert_eq!( *KnotVec::bezier_knot(3), vec![0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0], );
pub fn uniform_knot(degree: usize, division: usize) -> KnotVec
[src]
Constructs the uniform knot vector
Examples
use truck_geometry::*; assert_eq!( *KnotVec::uniform_knot(2, 5), vec![0.0, 0.0, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.0, 1.0], );
Methods from Deref<Target = Vec<f64, Global>>
pub fn capacity(&self) -> usize
1.0.0[src]
Returns the number of elements the vector can hold without reallocating.
Examples
let vec: Vec<i32> = Vec::with_capacity(10); assert_eq!(vec.capacity(), 10);
pub fn as_slice(&self) -> &[T]
1.7.0[src]
Extracts a slice containing the entire vector.
Equivalent to &s[..]
.
Examples
use std::io::{self, Write}; let buffer = vec![1, 2, 3, 5, 8]; io::sink().write(buffer.as_slice()).unwrap();
pub fn as_ptr(&self) -> *const T
1.37.0[src]
Returns a raw pointer to the vector's buffer.
The caller must ensure that the vector outlives the pointer this function returns, or else it will end up pointing to garbage. Modifying the vector may cause its buffer to be reallocated, which would also make any pointers to it invalid.
The caller must also ensure that the memory the pointer (non-transitively) points to
is never written to (except inside an UnsafeCell
) using this pointer or any pointer
derived from it. If you need to mutate the contents of the slice, use as_mut_ptr
.
Examples
let x = vec![1, 2, 4]; let x_ptr = x.as_ptr(); unsafe { for i in 0..x.len() { assert_eq!(*x_ptr.add(i), 1 << i); } }
pub fn allocator(&self) -> &A
[src]
allocator_api
)Returns a reference to the underlying allocator.
pub fn len(&self) -> usize
1.0.0[src]
Returns the number of elements in the vector, also referred to as its 'length'.
Examples
let a = vec![1, 2, 3]; assert_eq!(a.len(), 3);
pub fn is_empty(&self) -> bool
1.0.0[src]
Returns true
if the vector contains no elements.
Examples
let mut v = Vec::new(); assert!(v.is_empty()); v.push(1); assert!(!v.is_empty());
Trait Implementations
impl AsRef<[f64]> for KnotVec
[src]
impl Clone for KnotVec
[src]
impl Debug for KnotVec
[src]
impl Deref for KnotVec
[src]
type Target = Vec<f64, Global>
The resulting type after dereferencing.
pub fn deref(&self) -> &Vec<f64, Global>ⓘ
[src]
impl<'de> Deserialize<'de> for KnotVec
[src]
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<KnotVec, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
[src]
__deserializer: __D
) -> Result<KnotVec, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
impl<'_> From<&'_ Vec<f64, Global>> for KnotVec
[src]
pub fn from(vec: &Vec<f64, Global>) -> KnotVec
[src]
construct by the reference of vector. The clone of vector is sorted by the order.
use truck_geometry::KnotVec; let knot_vec = KnotVec::from(&vec![1.0, 0.0, 3.0, 2.0]); let arr : Vec<f64> = knot_vec.into(); assert_eq!(arr, vec![0.0, 1.0, 2.0, 3.0]);
impl From<KnotVec> for Vec<f64, Global>
[src]
pub fn from(knotvec: KnotVec) -> Vec<f64, Global>ⓘ
[src]
KnotVec into Vec
use truck_geometry::KnotVec; let vec = vec![0.0, 1.0, 2.0, 3.0]; let knot_vec = KnotVec::from(&vec); let vec0 : Vec<f64> = knot_vec.into(); assert_eq!(vec, vec0);
impl From<Vec<f64, Global>> for KnotVec
[src]
pub fn from(vec: Vec<f64, Global>) -> KnotVec
[src]
construct from Vec<f64>
. The vector will sorted by the order.
use truck_geometry::KnotVec; let knot_vec = KnotVec::from(vec![1.0, 0.0, 3.0, 2.0]); let arr : Vec<f64> = knot_vec.into(); assert_eq!(arr, vec![0.0, 1.0, 2.0, 3.0]);
impl FromIterator<f64> for KnotVec
[src]
pub fn from_iter<I>(iter: I) -> KnotVec where
I: IntoIterator<Item = f64>,
[src]
I: IntoIterator<Item = f64>,
impl<'a> IntoIterator for &'a KnotVec
[src]
type Item = &'a f64
The type of the elements being iterated over.
type IntoIter = Iter<'a, f64>
Which kind of iterator are we turning this into?
pub fn into_iter(self) -> <&'a KnotVec as IntoIterator>::IntoIter
[src]
impl PartialEq<KnotVec> for KnotVec
[src]
impl Serialize for KnotVec
[src]
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
[src]
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
impl StructuralPartialEq for KnotVec
[src]
Auto Trait Implementations
impl RefUnwindSafe for KnotVec
[src]
impl Send for KnotVec
[src]
impl Sync for KnotVec
[src]
impl Unpin for KnotVec
[src]
impl UnwindSafe for KnotVec
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,