1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) 2025 Junior Sundar
//
// SPDX-License-Identifier: BSD-3-Clause
use cratestate;
/// A trait for checking if states are valid.
///
/// This is the central trait for defining problem-specific constraints, most commonly
/// for collision checking. A `StateValidityChecker` is given to a planner, which then
/// uses the `is_valid` method to determine if sampled states or motions are allowed.
///
/// This generic approach allows users of the `oxmpl` library to define any custom
/// logic for state validity (e.g., checking against complex geometry, satisfying
/// physical constraints) without changing the core planners.
///
/// # Example
///
/// ```
/// use oxmpl::base::state::{State, RealVectorState};
/// use oxmpl::base::validity::StateValidityChecker;
///
/// // A simple checker that considers any state with a positive x-coordinate to be invalid.
/// struct PositiveXIsInvalidChecker;
///
/// impl StateValidityChecker<RealVectorState> for PositiveXIsInvalidChecker {
/// fn is_valid(&self, state: &RealVectorState) -> bool {
/// state.values.get(0).map_or(true, |&x| x <= 0.0)
/// }
/// }
///
/// let checker = PositiveXIsInvalidChecker;
/// let valid_state = RealVectorState { values: vec![-1.0, 5.0] };
/// let invalid_state = RealVectorState { values: vec![1.0, 5.0] };
///
/// assert!(checker.is_valid(&valid_state));
/// assert!(!checker.is_valid(&invalid_state));
/// ```