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.
2
2
//!
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.
4
4
//!
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.
6
6
7
7
use std:: cmp:: Ordering ;
8
8
@@ -16,15 +16,13 @@ use crate::lrm_scale::{
16
16
use crate :: lrs_generated;
17
17
use geo:: { coord, point, Point } ;
18
18
19
- /// Handle to identify a [LrmScale] within a specific [Lrs]
19
+ /// Used as handle to identify a [` LrmScale` ] within a specific [` Lrs`].
20
20
#[ derive( Copy , Clone , Debug , Eq , Hash , PartialEq ) ]
21
21
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`].
23
23
#[ derive( Copy , Clone , Debug , Eq , Hash , PartialEq ) ]
24
24
pub struct TraversalHandle ( usize ) ;
25
25
26
- /// Todo create struct LRM {scale, traversals, reference_traversal}
27
-
28
26
struct Lrm {
29
27
scale : LrmScale ,
30
28
reference_traversal : TraversalHandle ,
@@ -37,55 +35,56 @@ struct Traversal<CurveImpl: Curve> {
37
35
lrms : Vec < LrmHandle > ,
38
36
}
39
37
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].
41
40
pub struct Lrs < CurveImpl : Curve > {
42
41
lrms : Vec < Lrm > ,
43
42
traversals : Vec < Traversal < CurveImpl > > ,
44
43
}
45
44
46
- /// The result of a projection onto an [LrmScale]
45
+ /// The result of a projection onto an [` LrmScale`].
47
46
pub struct LrmProjection {
48
- /// The measure anchor and offset
47
+ /// Contains ` measure` ([`LrmScaleMeasure`]) and `lrm` ([`LrmHandle`]).
49
48
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.
51
50
pub orthogonal_offset : f64 ,
52
51
}
53
52
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.
55
54
#[ derive( Clone , Copy , Debug ) ]
56
55
pub struct LrmPosition {
57
- /// The distance from that of the scale
56
+ /// The distance from that of the scale.
58
57
pub distance_from_start : ScalePosition ,
59
- /// Identifies the LrmScale
58
+ /// Identifies the [` LrmScale`].
60
59
pub lrm : LrmHandle ,
61
60
}
62
61
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.
64
63
#[ derive( Clone , Debug ) ]
65
64
pub struct LrmMeasure {
66
- /// Anchor and offset to that anchor
65
+ /// Contains `anchor_name` and `scale_offset` ([`ScalePosition`]).
67
66
pub measure : LrmScaleMeasure ,
68
- /// Identifies the LrmScale
67
+ /// Identifies the [` LrmScale`].
69
68
pub lrm : LrmHandle ,
70
69
}
71
70
72
- /// The result of a projection an a Traversal
71
+ /// The result of a projection an a [` Traversal`].
73
72
#[ derive( Clone , Copy , Debug ) ]
74
73
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`].
76
75
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.
78
77
pub orthogonal_offset : f64 ,
79
- /// identifies the traversal
78
+ /// Identifies the [`Traversal`].
80
79
pub traversal : TraversalHandle ,
81
80
}
82
81
83
- /// Identifies a position on a traversal
82
+ /// Identifies a position on a [`Traversal`].
84
83
#[ derive( Clone , Copy , Debug ) ]
85
84
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`].
87
86
pub distance_from_start : CurvePosition ,
88
- /// Identifies the traversal
87
+ /// Identifies the [`Traversal`].
89
88
pub traversal : TraversalHandle ,
90
89
}
91
90
@@ -98,34 +97,36 @@ impl From<TraversalPosition> for CurveProjection {
98
97
}
99
98
}
100
99
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.
103
103
pub struct TraversalRange {
104
- /// Identifies the traversal
104
+ /// Identifies the [`Traversal`].
105
105
pub traversal : TraversalHandle ,
106
- /// Begin of the range
106
+ /// Begin of the range.
107
107
pub begin : CurvePosition ,
108
- /// End of the range
108
+ /// End of the range.
109
109
pub end : CurvePosition ,
110
- /// Direction of the range
110
+ /// [` Direction`] of the range.
111
111
pub direction : Direction ,
112
112
}
113
113
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.
116
117
pub struct LrmRange {
117
- /// Identifies the Lrm
118
+ /// Identifies the [` Lrm`].
118
119
pub lrm : LrmHandle ,
119
- /// Begin of the range
120
+ /// Begin of the range.
120
121
pub begin : LrmScaleMeasure ,
121
- /// End of the range
122
+ /// End of the range.
122
123
pub end : LrmScaleMeasure ,
123
- /// Direction of the range
124
+ /// [` Direction`] of the range.
124
125
pub direction : Direction ,
125
126
}
126
127
127
128
impl < CurveImpl : Curve > Lrs < CurveImpl > {
128
- /// Loads an Lrs from the file system
129
+ /// Loads an [` Lrs`] from the file system
129
130
pub fn new < P : AsRef < std:: path:: Path > > ( filename : P ) -> Result < Self , LrsError > {
130
131
use std:: io:: Read ;
131
132
let mut f = std:: fs:: File :: open ( filename) . map_err ( |_| LrsError :: OpenFileError ) ?;
@@ -227,97 +228,97 @@ impl<CurveImpl: Curve> Lrs<CurveImpl> {
227
228
}
228
229
}
229
230
230
- /// Errors when manipulating a Lrs
231
+ /// Errors when manipulating [` Lrs`].
231
232
#[ derive( Error , Debug , PartialEq ) ]
232
233
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.
234
235
#[ error( "invalid handle" ) ]
235
236
InvalidHandle ,
236
- /// There was an error when manipulation a curve of the lrs
237
+ /// An error occured while manipulating a [`Curve`] of the [`Lrs`].
237
238
#[ error( "curve error" ) ]
238
239
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`].
240
241
#[ error( "curve error" ) ]
241
242
LrmScaleError ( #[ from] LrmScaleError ) ,
242
- /// Could not open the LRS source
243
+ /// Could not open the LRS file.
243
244
#[ error( "open file error" ) ]
244
245
OpenFileError ,
245
- /// Could not read the LRS source content
246
+ /// Could not read the LRS file.
246
247
#[ error( "read file error" ) ]
247
248
ReadFileError ,
248
- /// Could not parse the LRS source data
249
+ /// Could not parse the LRS file.
249
250
#[ error( "invalid flatbuffer content" ) ]
250
251
InvalidArchive ,
251
252
}
252
253
253
254
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`.
255
256
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`.
257
258
fn get_traversal ( & self , traversal_id : & str ) -> Option < TraversalHandle > ;
258
259
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.
262
263
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.
265
266
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.
268
269
fn lookup_traversals ( & self , point : Point ) -> Vec < TraversalProjection > ;
269
270
270
- /// Given a traversal position , returns it geographical position
271
+ /// Given a [`TraversalPosition`] , returns it geographical position ([`Point`]).
271
272
fn locate_traversal ( & self , position : TraversalPosition ) -> Result < Point , LrsError > ;
272
273
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`].
276
277
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`].
280
281
fn get_lrm_reference_traversal ( & self , lrm : LrmHandle ) -> TraversalHandle ;
281
282
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`.
284
285
fn get_traversal_lrms ( & self , traversal : TraversalHandle ) -> & [ LrmHandle ] ;
285
286
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.
288
289
fn traversal_project (
289
290
& self ,
290
291
position : TraversalPosition ,
291
292
onto : TraversalHandle ,
292
293
) -> Result < TraversalProjection , LrsError > ;
293
294
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.
296
297
fn traversal_project_range (
297
298
& self ,
298
299
range : TraversalRange ,
299
300
onto : TraversalHandle ,
300
301
) -> Result < TraversalRange , LrsError > ;
301
302
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`].
303
304
fn lrm_project (
304
305
& self ,
305
306
position : TraversalPosition ,
306
307
onto : LrmHandle ,
307
308
) -> Result < LrmProjection , LrsError > ;
308
309
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.
311
312
fn lrm_project_range (
312
313
& self ,
313
314
range : TraversalRange ,
314
315
onto : LrmHandle ,
315
316
) -> Result < LrmRange , LrsError > ;
316
317
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`.
319
320
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`].
321
322
fn lrm_get_position ( & self , measure : LrmMeasure ) -> Result < LrmPosition , LrsError > ;
322
323
323
324
// TODO
0 commit comments