Skip to content

Commit ebcf3a7

Browse files
committed
doc: enhance doc + typos
1 parent e2d176e commit ebcf3a7

File tree

1 file changed

+74
-71
lines changed

1 file changed

+74
-71
lines changed

src/lrs.rs

+74-71
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//! A linear reference system ([Lrs]) is the combination of multiple [LrmScale] and Traversals
1+
//! A Linear Reference System ([`Lrs`]) is the combination of multiple [`LrmScale`] and [`Traversal`]s.
22
//!
3-
//! For instance a highway could have a LRS, with an LrmScale for every direction
3+
//! For instance a highway could have a [`Lrs`], with an [`LrmScale`] for every direction.
44
//!
5-
//! A traversal is a chain of [Segment] that build a [Curve]. A segment could be the road between two intersections
5+
//! A traversal is a chain of `Segment` that builds a [`Curve`]. A segment could be the road between two intersections.
66
77
use std::cmp::Ordering;
88

@@ -16,14 +16,14 @@ use crate::lrm_scale::{
1616
use crate::lrs_generated;
1717
use geo::{coord, point, Point};
1818

19-
/// Handle to identify a [LrmScale] within a specific [Lrs]
19+
/// Used as handle to identify a [`LrmScale`] within a specific [`Lrs`].
2020
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
2121
pub struct LrmHandle(usize);
22-
/// Handle to identify a Traversal within a specific [Lrs]
22+
/// Used as handle to identify a [`Traversal`] within a specific [`Lrs`].
2323
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
2424
pub struct TraversalHandle(usize);
2525

26-
/// Todo create struct LRM {scale, traversals, reference_traversal}
26+
/// TODO : create struct LRM {scale, traversals, reference_traversal}
2727
2828
struct Lrm {
2929
scale: LrmScale,
@@ -37,55 +37,56 @@ struct Traversal<CurveImpl: Curve> {
3737
lrms: Vec<LrmHandle>,
3838
}
3939

40-
/// The Linear Reference System. It must be specified for a given implementation of [Curve], such as [crate::curves::LineStringCurve]
40+
/// The Linear Reference System. It must be specified for a given implementation
41+
/// of [Curve], such as [crate::curves::LineStringCurve].
4142
pub struct Lrs<CurveImpl: Curve> {
4243
lrms: Vec<Lrm>,
4344
traversals: Vec<Traversal<CurveImpl>>,
4445
}
4546

46-
/// The result of a projection onto an [LrmScale]
47+
/// The result of a projection onto an [`LrmScale`].
4748
pub struct LrmProjection {
48-
/// The measure anchor and offset
49+
/// Contains `measure` ([`LrmScaleMeasure`]) and `lrm` ([`LrmHandle`]).
4950
pub measure: LrmMeasure,
50-
/// How far from the Lrm is the point that has been projected
51+
/// How far from the [`Lrm`] is the [`Point`] that has been projected.
5152
pub orthogonal_offset: f64,
5253
}
5354

54-
/// Identifies a position on an [LrmScale] by distance from start
55+
/// Identifies a [`ScalePosition`] on an [`LrmScale`] by the distance from the start of the scale.
5556
#[derive(Clone, Copy, Debug)]
5657
pub struct LrmPosition {
57-
/// The distance from that of the scale
58+
/// The distance from that of the scale.
5859
pub distance_from_start: ScalePosition,
59-
/// Identifies the LrmScale
60+
/// Identifies the [`LrmScale`].
6061
pub lrm: LrmHandle,
6162
}
6263

63-
/// Identifies a position on an [LrmScale] by distance from an anchor of the scale
64+
/// Identifies a position on an [LrmScale] by distance from an [`Anchor`] of the scale.
6465
#[derive(Clone, Debug)]
6566
pub struct LrmMeasure {
66-
/// Anchor and offset to that anchor
67+
/// Contains `anchor_name` and `scale_offset` ([`ScalePosition`]).
6768
pub measure: LrmScaleMeasure,
68-
/// Identifies the LrmScale
69+
/// Identifies the [`LrmScale`].
6970
pub lrm: LrmHandle,
7071
}
7172

72-
/// The result of a projection an a Traversal
73+
/// The result of a projection an a [`Traversal`].
7374
#[derive(Clone, Copy, Debug)]
7475
pub struct TraversalProjection {
75-
/// Distance from the start of the curve of the traversal
76+
/// Distance from the start of the [`Curve`] to the [`Traversal`].
7677
pub distance_from_start: CurvePosition,
77-
/// How far from the traversal is the point has been projected
78+
/// How far from the [`Traversal`] is the [`Point`] that has been projected.
7879
pub orthogonal_offset: f64,
79-
/// identifies the traversal
80+
/// Identifies the [`Traversal`].
8081
pub traversal: TraversalHandle,
8182
}
8283

83-
/// Identifies a position on a traversal
84+
/// Identifies a position on a [`Traversal`].
8485
#[derive(Clone, Copy, Debug)]
8586
pub struct TraversalPosition {
86-
/// Distance from the start of the curve of the traversal
87+
/// Distance from the start of the [`Curve`] to the [`Traversal`].
8788
pub distance_from_start: CurvePosition,
88-
/// Identifies the traversal
89+
/// Identifies the [`Traversal`].
8990
pub traversal: TraversalHandle,
9091
}
9192

@@ -98,34 +99,36 @@ impl From<TraversalPosition> for CurveProjection {
9899
}
99100
}
100101

101-
/// A range on a traversal
102-
/// It can be used to identify a speed limit zone
102+
/// Describes an interval (= range) on a [`Traversal`].
103+
/// The borders are [`CurvePosition`]s.
104+
/// It can be used to identify a speed limit zone for instance.
103105
pub struct TraversalRange {
104-
/// Identifies the traversal
106+
/// Identifies the [`Traversal`].
105107
pub traversal: TraversalHandle,
106-
/// Begin of the range
108+
/// Begin of the range.
107109
pub begin: CurvePosition,
108-
/// End of the range
110+
/// End of the range.
109111
pub end: CurvePosition,
110-
/// Direction of the range
112+
/// [`Direction`] of the range.
111113
pub direction: Direction,
112114
}
113115

114-
/// A range on a [LrmScale]
115-
/// It can be used to identify a speed limit zone
116+
/// Describes an interval (= range) on a [`LrmScale`].
117+
/// The borders are [`LrmScaleMeasure`]s.
118+
/// It can be used to identify a speed limit zone for instance.
116119
pub struct LrmRange {
117-
/// Identifies the Lrm
120+
/// Identifies the [`Lrm`].
118121
pub lrm: LrmHandle,
119-
/// Begin of the range
122+
/// Begin of the range.
120123
pub begin: LrmScaleMeasure,
121-
/// End of the range
124+
/// End of the range.
122125
pub end: LrmScaleMeasure,
123-
/// Direction of the range
126+
/// [`Direction`] of the range.
124127
pub direction: Direction,
125128
}
126129

127130
impl<CurveImpl: Curve> Lrs<CurveImpl> {
128-
/// Loads an Lrs from the file system
131+
/// Loads an [`Lrs`] from the file system
129132
pub fn new<P: AsRef<std::path::Path>>(filename: P) -> Result<Self, LrsError> {
130133
use std::io::Read;
131134
let mut f = std::fs::File::open(filename).map_err(|_| LrsError::OpenFileError)?;
@@ -227,97 +230,97 @@ impl<CurveImpl: Curve> Lrs<CurveImpl> {
227230
}
228231
}
229232

230-
/// Errors when manipulating a Lrs
233+
/// Errors when manipulating [`Lrs`].
231234
#[derive(Error, Debug, PartialEq)]
232235
pub enum LrsError {
233-
/// The handle is not valid. Maybe it was build manually or the structure mutated
236+
/// The [`LrmHandle`] is not valid. It might have been built manually or the structure mutated.
234237
#[error("invalid handle")]
235238
InvalidHandle,
236-
/// There was an error when manipulation a curve of the lrs
239+
/// An error occured while manipulating a [`Curve`] of the [`Lrs`].
237240
#[error("curve error")]
238241
CurveError(#[from] CurveError),
239-
/// There was an error when manipulation a lrm scale of the lrs
242+
/// An error occured while manipulating a [`LrmScale`] of the [`Lrs`].
240243
#[error("curve error")]
241244
LrmScaleError(#[from] LrmScaleError),
242-
/// Could not open the LRS source
245+
/// Could not open the LRS file.
243246
#[error("open file error")]
244247
OpenFileError,
245-
/// Could not read the LRS source content
248+
/// Could not read the LRS file.
246249
#[error("read file error")]
247250
ReadFileError,
248-
/// Could not parse the LRS source data
251+
/// Could not parse the LRS file.
249252
#[error("invalid flatbuffer content")]
250253
InvalidArchive,
251254
}
252255

253256
trait LrsBase {
254-
/// Returns the handle (if it exists) of the LRM identified by its id
257+
/// Returns the [`LrmHandle`] (if it exists) of the [`Lrm`] identified by its `lrm_id`.
255258
fn get_lrm(&self, lrm_id: &str) -> Option<LrmHandle>;
256-
/// Returns the handle (if it exists) of the traversal identified by its name
259+
/// Returns the [`TraversalHandle`] (if it exists) of the [`Traversal`] identified by its `traversal_id`.
257260
fn get_traversal(&self, traversal_id: &str) -> Option<TraversalHandle>;
258261

259-
/// Project a point on all traversals applicable to a given lrm
260-
/// The point must be in the bounding box of the curve of the traversal
261-
/// The result is sorted by orthogonal_offset: the lrm nearest to the point is the first item
262+
/// Projects a [`Point`] on all applicable [`Traversal`]s to a given [`Lrm`].
263+
/// The [`Point`] must be in the bounding box of the [`Curve`] of the [`Traversal`].
264+
/// The result is sorted by `orthogonal_offset`: the nearest [`Lrm`] to the [`Point`] is the first item.
262265
fn lookup(&self, point: Point, lrm: LrmHandle) -> Vec<LrmProjection>;
263-
/// Project a point on all LRM where the point is in the bounding box
264-
/// The result is sorted by orthogonal_offset: the lrm nearest to the point is the first item
266+
/// Projects a [`Point`] on all [`Lrm`] where the [`Point`] is in the bounding box.
267+
/// The result is sorted by `orthogonal_offset`: the nearest [`Lrm`] to the [`Point`] is the first item.
265268
fn lookup_lrms(&self, point: Point) -> Vec<LrmProjection>;
266-
/// Project a point on all traversals where the point is in the bounding box
267-
/// The result is sorted by orthogonal_offset: the lrm nearest to the point is the first item
269+
/// Projects a [`Point`] on all [`Traversal`]s where the [`Point`] is in the bounding box.
270+
/// The result is sorted by `orthogonal_offset`: the nearest [`Lrm`] to the [`Point`] is the first item.
268271
fn lookup_traversals(&self, point: Point) -> Vec<TraversalProjection>;
269272

270-
/// Given a traversal position, returns it geographical position
273+
/// Given a [`TraversalPosition`], returns it geographical position ([`Point`]).
271274
fn locate_traversal(&self, position: TraversalPosition) -> Result<Point, LrsError>;
272275

273-
/// And LRM can be used on many traversals
274-
/// For example for both directions of a highway
275-
/// This method returns all traversals that applicable to that traversal
276+
/// And [`Lrm`] can be used on many [`Traversal`]s.
277+
/// For example, for both directions of a highway.
278+
/// This method returns all applicable [`TraversalHandle`]s to that [`Traversal`].
276279
fn get_lrm_applicable_traversals(&self, lrm: LrmHandle) -> &[TraversalHandle];
277-
/// An LRM has a reference traversal
278-
/// It could be the centerline of a highway, or a specific track
279-
/// This methods returns the handle to that traversal
280+
/// An [`Lrm`] has a reference [`Traversal`]
281+
/// For example, for the centerline of a highway, or a specific track.
282+
/// This methods returns the [`TraversalHandle`].
280283
fn get_lrm_reference_traversal(&self, lrm: LrmHandle) -> TraversalHandle;
281284

282-
/// A traversal can be use for multiple LRM
283-
/// A highway could have milestones referenced in miles and kilometers
285+
/// A [`Traversal`] can be use for multiple [`Lrm`]s.
286+
/// For example, a highway could have milestones referenced in `miles` AND `kilometers`.
284287
fn get_traversal_lrms(&self, traversal: TraversalHandle) -> &[LrmHandle];
285288

286-
/// Projects a position on one traversal onto an other traversal
287-
/// e.g. when placing a point on both sides of the highway
289+
/// Projects a [`TraversalPosition`] on a [`Traversal`] onto an other [`Traversal`],
290+
/// e.g. when placing a point on both sides of the highway.
288291
fn traversal_project(
289292
&self,
290293
position: TraversalPosition,
291294
onto: TraversalHandle,
292295
) -> Result<TraversalProjection, LrsError>;
293296

294-
/// Projects a range on one traversal onto an other traversal
295-
/// e.g. when placing a stretch where wild animal cross
297+
/// Projects a [`TraversalRange`] on a [`Traversal`] onto an other [`Traversal`],
298+
/// e.g. when placing a stretch where wild animals cross.
296299
fn traversal_project_range(
297300
&self,
298301
range: TraversalRange,
299302
onto: TraversalHandle,
300303
) -> Result<TraversalRange, LrsError>;
301304

302-
/// Given the position on a traversal, projects that position onto an LRM
305+
/// Given the [`TraversalPosition`] on a [`Traversal`], projects that [`TraversalPosition`] onto an [`Lrm`].
303306
fn lrm_project(
304307
&self,
305308
position: TraversalPosition,
306309
onto: LrmHandle,
307310
) -> Result<LrmProjection, LrsError>;
308311

309-
/// Projects a range on one traversal onto an [LrmScale]
310-
/// e.g. when placing a stretch where wild animal cross
312+
/// Projects a [`TraversalRange`] on a [`Traversal`] onto an [LrmScale],
313+
/// e.g. when placing a stretch where wild animals cross.
311314
fn lrm_project_range(
312315
&self,
313316
range: TraversalRange,
314317
onto: LrmHandle,
315318
) -> Result<LrmRange, LrsError>;
316319

317-
/// Given a position on the LRM, returns the measure
318-
/// It will find the nearest anchor that gives a positive offset
320+
/// Given a [`LrmPosition`], returns its [`LrmMeasure`].
321+
/// It will find the nearest [`Anchor`] that gives a positive `offset`.
319322
fn lrm_get_measure(&self, position: LrmPosition) -> Result<LrmMeasure, LrsError>;
320-
/// Given a measure, returns the position on that LRM
323+
/// Given an [`LrmMeasure`], returns its [`LrmPosition`].
321324
fn lrm_get_position(&self, measure: LrmMeasure) -> Result<LrmPosition, LrsError>;
322325

323326
// TODO

0 commit comments

Comments
 (0)