Skip to content

Commit 04d4cc9

Browse files
committed
python: add __repr__ methods
This makes handling the objects more visual than seeing the binary addresses Signed-off-by: Baptiste Prevot <pro.baptiste.prevot@gmail.com>
1 parent 7402ba2 commit 04d4cc9

7 files changed

Lines changed: 33 additions & 8 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ node_modules
33
dist
44
data
55
.env
6+
.venv
7+
.vscode
8+
pkg

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "liblrs"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
edition = "2021"
55
description = "Library to manipulate linear referencing systems"
66
license = "MIT"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ To run locally:
4848

4949
```bash
5050
cd wasm
51+
npm install
52+
npm install -g wasm-pack
5153
npm run serve
5254
```
5355

python/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "liblrs_python"
33
description = "Python bindings for liblrs: a library to work with linear referencing systems"
4-
version = "0.2.1"
4+
version = "0.2.2"
55
edition = "2021"
66
license = "MIT"
77
repository = "https://github.com/osrd-project/liblrs/"

python/src/lib.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn liblrs_python(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
2626
Ok(())
2727
}
2828

29-
#[derive(Clone, Copy)]
29+
#[derive(Clone, Copy, Debug)]
3030
/// A geographical [`Point`], it can be either a projected or spherical coordinates.
3131
#[pyclass]
3232
pub struct Point {
@@ -47,6 +47,10 @@ impl Point {
4747
fn new(x: f64, y: f64) -> Self {
4848
Self { x, y }
4949
}
50+
51+
fn __repr__(&self) -> String {
52+
format!("{:?}", self)
53+
}
5054
}
5155

5256
impl From<geo_types::Point> for Point {
@@ -83,7 +87,7 @@ impl From<Point> for geo_types::Coord {
8387
}
8488

8589
#[pyclass]
86-
#[derive(Clone)]
90+
#[derive(Clone, Debug)]
8791
/// Represent a position on an [`LrmScale`] relative as an `offset` to an [`Anchor`].
8892
pub struct LrmScaleMeasure {
8993
#[pyo3(get, set)]
@@ -122,6 +126,10 @@ impl LrmScaleMeasure {
122126
scale_offset,
123127
}
124128
}
129+
130+
fn __repr__(&self) -> String {
131+
format!("{:?}", self)
132+
}
125133
}
126134

127135
#[derive(Clone, Copy)]
@@ -156,7 +164,7 @@ impl From<SegmentOfTraversal> for liblrs::builder::SegmentOfTraversal {
156164
}
157165
}
158166

159-
#[derive(Clone, Copy)]
167+
#[derive(Clone, Copy, Debug)]
160168
#[pyclass]
161169
/// The linear position of an anchor doesn’t always match the measured distance
162170
/// For example if a road was transformed into a bypass, resulting in a longer road,
@@ -181,6 +189,10 @@ impl AnchorOnLrm {
181189
distance_along_lrm,
182190
}
183191
}
192+
193+
fn __repr__(&self) -> String {
194+
format!("{:?}", self)
195+
}
184196
}
185197

186198
impl From<AnchorOnLrm> for liblrs::builder::AnchorOnLrm {
@@ -192,6 +204,7 @@ impl From<AnchorOnLrm> for liblrs::builder::AnchorOnLrm {
192204
}
193205
}
194206

207+
#[derive(Debug)]
195208
#[pyclass]
196209
/// An `Anchor` is a reference point for a given [`Curve`].
197210
/// It can be a milestone, a bridge…
@@ -210,6 +223,13 @@ pub struct Anchor {
210223
pub scale_position: f64,
211224
}
212225

226+
#[pymethods]
227+
impl Anchor {
228+
fn __repr__(&self) -> String {
229+
format!("{:?}", self)
230+
}
231+
}
232+
213233
#[pyclass]
214234
/// The result of a projection onto an [`LrmScale`].
215235
pub struct LrmProjection {

wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"pmtiles": "3.2.0"
2222
},
2323
"name": "liblrs",
24-
"version": "0.2.1",
24+
"version": "0.2.2",
2525
"repository": {
2626
"type": "git",
2727
"url": "https://github.com/osrd-project/liblrs/"

0 commit comments

Comments
 (0)