Add D=Dynamic default and ::to_range_inclusive for DimRange (nalgebra)

This commit is contained in:
Andreas Longva 2021-01-20 17:42:25 +01:00
parent 561501a08f
commit b2dbcf3168

View File

@ -169,7 +169,7 @@ pub struct MatrixParameters<NParameters, R, C> {
/// ranges such as `5 ..= 6`. The latter example corresponds to dimensions from (inclusive)
/// `Dynamic::new(5)` to `Dynamic::new(6)` (inclusive).
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DimRange<D>(RangeInclusive<D>);
pub struct DimRange<D=Dynamic>(RangeInclusive<D>);
impl<D: Dim> DimRange<D> {
/// The lower bound for dimensions generated.
@ -201,6 +201,13 @@ impl From<RangeInclusive<usize>> for DimRange<Dynamic> {
}
}
impl<D: Dim> DimRange<D> {
/// Converts the `DimRange` into an instance of `RangeInclusive`.
pub fn to_range_inclusive(&self) -> RangeInclusive<usize> {
self.lower_bound().value() ..= self.upper_bound().value()
}
}
impl From<usize> for DimRange<Dynamic> {
fn from(dim: usize) -> Self {
DimRange::from(Dynamic::new(dim))