cartesian-tree 0.2.0__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/Cargo.lock +1 -1
  2. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/Cargo.toml +14 -1
  3. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/PKG-INFO +2 -2
  4. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/pyproject.toml +1 -1
  5. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/python/cartesian_tree/lib.py +5 -1
  6. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/src/bindings/frame.rs +13 -15
  7. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/src/bindings/pose.rs +4 -5
  8. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/src/bindings/utils.rs +6 -6
  9. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/src/frame.rs +47 -23
  10. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/src/pose.rs +14 -11
  11. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/src/tree/traits.rs +1 -0
  12. cartesian_tree-0.2.0/.github/CODEOWNERS +0 -1
  13. cartesian_tree-0.2.0/.github/workflows/ci.yaml +0 -91
  14. cartesian_tree-0.2.0/.github/workflows/publish.yaml +0 -61
  15. cartesian_tree-0.2.0/.github/workflows/release.yaml +0 -20
  16. cartesian_tree-0.2.0/.gitignore +0 -25
  17. cartesian_tree-0.2.0/license-apache +0 -176
  18. cartesian_tree-0.2.0/python/tests/__init__.py +0 -1
  19. cartesian_tree-0.2.0/python/tests/test_lib.py +0 -147
  20. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/README.md +0 -0
  21. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/license-mit +0 -0
  22. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/python/cartesian_tree/__init__.py +0 -0
  23. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/python/cartesian_tree/helper.py +0 -0
  24. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/python/cartesian_tree/py.typed +0 -0
  25. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/src/bindings/mod.rs +0 -0
  26. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/src/errors.rs +0 -0
  27. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/src/lib.rs +0 -0
  28. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/src/orientation.rs +0 -0
  29. {cartesian_tree-0.2.0 → cartesian_tree-0.2.1}/src/tree/mod.rs +0 -0
@@ -4,7 +4,7 @@ version = 4
4
4
 
5
5
  [[package]]
6
6
  name = "CartesianTree"
7
- version = "0.2.0"
7
+ version = "0.2.1"
8
8
  dependencies = [
9
9
  "nalgebra",
10
10
  "pyo3",
@@ -1,16 +1,29 @@
1
1
  [package]
2
2
  authors = ["Kn0g"]
3
3
  name = "CartesianTree"
4
- version = "0.2.0"
4
+ version = "0.2.1"
5
5
  edition = "2024"
6
6
  description = "Build hierarchical Cartesian coordinate systems to easily transform poses."
7
7
  homepage = "https://github.com/Kn0g/cartesian-tree"
8
8
  readme = "README.md"
9
9
  repository = "https://github.com/Kn0g/cartesian-tree"
10
10
  license = "MIT"
11
+ include = ["/src"]
11
12
  keywords = ["Cartesian", "coordinate-systems", "transform", "poses"]
12
13
  categories = ["mathematics", "data-structures"]
13
14
 
15
+ [lints.clippy]
16
+ all = "warn"
17
+ style = "warn"
18
+ pedantic = "warn"
19
+ cargo = "warn"
20
+ nursery = "warn"
21
+ missing_panics_doc = "warn"
22
+ missing_errors_doc = "warn"
23
+ missing_safety_doc = "warn"
24
+ empty_line_after_outer_attr = "warn"
25
+ empty_line_after_doc_comments = "warn"
26
+
14
27
  [dependencies]
15
28
  nalgebra = { version = "0.33.2", features = ["serde-serialize"] }
16
29
  pyo3 = { version = "0.25.0", features = ["extension-module"] , optional = true}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cartesian-tree
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Classifier: Programming Language :: Python
5
5
  Requires-Dist: cartesian-tree[lint] ; extra == 'dev'
6
6
  Requires-Dist: cartesian-tree[test] ; extra == 'dev'
@@ -13,12 +13,12 @@ Provides-Extra: dev
13
13
  Provides-Extra: lint
14
14
  Provides-Extra: test
15
15
  Provides-Extra: build
16
+ License-File: license-mit
16
17
  Summary: Build hierarchical Cartesian coordinate systems to easily transform poses.
17
18
  Keywords: Cartesian,coordinate systems,transform,poses
18
19
  Home-Page: https://github.com/Kn0g/cartesian-tree
19
20
  Author: Kn0g
20
21
  Maintainer: Kn0g
21
- License-Expression: MIT
22
22
  Requires-Python: >=3.9
23
23
  Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
24
24
 
@@ -9,7 +9,7 @@ maintainers = [{name = "Kn0g"}]
9
9
  description = "Build hierarchical Cartesian coordinate systems to easily transform poses."
10
10
  readme = "README.md"
11
11
  keywords = ["Cartesian", "coordinate systems", "transform", "poses"]
12
- license = "MIT"
12
+ license = { file = "license-mit" }
13
13
  classifiers = [
14
14
  "Programming Language :: Python"
15
15
  ]
@@ -140,11 +140,15 @@ class Frame:
140
140
  def apply_config(self, config_json: str) -> None:
141
141
  """Applies a JSON config to update matching transforms in the tree.
142
142
 
143
+ Deserializes the JSON to a temporary structure, then recursively updates transforms to the
144
+ parent frames where names match (partial apply; ignores unmatched frames in config).
145
+ It is assumed this frame is the root.
146
+
143
147
  Args:
144
148
  config_json: The JSON string to apply.
145
149
 
146
150
  Raises:
147
- ValueError: On deserialization or mismatch errors.
151
+ ValueError: On deserialization or mismatch errors (e.g. if this frame is not the root).
148
152
  """
149
153
  self._core_frame.apply_config(config_json)
150
154
 
@@ -20,7 +20,7 @@ impl PyFrame {
20
20
  #[new]
21
21
  #[pyo3(signature = (name))]
22
22
  fn new(name: String) -> Self {
23
- PyFrame {
23
+ Self {
24
24
  rust_frame: RustFrame::new_origin(name),
25
25
  }
26
26
  }
@@ -36,11 +36,11 @@ impl PyFrame {
36
36
  name: String,
37
37
  position: PyPosition,
38
38
  quaternion: PyQuaternion,
39
- ) -> PyResult<PyFrame> {
39
+ ) -> PyResult<Self> {
40
40
  let child_frame = self
41
41
  .rust_frame
42
42
  .add_child(name, position.position, quaternion.quat)?;
43
- Ok(PyFrame {
43
+ Ok(Self {
44
44
  rust_frame: child_frame,
45
45
  })
46
46
  }
@@ -52,14 +52,14 @@ impl PyFrame {
52
52
  desired_position: PyPosition,
53
53
  desired_quaternion: PyQuaternion,
54
54
  reference_pose: &PyPose,
55
- ) -> PyResult<PyFrame> {
55
+ ) -> PyResult<Self> {
56
56
  let new_rust_frame = self.rust_frame.calibrate_child(
57
57
  name,
58
58
  desired_position.position,
59
59
  desired_quaternion.quat,
60
60
  &reference_pose.rust_pose,
61
61
  )?;
62
- Ok(PyFrame {
62
+ Ok(Self {
63
63
  rust_frame: new_rust_frame,
64
64
  })
65
65
  }
@@ -98,8 +98,8 @@ impl PyFrame {
98
98
  }
99
99
 
100
100
  #[pyo3(signature = (json))]
101
- fn apply_config(&self, json: String) -> PyResult<()> {
102
- self.rust_frame.apply_config(&json)?;
101
+ fn apply_config(&self, json: &str) -> PyResult<()> {
102
+ self.rust_frame.apply_config(json)?;
103
103
  Ok(())
104
104
  }
105
105
 
@@ -108,23 +108,21 @@ impl PyFrame {
108
108
  self.rust_frame.depth()
109
109
  }
110
110
 
111
- fn root(&self) -> PyFrame {
112
- PyFrame {
111
+ fn root(&self) -> Self {
112
+ Self {
113
113
  rust_frame: self.rust_frame.root(),
114
114
  }
115
115
  }
116
116
 
117
- fn parent(&self) -> Option<PyFrame> {
118
- self.rust_frame
119
- .parent()
120
- .map(|rf| PyFrame { rust_frame: rf })
117
+ fn parent(&self) -> Option<Self> {
118
+ self.rust_frame.parent().map(|rf| Self { rust_frame: rf })
121
119
  }
122
120
 
123
- fn children(&self) -> Vec<PyFrame> {
121
+ fn children(&self) -> Vec<Self> {
124
122
  self.rust_frame
125
123
  .children()
126
124
  .into_iter()
127
- .map(|rf| PyFrame { rust_frame: rf })
125
+ .map(|rf| Self { rust_frame: rf })
128
126
  .collect()
129
127
  }
130
128
 
@@ -22,7 +22,7 @@ impl PyPose {
22
22
  .map(|frame| PyFrame { rust_frame: frame })
23
23
  }
24
24
 
25
- fn transformation(&self) -> (PyPosition, PyQuaternion) {
25
+ const fn transformation(&self) -> (PyPosition, PyQuaternion) {
26
26
  let isometry = self.rust_pose.transformation();
27
27
  (
28
28
  PyPosition {
@@ -40,9 +40,9 @@ impl PyPose {
40
40
  }
41
41
 
42
42
  #[pyo3(signature = (target_frame))]
43
- fn in_frame(&self, target_frame: &PyFrame) -> PyResult<PyPose> {
43
+ fn in_frame(&self, target_frame: &PyFrame) -> PyResult<Self> {
44
44
  let new_rust_pose = self.rust_pose.in_frame(&target_frame.rust_frame)?;
45
- Ok(PyPose {
45
+ Ok(Self {
46
46
  rust_pose: new_rust_pose,
47
47
  })
48
48
  }
@@ -70,8 +70,7 @@ impl PyPose {
70
70
  format!(
71
71
  "'{}', ({:.2}, {:.2}, {:.2})({:.4}, {:.4}, {:.4}, {:.4}))",
72
72
  self.frame()
73
- .map(|frame| frame.name())
74
- .unwrap_or_else(|| "Unknown".to_string()),
73
+ .map_or_else(|| "Unknown".to_string(), |frame| frame.name()),
75
74
  position.x,
76
75
  position.y,
77
76
  position.z,
@@ -4,7 +4,7 @@ use pyo3::prelude::*;
4
4
  use crate::CartesianTreeError;
5
5
 
6
6
  impl From<CartesianTreeError> for PyErr {
7
- fn from(err: CartesianTreeError) -> PyErr {
7
+ fn from(err: CartesianTreeError) -> Self {
8
8
  pyo3::exceptions::PyValueError::new_err(err.to_string())
9
9
  }
10
10
  }
@@ -18,8 +18,8 @@ pub struct PyRPY {
18
18
  #[pymethods]
19
19
  impl PyRPY {
20
20
  #[new]
21
- fn new(roll: f64, pitch: f64, yaw: f64) -> Self {
22
- PyRPY {
21
+ const fn new(roll: f64, pitch: f64, yaw: f64) -> Self {
22
+ Self {
23
23
  rpy: Vector3::new(roll, pitch, yaw),
24
24
  }
25
25
  }
@@ -80,7 +80,7 @@ pub struct PyQuaternion {
80
80
  impl PyQuaternion {
81
81
  #[new]
82
82
  fn new(x: f64, y: f64, z: f64, w: f64) -> Self {
83
- PyQuaternion {
83
+ Self {
84
84
  quat: UnitQuaternion::from_quaternion(nalgebra::Quaternion::new(w, x, y, z)),
85
85
  }
86
86
  }
@@ -151,8 +151,8 @@ pub struct PyPosition {
151
151
  #[pymethods]
152
152
  impl PyPosition {
153
153
  #[new]
154
- fn new(x: f64, y: f64, z: f64) -> Self {
155
- PyPosition {
154
+ const fn new(x: f64, y: f64, z: f64) -> Self {
155
+ Self {
156
156
  position: Vector3::new(x, y, z),
157
157
  }
158
158
  }
@@ -57,7 +57,7 @@ impl Frame {
57
57
  /// let origin = Frame::new_origin("world");
58
58
  /// ```
59
59
  pub fn new_origin(name: impl Into<String>) -> Self {
60
- Frame {
60
+ Self {
61
61
  data: Rc::new(RefCell::new(FrameData {
62
62
  name: name.into(),
63
63
  parent: None,
@@ -81,7 +81,7 @@ impl Frame {
81
81
 
82
82
  pub(crate) fn walk_up_and_transform(
83
83
  &self,
84
- target: &Frame,
84
+ target: &Self,
85
85
  ) -> Result<Isometry3<f64>, CartesianTreeError> {
86
86
  let mut transform = Isometry3::identity();
87
87
  let mut current = self.clone();
@@ -109,6 +109,7 @@ impl Frame {
109
109
  }
110
110
 
111
111
  /// Returns the name of the frame.
112
+ #[must_use]
112
113
  pub fn name(&self) -> String {
113
114
  self.borrow().name.clone()
114
115
  }
@@ -116,8 +117,11 @@ impl Frame {
116
117
  /// Returns the transformation from this frame to its parent frame.
117
118
  ///
118
119
  /// # Returns
119
- /// - `Ok(Isometry3<f64>)` if the frame has a parent.
120
- /// - `Err(String)` if the frame has no parent.
120
+ /// - The isometry from this frame to its parent frame.
121
+ ///
122
+ /// # Errors
123
+ /// Returns a [`CartesianTreeError`] if:
124
+ /// - The frame has no parent.
121
125
  pub fn transform_to_parent(&self) -> Result<Isometry3<f64>, CartesianTreeError> {
122
126
  if self.parent().is_none() {
123
127
  return Err(CartesianTreeError::RootHasNoParent(self.name()));
@@ -136,7 +140,10 @@ impl Frame {
136
140
  ///
137
141
  /// # Returns
138
142
  /// - `Ok(())` if the transformation was updated successfully.
139
- /// - `Err(String)` if the frame has no parent.
143
+ ///
144
+ /// # Errors
145
+ /// Returns a [`CartesianTreeError`] if:
146
+ /// - The frame has no parent (i.e., the root frame).
140
147
  ///
141
148
  /// # Example
142
149
  /// ```
@@ -178,8 +185,11 @@ impl Frame {
178
185
  /// - `orientation`: An orientation convertible into a unit quaternion.
179
186
  ///
180
187
  /// # Returns
181
- /// - `Ok(Rc<Frame>)` the newly added child frame.
182
- /// - `Err(String)` if a child with the same name already exists.
188
+ /// The newly added child frame.
189
+ ///
190
+ /// # Errors
191
+ /// Returns a [`CartesianTreeError`] if:
192
+ /// - A child with the same name already exists.
183
193
  ///
184
194
  /// # Example
185
195
  /// ```
@@ -196,7 +206,7 @@ impl Frame {
196
206
  name: impl Into<String>,
197
207
  position: Vector3<f64>,
198
208
  orientation: O,
199
- ) -> Result<Frame, CartesianTreeError>
209
+ ) -> Result<Self, CartesianTreeError>
200
210
  where
201
211
  O: IntoOrientation,
202
212
  {
@@ -217,7 +227,7 @@ impl Frame {
217
227
  let quat = orientation.into_orientation();
218
228
  let transform = Isometry3::from_parts(Translation3::from(position), quat);
219
229
 
220
- let child = Frame {
230
+ let child = Self {
221
231
  data: Rc::new(RefCell::new(FrameData {
222
232
  name: child_name,
223
233
  parent: Some(Rc::downgrade(&self.data)),
@@ -240,9 +250,13 @@ impl Frame {
240
250
  /// - `reference_pose`: The existing pose (in some frame A) used as the calibration reference.
241
251
  ///
242
252
  /// # Returns
243
- /// - `Ok(Frame)` the new child frame if successful.
244
- /// - `Err(CartesianTreeError)` if the reference frame is invalid, no common ancestor exists,
245
- /// or a child name conflict occurs.
253
+ /// - The new child frame if successful.
254
+ ///
255
+ /// # Errors
256
+ /// Returns a [`CartesianTreeError`] if:
257
+ /// - The reference frame is invalid.
258
+ /// - No common ancestor exists.
259
+ /// - A child with the same name already exists.
246
260
  ///
247
261
  /// # Example
248
262
  /// ```
@@ -264,7 +278,7 @@ impl Frame {
264
278
  desired_position: Vector3<f64>,
265
279
  desired_orientation: O,
266
280
  reference_pose: &Pose,
267
- ) -> Result<Frame, CartesianTreeError>
281
+ ) -> Result<Self, CartesianTreeError>
268
282
  where
269
283
  O: IntoOrientation,
270
284
  {
@@ -328,8 +342,11 @@ impl Frame {
328
342
  /// Transforms for root frames are set to identity.
329
343
  ///
330
344
  /// # Returns
331
- /// - `Ok(String)` the pretty-printed JSON.
332
- /// - `Err(CartesianTreeError)` on serialization failure.
345
+ /// The serialized tree as a JSON string.
346
+ ///
347
+ /// # Errors
348
+ /// Returns a [`CartesianTreeError`] if:
349
+ /// - On deserialization failure.
333
350
  pub fn to_json(&self) -> Result<String, CartesianTreeError> {
334
351
  let serial = self.to_serial();
335
352
  Ok(serde_json::to_string_pretty(&serial)?)
@@ -340,7 +357,9 @@ impl Frame {
340
357
  /// This is used internally for JSON serialization.
341
358
  fn to_serial(&self) -> SerialFrame {
342
359
  let (position, orientation) = if self.parent().is_some() {
343
- let iso = self.transform_to_parent().unwrap_or(Isometry3::identity());
360
+ let iso = self
361
+ .transform_to_parent()
362
+ .unwrap_or_else(|_| Isometry3::identity());
344
363
  (iso.translation.vector, iso.rotation)
345
364
  } else {
346
365
  (Vector3::zeros(), UnitQuaternion::identity())
@@ -357,15 +376,20 @@ impl Frame {
357
376
  /// Applies a JSON config to this frame tree by updating matching transforms.
358
377
  ///
359
378
  /// Deserializes the JSON to a temporary structure, then recursively updates transforms
360
- /// where names match (partial apply; ignores unmatched nodes in config).
379
+ /// where names match (partial apply; ignores unmatched frames in config).
361
380
  /// Skips updating root frames (identity assumed) - assumes this frame is the root.
362
381
  ///
363
382
  /// # Arguments
364
383
  /// - `json`: The JSON string to apply.
365
384
  ///
366
385
  /// # Returns
367
- /// - `Ok(())` if applied successfully (even if partial).
368
- /// - `Err(CartesianTreeError)` on deserialization or mismatch (e.g., root names differ).
386
+ /// `Ok(())` if applied successfully (even if partial).
387
+ ///
388
+ /// # Errors
389
+ /// Returns a [`CartesianTreeError`] if:
390
+ /// - On deserialization failure.
391
+ /// - The frame names do not match at the root.
392
+ ///
369
393
  pub fn apply_config(&self, json: &str) -> Result<(), CartesianTreeError> {
370
394
  let serial: SerialFrame = serde_json::from_str(json)?;
371
395
  self.apply_serial(&serial)
@@ -400,13 +424,13 @@ impl Frame {
400
424
  }
401
425
 
402
426
  impl HasParent for Frame {
403
- type Node = Frame;
427
+ type Node = Self;
404
428
 
405
429
  fn parent(&self) -> Option<Self::Node> {
406
430
  self.borrow()
407
431
  .parent
408
432
  .clone()
409
- .and_then(|data_weak| data_weak.upgrade().map(|data_rc| Frame { data: data_rc }))
433
+ .and_then(|data_weak| data_weak.upgrade().map(|data_rc| Self { data: data_rc }))
410
434
  }
411
435
  }
412
436
 
@@ -417,8 +441,8 @@ impl NodeEquality for Frame {
417
441
  }
418
442
 
419
443
  impl HasChildren for Frame {
420
- type Node = Frame;
421
- fn children(&self) -> Vec<Frame> {
444
+ type Node = Self;
445
+ fn children(&self) -> Vec<Self> {
422
446
  self.borrow().children.clone()
423
447
  }
424
448
  }
@@ -24,11 +24,11 @@ impl Pose {
24
24
  frame: Weak<RefCell<FrameData>>,
25
25
  position: Vector3<f64>,
26
26
  orientation: O,
27
- ) -> Pose
27
+ ) -> Self
28
28
  where
29
29
  O: IntoOrientation,
30
30
  {
31
- Pose {
31
+ Self {
32
32
  parent: frame,
33
33
  transform_to_parent: Isometry3::from_parts(
34
34
  Translation3::from(position),
@@ -52,6 +52,7 @@ impl Pose {
52
52
  /// let pose = frame.add_pose(Vector3::new(0.0, 0.0, 0.0), UnitQuaternion::identity());
53
53
  /// assert_eq!(pose.frame().unwrap().name(), "base");
54
54
  /// ```
55
+ #[must_use]
55
56
  pub fn frame(&self) -> Option<Frame> {
56
57
  self.parent.upgrade().map(|data| Frame { data })
57
58
  }
@@ -60,7 +61,8 @@ impl Pose {
60
61
  ///
61
62
  /// # Returns
62
63
  /// The transformation of the pose in its parent frame.
63
- pub fn transformation(&self) -> Isometry3<f64> {
64
+ #[must_use]
65
+ pub const fn transformation(&self) -> Isometry3<f64> {
64
66
  self.transform_to_parent
65
67
  }
66
68
 
@@ -93,8 +95,12 @@ impl Pose {
93
95
  /// * `target` - The frame to express this pose in.
94
96
  ///
95
97
  /// # Returns
96
- /// - `Ok(Pose)` a new `Pose`, expressed in the `target` frame.
97
- /// - `Err(String)` if the frame hierarchy cannot be resolved (due to dropped frames or no common ancestor).
98
+ /// A new `Pose`, expressed in the `target` frame.
99
+ ///
100
+ /// # Errors
101
+ /// Returns a [`CartesianTreeError`] if:
102
+ /// - The frame hierarchy cannot be resolved (e.g., due to dropped frames).
103
+ /// - There is no common ancestor between `self` and `target`.
98
104
  ///
99
105
  /// # Example
100
106
  /// ```
@@ -106,7 +112,7 @@ impl Pose {
106
112
  /// let new_frame = root.add_child("child", Vector3::new(1.0, 0.0, 0.0), UnitQuaternion::identity()).unwrap();
107
113
  /// let pose_in_new_frame = pose.in_frame(&new_frame);
108
114
  /// ```
109
- pub fn in_frame(&self, target: &Frame) -> Result<Pose, CartesianTreeError> {
115
+ pub fn in_frame(&self, target: &Frame) -> Result<Self, CartesianTreeError> {
110
116
  let source_data = self
111
117
  .parent
112
118
  .upgrade()
@@ -114,10 +120,7 @@ impl Pose {
114
120
  let source = Frame { data: source_data };
115
121
  let ancestor = source
116
122
  .lca_with(target)
117
- .ok_or(CartesianTreeError::NoCommonAncestor(
118
- source.name(),
119
- target.name(),
120
- ))?;
123
+ .ok_or_else(|| CartesianTreeError::NoCommonAncestor(source.name(), target.name()))?;
121
124
 
122
125
  // Transformation from source frame up to ancestor
123
126
  let tf_up = source.walk_up_and_transform(&ancestor)? * self.transform_to_parent;
@@ -125,7 +128,7 @@ impl Pose {
125
128
  // Transformation from target frame up to ancestor (to be inverted)
126
129
  let tf_down = target.walk_up_and_transform(&ancestor)?;
127
130
 
128
- Ok(Pose {
131
+ Ok(Self {
129
132
  parent: target.downgrade(),
130
133
  transform_to_parent: tf_down.inverse() * tf_up,
131
134
  })
@@ -59,6 +59,7 @@ pub trait Walking: HasParent<Node = Self> + NodeEquality + Clone {
59
59
  /// # Returns
60
60
  ///
61
61
  /// The root Node.
62
+ #[must_use]
62
63
  fn root(&self) -> Self {
63
64
  self.walk_up(self.depth()).unwrap_or_else(|| self.clone())
64
65
  }
@@ -1 +0,0 @@
1
- * @Kn0g
@@ -1,91 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- push:
5
- branches:
6
- - "**"
7
- pull_request:
8
- branches:
9
- - "main"
10
- workflow_dispatch:
11
- workflow_call:
12
-
13
- env:
14
- CARGO_TERM_COLOR: always
15
-
16
- jobs:
17
- test:
18
- name: Test (${{ matrix.os }} / py${{ matrix.python-version }})
19
- runs-on: ${{ matrix.os }}
20
- strategy:
21
- fail-fast: false
22
- matrix:
23
- os: [ubuntu-latest, macos-latest]
24
- python-version: ["3.9", "3.10", "3.11", "3.12"]
25
-
26
- steps:
27
- - uses: actions/checkout@v4
28
-
29
- - name: Install Rust toolchain
30
- uses: dtolnay/rust-toolchain@stable
31
- with:
32
- components: rustfmt, clippy
33
-
34
- - name: Cache cargo
35
- uses: actions/cache@v4
36
- with:
37
- path: |
38
- ~/.cargo/registry
39
- ~/.cargo/git
40
- target
41
- key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
42
-
43
- - name: Cache pip
44
- uses: actions/cache@v4
45
- with:
46
- path: ~/.cache/pip
47
- key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
48
-
49
- - name: Run Rust fmt
50
- run: cargo fmt --check
51
-
52
- - name: Run clippy
53
- run: cargo clippy --all-features
54
-
55
- - name: Run Rust tests
56
- run: cargo test --verbose
57
-
58
- - name: Setup Python
59
- uses: actions/setup-python@v5
60
- with:
61
- python-version: ${{ matrix.python-version }}
62
-
63
- - name: Create Python Virtual Environment
64
- run: python -m venv .venv
65
-
66
- - name: Activate Virtual Environment and Install Python dependencies
67
- run: |
68
- source .venv/bin/activate
69
- pip install .[dev]
70
-
71
- - name: Run ruff linting
72
- run: |
73
- source .venv/bin/activate
74
- ruff format --check python
75
- ruff check python
76
-
77
- - name: Run mypy
78
- run: |
79
- source .venv/bin/activate
80
- mypy python
81
-
82
- - name: Build and install Python bindings
83
- run: |
84
- source .venv/bin/activate
85
- maturin develop --release
86
-
87
- - name: Run Python tests
88
- run: |
89
- source .venv/bin/activate
90
- pytest python/tests
91
-
@@ -1,61 +0,0 @@
1
- name: Publish
2
-
3
- on:
4
- workflow_call:
5
- secrets:
6
- CARGO_REGISTRY_TOKEN:
7
- required: true
8
- PYPI_TOKEN:
9
- required: true
10
-
11
- env:
12
- CARGO_TERM_COLOR: always
13
-
14
- jobs:
15
- publish-rust:
16
- name: Publish Rust Crate
17
- runs-on: ubuntu-latest
18
- steps:
19
- - uses: actions/checkout@v4
20
- - name: Install Rust toolchain
21
- uses: dtolnay/rust-toolchain@stable
22
-
23
- - name: Publish to crates.io
24
- run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
25
-
26
- publish-python:
27
- name: Publish Python Package
28
- runs-on: ${{ matrix.os }}
29
- strategy:
30
- fail-fast: false
31
- matrix:
32
- os: [ubuntu-latest, macos-latest]
33
- python-version: ["3.9", "3.10", "3.11", "3.12"]
34
-
35
- steps:
36
- - uses: actions/checkout@v4
37
- - name: Setup Python
38
- uses: actions/setup-python@v5
39
- with:
40
- python-version: ${{ matrix.python-version }}
41
-
42
- - name: Build and publish wheels
43
- uses: messense/maturin-action@v1
44
- with:
45
- maturin-version: latest
46
- command: publish
47
- args: --username __token__ --password ${{ secrets.PYPI_TOKEN }} --skip-existing
48
- manylinux: auto
49
-
50
- publish-sdist:
51
- name: Publish sdist (source)
52
- runs-on: ubuntu-latest
53
- steps:
54
- - uses: actions/checkout@v4
55
-
56
- - uses: actions/setup-python@v5
57
- with:
58
- python-version: "3.12"
59
-
60
- - name: Build and publish sdist
61
- run: maturin publish --sdist --username __token__ --password ${{ secrets.PYPI_TOKEN }} --skip-existing
@@ -1,20 +0,0 @@
1
- name: Release Tag
2
-
3
- on:
4
- push:
5
- tags:
6
- - "**"
7
-
8
- jobs:
9
- ci:
10
- name: Run CI Checks
11
- uses: ./.github/workflows/ci.yaml
12
-
13
- publish:
14
- name: Publish Releases
15
- needs: ci
16
- if: success()
17
- uses: ./.github/workflows/publish.yaml
18
- secrets:
19
- CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
20
- PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
@@ -1,25 +0,0 @@
1
- # Generated by Cargo
2
- # will have compiled files and executables
3
- debug/
4
- target/
5
-
6
- # These are backup files generated by rustfmt
7
- **/*.rs.bk
8
-
9
- # MSVC Windows builds of rustc generate these, which store debugging information
10
- *.pdb
11
-
12
- # RustRover
13
- # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
14
- # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
15
- # and can be added to the global gitignore or merged into this file. For a more nuclear
16
- # option (not recommended) you can uncomment the following to ignore the entire idea folder.
17
- #.idea/
18
-
19
- # Python eco-system
20
- venv
21
- **/*/__pycache__
22
- **/*/*cartesian_tree.cpython-*.so
23
-
24
- # VS Code
25
- .vscode/
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
@@ -1 +0,0 @@
1
- """Tests."""
@@ -1,147 +0,0 @@
1
- """Contains unit tests for the library."""
2
-
3
- from math import radians
4
-
5
- import pytest
6
-
7
- from cartesian_tree import RPY, Frame, Pose, Position, Quaternion
8
-
9
-
10
- def test_create_root_frame() -> None:
11
- frame = Frame("root")
12
- assert frame.name == "root"
13
- assert frame.parent() is None
14
- assert frame.depth == 0
15
-
16
-
17
- def test_tree_structure() -> None:
18
- frame = Frame("root")
19
- pos = Position(1.0, 2.0, 3.0)
20
- quat = Quaternion(0.0, 0.0, 0.0, 1.0)
21
- child = frame.add_child("child", pos, quat)
22
- grandchild = child.add_child("grandchild", pos, quat)
23
- assert grandchild.depth == 2 # noqa: PLR2004
24
- parent = grandchild.parent()
25
- assert parent is not None
26
- assert parent.name == "child"
27
- assert grandchild.root().name == "root"
28
-
29
-
30
- def test_add_child_frame_with_quaternion() -> None:
31
- root = Frame("base")
32
- pos = Position(1.0, 2.0, 3.0)
33
- quat = Quaternion(0.0, 0.0, 0.0, 1.0)
34
- child = root.add_child("child", pos, quat)
35
-
36
- assert isinstance(child, Frame)
37
- assert child.name == "child"
38
- parent = child.parent()
39
- assert parent is not None
40
- assert parent.name == "base"
41
- assert root.children()[0].name == "child"
42
-
43
-
44
- def test_add_child_frame_with_rpy() -> None:
45
- root = Frame("world")
46
- pos = Position(0.0, 0.0, 0.0)
47
- rpy = RPY(0.0, 0.0, 0.0)
48
- child = root.add_child("child_rpy", pos, rpy)
49
-
50
- assert isinstance(child, Frame)
51
- assert child.name == "child_rpy"
52
-
53
- parent = child.parent()
54
- assert parent is not None
55
- assert parent.name == "world"
56
-
57
-
58
- def test_transformation_to_parent_and_update() -> None:
59
- root = Frame("root")
60
- pos = Position(1.0, 2.0, 3.0)
61
- quat = Quaternion(0.0, 0.0, 0.0, 1.0)
62
- child = root.add_child("child", pos, quat)
63
-
64
- orig_pos, orig_quat = child.transformation_to_parent()
65
- assert isinstance(orig_pos, Position)
66
- assert isinstance(orig_quat, Quaternion)
67
-
68
- # Update transformation
69
- new_pos = Position(5.0, 6.0, 7.0)
70
- new_quat = Quaternion(0.0, 0.7071, 0.0, 0.7071)
71
- child.update_transformation(new_pos, new_quat)
72
-
73
- upd_pos, upd_quat = child.transformation_to_parent()
74
- assert upd_pos.to_tuple() == pytest.approx((5.0, 6.0, 7.0), abs=1e-5)
75
- assert upd_quat.to_tuple() == pytest.approx((0.0, 0.7071, 0.0, 0.7071), abs=1e-5)
76
-
77
-
78
- def test_add_pose_and_update() -> None:
79
- root = Frame("base")
80
- pos = Position(1.0, 2.0, 3.0)
81
- quat = Quaternion(0.0, 0.0, 0.0, 1.0)
82
- pose = root.add_pose(pos, quat)
83
-
84
- assert isinstance(pose, Pose)
85
- p_pos, p_quat = pose.transformation()
86
- assert p_pos.to_tuple() == pytest.approx((1.0, 2.0, 3.0), abs=1e-5)
87
- assert p_quat.to_tuple() == pytest.approx((0.0, 0.0, 0.0, 1.0), abs=1e-5)
88
-
89
- # Update the pose
90
- new_pos = Position(4.0, 5.0, 6.0)
91
- new_rpy = RPY(0.0, 0.0, 0.0)
92
- pose.update(new_pos, new_rpy)
93
- up_pos, _ = pose.transformation()
94
- assert up_pos.to_tuple() == pytest.approx((4.0, 5.0, 6.0), abs=1e-5)
95
-
96
- # Access frame
97
- frame_of_pose = pose.frame()
98
- assert frame_of_pose.name == "base"
99
- frame_of_pose.add_child("child_of_pose_frame", pos, quat)
100
- assert len(frame_of_pose.children()) == 1
101
-
102
-
103
- def test_pose_in_frame() -> None:
104
- base = Frame("base")
105
- frame_1 = base.add_child("frame1", Position(1, 1, 1), Quaternion(0, 0, 0, 1))
106
- frame_2 = base.add_child("frame2", Position(-2, 0, 0), RPY(0, 0, radians(90)))
107
-
108
- pose_in_frame1 = frame_1.add_pose(Position(0, 0, 0), Quaternion(0, 0, 0, 1))
109
- transformed_pose = pose_in_frame1.in_frame(frame_2)
110
-
111
- pos, quat = transformed_pose.transformation()
112
-
113
- assert pos.to_tuple() == pytest.approx((1.0, -3.0, 1.0), abs=1e-5)
114
- assert quat.to_rpy().to_tuple() == pytest.approx((0.0, 0.0, -radians(90)), abs=1e-5)
115
-
116
-
117
- def test_calibrate_frame() -> None:
118
- base = Frame("base")
119
- reference_frame = base.add_child("reference", Position(1, 1, 1), Quaternion(0, 0, 0, 1))
120
- reference_pose = reference_frame.add_pose(Position(1, 1, 1), Quaternion(0, 0, 0, 1))
121
-
122
- calibrated_frame = base.calibrate_child("calibrated", Position(0, 0, 0), RPY(0, 0, 0), reference_pose)
123
-
124
- pos, quat = calibrated_frame.transformation_to_parent()
125
-
126
- assert pos.to_tuple() == pytest.approx((2.0, 2.0, 2.0), abs=1e-5)
127
- assert quat.to_tuple() == pytest.approx((0.0, 0.0, 0.0, 1.0), abs=1e-5)
128
-
129
-
130
- def test_serialization() -> None:
131
- root = Frame("root")
132
- child1 = root.add_child("child1", Position(1, 0, 0), Quaternion(0, 0, 0, 1))
133
- child2 = child1.add_child("child2", Position(0, 1, 0), RPY(0, 0, radians(90)))
134
- child2.add_pose(Position(0, 0, 1), Quaternion(0, 0, 0, 1))
135
-
136
- json_str = root.to_json()
137
-
138
- default_root = Frame("root")
139
- default_child1 = default_root.add_child("child1", Position(2, 0, 0), Quaternion(0, 0, 0, 1))
140
- default_child2 = default_child1.add_child("child2", Position(0, 2, 0), RPY(0, 0, radians(90)))
141
-
142
- default_root.apply_config(json_str)
143
-
144
- position, _ = default_child1.transformation_to_parent()
145
- assert position.to_tuple() == pytest.approx((1.0, 0.0, 0.0), abs=1e-5) # Updated back to '1'
146
- position, _ = default_child2.transformation_to_parent()
147
- assert position.to_tuple() == pytest.approx((0.0, 1.0, 0.0), abs=1e-5) # Updated back to '1'
File without changes