pub type IntervalClosed<RealType> = IntervalBounded<RealType, Closed, Closed>;Expand description
A closed interval [a, b] where both endpoints are included.
The IntervalClosed represents the most common type of interval in mathematics,
where both the lower bound a and upper bound b are part of the interval.
Every real number x satisfying a ≤ x ≤ b belongs to this interval.
§Mathematical Properties
- Notation:
[a, b] - Definition:
{x ∈ ℝ : a ≤ x ≤ b} - Endpoints: Both included
- Compactness: Always compact (closed and bounded)
- Connectedness: Always connected (no gaps)
§Use Cases
Closed intervals are ideal when:
- You need to include boundary values (e.g.,
[0., 1.]for probabilities) - Working with integration bounds where endpoints matter
- Defining domains where the boundary is part of the solution
- Representing physical quantities with inclusive limits
§Construction
use grid1d::intervals::*;
// Infallible construction (panics in debug mode if invalid)
let interval = IntervalClosed::new(0.0, 1.0);
// Fallible construction (returns Result)
let result = IntervalClosed::try_new(0.0, 1.0).unwrap();§Key Operations
use grid1d::intervals::*;
let interval = IntervalClosed::new(-1.0, 1.0);
// Point containment (includes endpoints)
assert!(interval.contains_point(&-1.0)); // Lower bound included
assert!(interval.contains_point(&0.0)); // Interior point
assert!(interval.contains_point(&1.0)); // Upper bound included
assert!(!interval.contains_point(&2.0)); // Outside interval
// Geometric properties
assert_eq!(interval.length().into_inner(), 2.0); // |b - a|
assert_eq!(interval.midpoint(), 0.0); // (a + b) / 2
assert!(interval.is_symmetric()); // True when a = -b
// Clamping values to interval bounds
assert_eq!(interval.clamp(-2.0), -1.0); // Below range
assert_eq!(interval.clamp(0.5), 0.5); // Within range
assert_eq!(interval.clamp(2.0), 1.0); // Above range§Comparison with Other Interval Types
| Property | Closed [a,b] | Open (a,b) | Half-open [a,b) |
|---|---|---|---|
Contains a | ✓ | ✗ | ✓ |
Contains b | ✓ | ✗ | ✗ |
| Length | b - a | b - a | b - a |
| Compactness | Always | Never | Never |
| Supremum | b (achieved) | b (not achieved) | b (not achieved) |
| Infimum | a (achieved) | a (not achieved) | a (achieved) |
§Performance Characteristics
- Memory: Two values of type
RealTypeplus bound type information - Point queries: O(1) - two comparisons
- Intersection: O(1) - bound arithmetic
- Construction: O(1) - single comparison in debug mode
§Error Conditions
Construction fails when:
lower_bound > upper_bound(invalid interval)- Either bound is not finite (NaN or infinite)
use grid1d::intervals::*;
// These will fail
assert!(IntervalClosed::try_new(1.0, 0.0).is_err()); // Inverted bounds
assert!(IntervalClosed::try_new(f64::NAN, 1.0).is_err()); // NaN bound§Advanced Usage
§Generic Programming
use grid1d::intervals::*;
use num_valid::RealScalar;
fn process_closed_interval<T: RealScalar>(interval: &IntervalClosed<T>) {
// Work with any numeric type that implements RealScalar
println!("Length: {}", interval.length());
}§Conversion to Other Types
use grid1d::intervals::*;
let closed = IntervalClosed::new(0.0, 1.0);
// Convert to general interval enum
let general: Interval<f64> = closed.clone().into();
// Convert to finite positive length category
let finite: IntervalFinitePositiveLength<f64> = closed.into();§Mathematical Examples
§Unit Interval
use grid1d::intervals::*;
let unit = IntervalClosed::new(0.0, 1.0); // [0., 1.]§Symmetric Interval
use grid1d::intervals::*;
use num_valid::{RealNative64StrictFinite, Constants};
let pi = RealNative64StrictFinite::pi();
let symmetric = IntervalClosed::new(-pi.clone(), pi); // [-π, π]
assert!(symmetric.is_symmetric());Aliased Type§
pub struct IntervalClosed<RealType> { /* private fields */ }Trait Implementations§
Source§impl<RealType: RealScalar> BuildIntervalInPartition for IntervalClosed<RealType>
impl<RealType: RealScalar> BuildIntervalInPartition for IntervalClosed<RealType>
Source§type FirstIntervalInPartition = IntervalBounded<RealType, Closed, Closed>
type FirstIntervalInPartition = IntervalBounded<RealType, Closed, Closed>
The interval type used for the first sub-interval in a partition. Read more
Source§type LastIntervalInPartition = IntervalBounded<RealType, Open, Closed>
type LastIntervalInPartition = IntervalBounded<RealType, Open, Closed>
The interval type used for the last sub-interval in a partition. Read more
Source§fn build_first_interval(
lower_bound: Self::RealType,
upper_bound: Self::RealType,
) -> Self::FirstIntervalInPartition
fn build_first_interval( lower_bound: Self::RealType, upper_bound: Self::RealType, ) -> Self::FirstIntervalInPartition
Constructs the first sub-interval in a partition. Read more
Source§fn build_last_interval(
lower_bound: Self::RealType,
upper_bound: Self::RealType,
) -> Self::LastIntervalInPartition
fn build_last_interval( lower_bound: Self::RealType, upper_bound: Self::RealType, ) -> Self::LastIntervalInPartition
Constructs the last sub-interval in a partition. Read more
Source§fn build_unique_interval(&self) -> Self
fn build_unique_interval(&self) -> Self
Builds a unique interval representing the entire domain. Read more
Source§fn build_middle_interval(
lower_bound: Self::RealType,
upper_bound: Self::RealType,
) -> IntervalLowerOpenUpperClosed<Self::RealType>
fn build_middle_interval( lower_bound: Self::RealType, upper_bound: Self::RealType, ) -> IntervalLowerOpenUpperClosed<Self::RealType>
Constructs a middle sub-interval in a partition. Read more
Source§impl<RealType: RealScalar> IntervalBoundsRuntime for IntervalClosed<RealType>
impl<RealType: RealScalar> IntervalBoundsRuntime for IntervalClosed<RealType>
Source§fn lower_bound_runtime(&self) -> Option<LowerBoundRuntime<RealType>>
fn lower_bound_runtime(&self) -> Option<LowerBoundRuntime<RealType>>
Returns the lower boundary value if the interval is bounded below. Read more
Source§fn upper_bound_runtime(&self) -> Option<UpperBoundRuntime<RealType>>
fn upper_bound_runtime(&self) -> Option<UpperBoundRuntime<RealType>>
Returns the upper boundary value if the interval is bounded above. Read more
Source§fn max_lower_bound<Other>(
&self,
other: &Other,
) -> Option<LowerBoundRuntime<Self::RealType>>where
Other: IntervalBoundsRuntime<RealType = Self::RealType>,
fn max_lower_bound<Other>(
&self,
other: &Other,
) -> Option<LowerBoundRuntime<Self::RealType>>where
Other: IntervalBoundsRuntime<RealType = Self::RealType>,
Finds the most restrictive (maximum) lower bound between two intervals. Read more
Source§fn min_upper_bound<Other>(
&self,
other: &Other,
) -> Option<UpperBoundRuntime<Self::RealType>>where
Other: IntervalBoundsRuntime<RealType = Self::RealType>,
fn min_upper_bound<Other>(
&self,
other: &Other,
) -> Option<UpperBoundRuntime<Self::RealType>>where
Other: IntervalBoundsRuntime<RealType = Self::RealType>,
Finds the most restrictive (minimum) upper bound between two intervals. Read more
Source§impl<RealType: RealScalar> IntervalHull<IntervalBounded<RealType, Closed, Closed>> for IntervalClosed<RealType>
impl<RealType: RealScalar> IntervalHull<IntervalBounded<RealType, Closed, Closed>> for IntervalClosed<RealType>
Source§impl<RealType: RealScalar> IntervalHull<IntervalBounded<RealType, Closed, Open>> for IntervalClosed<RealType>
impl<RealType: RealScalar> IntervalHull<IntervalBounded<RealType, Closed, Open>> for IntervalClosed<RealType>
Source§impl<RealType: RealScalar> IntervalHull<IntervalBounded<RealType, Open, Closed>> for IntervalClosed<RealType>
impl<RealType: RealScalar> IntervalHull<IntervalBounded<RealType, Open, Closed>> for IntervalClosed<RealType>
Source§impl<RealType: RealScalar> IntervalHull<IntervalBounded<RealType, Open, Open>> for IntervalClosed<RealType>
impl<RealType: RealScalar> IntervalHull<IntervalBounded<RealType, Open, Open>> for IntervalClosed<RealType>
Source§impl<RealType: RealScalar> IntervalHull<IntervalLowerBoundedUpperUnbounded<RealType, Closed>> for IntervalClosed<RealType>
impl<RealType: RealScalar> IntervalHull<IntervalLowerBoundedUpperUnbounded<RealType, Closed>> for IntervalClosed<RealType>
Source§impl<RealType: RealScalar> IntervalHull<IntervalLowerBoundedUpperUnbounded<RealType, Open>> for IntervalClosed<RealType>
impl<RealType: RealScalar> IntervalHull<IntervalLowerBoundedUpperUnbounded<RealType, Open>> for IntervalClosed<RealType>
Source§impl<RealType: RealScalar> IntervalHull<IntervalLowerUnboundedUpperBounded<RealType, Closed>> for IntervalClosed<RealType>
impl<RealType: RealScalar> IntervalHull<IntervalLowerUnboundedUpperBounded<RealType, Closed>> for IntervalClosed<RealType>
Source§impl<RealType: RealScalar> IntervalHull<IntervalLowerUnboundedUpperBounded<RealType, Open>> for IntervalClosed<RealType>
impl<RealType: RealScalar> IntervalHull<IntervalLowerUnboundedUpperBounded<RealType, Open>> for IntervalClosed<RealType>
Source§impl<RealType: RealScalar> IntervalHull<IntervalLowerUnboundedUpperUnbounded<RealType>> for IntervalClosed<RealType>
impl<RealType: RealScalar> IntervalHull<IntervalLowerUnboundedUpperUnbounded<RealType>> for IntervalClosed<RealType>
Source§impl<RealType: RealScalar> TryFrom<Interval<RealType>> for IntervalClosed<RealType>
impl<RealType: RealScalar> TryFrom<Interval<RealType>> for IntervalClosed<RealType>
Source§impl<RealType: RealScalar> TryFrom<IntervalFinitePositiveLength<RealType>> for IntervalClosed<RealType>
impl<RealType: RealScalar> TryFrom<IntervalFinitePositiveLength<RealType>> for IntervalClosed<RealType>
Source§type Error = ErrorsIntervalConversion<RealType>
type Error = ErrorsIntervalConversion<RealType>
The type returned in the event of a conversion error.