Skip to content

Commit 1777854

Browse files
louisgreinerTristramg
authored andcommitted
doc: enhance doc + typos
1 parent e2d176e commit 1777854

File tree

1 file changed

+73
-72
lines changed

1 file changed

+73
-72
lines changed

src/lrs.rs

+73-72
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,15 +16,13 @@ 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}
27-
2826
struct Lrm {
2927
scale: LrmScale,
3028
reference_traversal: TraversalHandle,
@@ -37,55 +35,56 @@ struct Traversal<CurveImpl: Curve> {
3735
lrms: Vec<LrmHandle>,
3836
}
3937

40-
/// The Linear Reference System. It must be specified for a given implementation of [Curve], such as [crate::curves::LineStringCurve]
38+
/// The Linear Reference System. It must be specified for a given implementation
39+
/// of [Curve], such as [crate::curves::LineStringCurve].
4140
pub struct Lrs<CurveImpl: Curve> {
4241
lrms: Vec<Lrm>,
4342
traversals: Vec<Traversal<CurveImpl>>,
4443
}
4544

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

54-
/// Identifies a position on an [LrmScale] by distance from start
53+
/// Identifies a [`ScalePosition`] on an [`LrmScale`] by the distance from the start of the scale.
5554
#[derive(Clone, Copy, Debug)]
5655
pub struct LrmPosition {
57-
/// The distance from that of the scale
56+
/// The distance from that of the scale.
5857
pub distance_from_start: ScalePosition,
59-
/// Identifies the LrmScale
58+
/// Identifies the [`LrmScale`].
6059
pub lrm: LrmHandle,
6160
}
6261

63-
/// Identifies a position on an [LrmScale] by distance from an anchor of the scale
62+
/// Identifies a position on an [LrmScale] by distance from an [`Anchor`] of the scale.
6463
#[derive(Clone, Debug)]
6564
pub struct LrmMeasure {
66-
/// Anchor and offset to that anchor
65+
/// Contains `anchor_name` and `scale_offset` ([`ScalePosition`]).
6766
pub measure: LrmScaleMeasure,
68-
/// Identifies the LrmScale
67+
/// Identifies the [`LrmScale`].
6968
pub lrm: LrmHandle,
7069
}
7170

72-
/// The result of a projection an a Traversal
71+
/// The result of a projection an a [`Traversal`].
7372
#[derive(Clone, Copy, Debug)]
7473
pub struct TraversalProjection {
75-
/// Distance from the start of the curve of the traversal
74+
/// Distance from the start of the [`Curve`] to the [`Traversal`].
7675
pub distance_from_start: CurvePosition,
77-
/// How far from the traversal is the point has been projected
76+
/// How far from the [`Traversal`] is the [`Point`] that has been projected.
7877
pub orthogonal_offset: f64,
79-
/// identifies the traversal
78+
/// Identifies the [`Traversal`].
8079
pub traversal: TraversalHandle,
8180
}
8281

83-
/// Identifies a position on a traversal
82+
/// Identifies a position on a [`Traversal`].
8483
#[derive(Clone, Copy, Debug)]
8584
pub struct TraversalPosition {
86-
/// Distance from the start of the curve of the traversal
85+
/// Distance from the start of the [`Curve`] to the [`Traversal`].
8786
pub distance_from_start: CurvePosition,
88-
/// Identifies the traversal
87+
/// Identifies the [`Traversal`].
8988
pub traversal: TraversalHandle,
9089
}
9190

@@ -98,34 +97,36 @@ impl From<TraversalPosition> for CurveProjection {
9897
}
9998
}
10099

101-
/// A range on a traversal
102-
/// It can be used to identify a speed limit zone
100+
/// Describes an interval (= range) on a [`Traversal`].
101+
/// The borders are [`CurvePosition`]s.
102+
/// It can be used to identify a speed limit zone for instance.
103103
pub struct TraversalRange {
104-
/// Identifies the traversal
104+
/// Identifies the [`Traversal`].
105105
pub traversal: TraversalHandle,
106-
/// Begin of the range
106+
/// Begin of the range.
107107
pub begin: CurvePosition,
108-
/// End of the range
108+
/// End of the range.
109109
pub end: CurvePosition,
110-
/// Direction of the range
110+
/// [`Direction`] of the range.
111111
pub direction: Direction,
112112
}
113113

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

127128
impl<CurveImpl: Curve> Lrs<CurveImpl> {
128-
/// Loads an Lrs from the file system
129+
/// Loads an [`Lrs`] from the file system
129130
pub fn new<P: AsRef<std::path::Path>>(filename: P) -> Result<Self, LrsError> {
130131
use std::io::Read;
131132
let mut f = std::fs::File::open(filename).map_err(|_| LrsError::OpenFileError)?;
@@ -227,97 +228,97 @@ impl<CurveImpl: Curve> Lrs<CurveImpl> {
227228
}
228229
}
229230

230-
/// Errors when manipulating a Lrs
231+
/// Errors when manipulating [`Lrs`].
231232
#[derive(Error, Debug, PartialEq)]
232233
pub enum LrsError {
233-
/// The handle is not valid. Maybe it was build manually or the structure mutated
234+
/// The [`LrmHandle`] is not valid. It might have been built manually or the structure mutated.
234235
#[error("invalid handle")]
235236
InvalidHandle,
236-
/// There was an error when manipulation a curve of the lrs
237+
/// An error occured while manipulating a [`Curve`] of the [`Lrs`].
237238
#[error("curve error")]
238239
CurveError(#[from] CurveError),
239-
/// There was an error when manipulation a lrm scale of the lrs
240+
/// An error occured while manipulating a [`LrmScale`] of the [`Lrs`].
240241
#[error("curve error")]
241242
LrmScaleError(#[from] LrmScaleError),
242-
/// Could not open the LRS source
243+
/// Could not open the LRS file.
243244
#[error("open file error")]
244245
OpenFileError,
245-
/// Could not read the LRS source content
246+
/// Could not read the LRS file.
246247
#[error("read file error")]
247248
ReadFileError,
248-
/// Could not parse the LRS source data
249+
/// Could not parse the LRS file.
249250
#[error("invalid flatbuffer content")]
250251
InvalidArchive,
251252
}
252253

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

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
260+
/// Projects a [`Point`] on all applicable [`Traversal`]s to a given [`Lrm`].
261+
/// The [`Point`] must be in the bounding box of the [`Curve`] of the [`Traversal`].
262+
/// The result is sorted by `orthogonal_offset`: the nearest [`Lrm`] to the [`Point`] is the first item.
262263
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
264+
/// Projects a [`Point`] on all [`Lrm`] where the [`Point`] is in the bounding box.
265+
/// The result is sorted by `orthogonal_offset`: the nearest [`Lrm`] to the [`Point`] is the first item.
265266
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
267+
/// Projects a [`Point`] on all [`Traversal`]s where the [`Point`] is in the bounding box.
268+
/// The result is sorted by `orthogonal_offset`: the nearest [`Lrm`] to the [`Point`] is the first item.
268269
fn lookup_traversals(&self, point: Point) -> Vec<TraversalProjection>;
269270

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

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
274+
/// And [`Lrm`] can be used on many [`Traversal`]s.
275+
/// For example, for both directions of a highway.
276+
/// This method returns all applicable [`TraversalHandle`]s to that [`Traversal`].
276277
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
278+
/// An [`Lrm`] has a reference [`Traversal`]
279+
/// For example, for the centerline of a highway, or a specific track.
280+
/// This methods returns the [`TraversalHandle`].
280281
fn get_lrm_reference_traversal(&self, lrm: LrmHandle) -> TraversalHandle;
281282

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

286-
/// Projects a position on one traversal onto an other traversal
287-
/// e.g. when placing a point on both sides of the highway
287+
/// Projects a [`TraversalPosition`] on a [`Traversal`] onto an other [`Traversal`],
288+
/// e.g. when placing a point on both sides of the highway.
288289
fn traversal_project(
289290
&self,
290291
position: TraversalPosition,
291292
onto: TraversalHandle,
292293
) -> Result<TraversalProjection, LrsError>;
293294

294-
/// Projects a range on one traversal onto an other traversal
295-
/// e.g. when placing a stretch where wild animal cross
295+
/// Projects a [`TraversalRange`] on a [`Traversal`] onto an other [`Traversal`],
296+
/// e.g. when placing a stretch where wild animals cross.
296297
fn traversal_project_range(
297298
&self,
298299
range: TraversalRange,
299300
onto: TraversalHandle,
300301
) -> Result<TraversalRange, LrsError>;
301302

302-
/// Given the position on a traversal, projects that position onto an LRM
303+
/// Given the [`TraversalPosition`] on a [`Traversal`], projects that [`TraversalPosition`] onto an [`Lrm`].
303304
fn lrm_project(
304305
&self,
305306
position: TraversalPosition,
306307
onto: LrmHandle,
307308
) -> Result<LrmProjection, LrsError>;
308309

309-
/// Projects a range on one traversal onto an [LrmScale]
310-
/// e.g. when placing a stretch where wild animal cross
310+
/// Projects a [`TraversalRange`] on a [`Traversal`] onto an [LrmScale],
311+
/// e.g. when placing a stretch where wild animals cross.
311312
fn lrm_project_range(
312313
&self,
313314
range: TraversalRange,
314315
onto: LrmHandle,
315316
) -> Result<LrmRange, LrsError>;
316317

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

323324
// TODO

0 commit comments

Comments
 (0)