rstmt_nrt/motion/config/path_finder_config.rs
1/*
2 Appellation: config <module>
3 Created At: 2026.01.09:11:31:54
4 Contrib: @FL03
5*/
6
7/// The [`PathFinderConfig`] object provides a standard interface for configuring various
8/// implemented transformers.
9#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
10#[cfg_attr(
11 feature = "serde",
12 derive(serde::Serialize, serde::Deserialize),
13 serde(default, rename_all = "snake_case")
14)]
15pub struct PathFinderConfig {
16 /// Maximum search depth for pathfinding
17 pub max_depth: usize,
18 /// Maximum number of paths to find
19 pub max_paths: usize,
20}
21
22impl PathFinderConfig {
23 /// the default maximum search depth for pathfinding
24 pub const DEFAULT_MAX_DEPTH: usize = 5;
25 /// the default maximum number of paths to find
26 pub const DEFAULT_MAX_PATHS: usize = 5;
27
28 /// returns a new instance of the [`PathFinderConfig`] with the given values
29 pub const fn new(depth: usize, paths: usize) -> Self {
30 Self {
31 max_depth: depth, // Default search depth
32 max_paths: paths, // default number of paths to find
33 }
34 }
35 /// returns a new instance of the [`PathFinderConfig`] with the given depth and default
36 /// [`paths`](Self::DEFAULT_MAX_PATHS)
37 pub const fn from_depth(depth: usize) -> Self {
38 Self {
39 max_depth: depth, // Default search depth
40 max_paths: Self::DEFAULT_MAX_PATHS, // default number of paths to find
41 }
42 }
43 /// returns a new instance of the [`PathFinderConfig`] with the given paths and default
44 /// [`depth`](Self::DEFAULT_MAX_DEPTH)
45 pub const fn from_paths(paths: usize) -> Self {
46 Self {
47 max_depth: Self::DEFAULT_MAX_DEPTH, // Default search depth
48 max_paths: paths, // default number of paths to find
49 }
50 }
51 /// returns the maximum depth for pathfinding
52 pub const fn max_depth(&self) -> usize {
53 self.max_depth
54 }
55 /// returns a mutable reference to the maximum depth for pathfinding
56 pub const fn max_depth_mut(&mut self) -> &mut usize {
57 &mut self.max_depth
58 }
59 /// returns the maximum number of paths to find
60 pub const fn max_paths(&self) -> usize {
61 self.max_paths
62 }
63 /// returns a mutable reference to the maximum number of paths to find
64 pub const fn max_paths_mut(&mut self) -> &mut usize {
65 &mut self.max_paths
66 }
67 /// [`replace`](core::mem::replace) the maximum depth for pathfinding, returning the previous value
68 pub const fn replace_max_depth(&mut self, depth: usize) -> usize {
69 core::mem::replace(self.max_depth_mut(), depth)
70 }
71 /// [`replace`](core::mem::replace) the maximum number of paths to find, returning the previous value
72 pub const fn replace_max_paths(&mut self, paths: usize) -> usize {
73 core::mem::replace(self.max_paths_mut(), paths)
74 }
75 /// [`replace`](core::mem::replace) the current values with that of another instance
76 pub const fn replace(&mut self, other: Self) -> Self {
77 core::mem::replace(self, other)
78 }
79 /// set the maximum depth for pathfinding
80 pub const fn set_max_depth(&mut self, depth: usize) {
81 self.max_depth = depth
82 }
83 /// set the maximum number of paths to find
84 pub const fn set_max_paths(&mut self, paths: usize) {
85 self.max_paths = paths
86 }
87 #[inline]
88 /// consumes the current instance to create another with the given maximum depth
89 pub fn with_max_depth(self, depth: usize) -> Self {
90 Self {
91 max_depth: depth,
92 ..self
93 }
94 }
95 #[inline]
96 /// consumes the current instance to create another with the given maximum number of paths
97 pub fn with_max_paths(self, paths: usize) -> Self {
98 Self {
99 max_paths: paths,
100 ..self
101 }
102 }
103}
104
105impl Default for PathFinderConfig {
106 fn default() -> Self {
107 Self {
108 max_depth: Self::DEFAULT_MAX_DEPTH,
109 max_paths: Self::DEFAULT_MAX_PATHS,
110 }
111 }
112}
113
114impl core::fmt::Display for PathFinderConfig {
115 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
116 write!(
117 f,
118 "{{ depth: {}, paths: {} }}",
119 self.max_depth, self.max_paths
120 )
121 }
122}