@@ -9,89 +9,89 @@ use geo::prelude::*;
9
9
use geo:: { coord, Line , LineString , Point , Rect } ;
10
10
use thiserror:: Error ;
11
11
12
- /// A curve is the fundamental building block for an LRM
13
- /// It provides basic primitives to locate/project points on it
14
- /// A curve can be part of a larger curve (e.g. for optimisation purpurses and have better bounding boxes)
15
- /// The curve can be implemented
12
+ /// A `Curve` is the fundamental building block for an LRM.
13
+ /// It provides basic primitives to locate/project points on it.
14
+ /// A `Curve` can be part of a larger `Curve` (e.g. for optimisation purposes and to have better bounding boxes).
15
+ /// The `Curve` can be implemented.
16
16
pub trait Curve {
17
- /// Build a new curve from a LineString
18
- /// max_extent is the maximum distance that is considered to be “on the curve”
19
- /// max_extent plays a role in the bounding box
17
+ /// Builds a new `Curve` from a [ LineString].
18
+ /// ` max_extent` is the maximum distance that is considered to be “on the curve”.
19
+ /// ` max_extent` plays a role in the bounding box.
20
20
fn new ( geom : LineString , max_extent : f64 ) -> Self ;
21
21
22
- /// Project the point to the closest position on the curve
23
- /// Will fail if the curve is invalid (e.g. no points on it)
24
- /// or if the point is to far away
25
- /// If the curve is a piece of a larger curve ( start_offset > 0)
26
- /// then the distance_along_curve if from the whole curve , not just the current piece
22
+ /// Projects the [Point] to the closest position on the `Curve`.
23
+ /// Will fail if the `Curve` is invalid (e.g. no `Point` on it)
24
+ /// or if the `Point` is too far away.
25
+ /// If the `Curve` is a piece of a larger `Curve` (` start_offset > 0` )
26
+ /// then the ` distance_along_curve` if from the whole `Curve` , not just the current piece.
27
27
fn project ( & self , point : Point ) -> Result < CurveProjection , CurveError > ;
28
28
29
- /// Returns the geographical position of a point on the curve
30
- /// Will return an error if the CurveProjection is not on this Curve
29
+ /// Returns the geographical position of a [Point] on the `Curve`.
30
+ /// Will return an error if the ` CurveProjection` is not on this ` Curve`.
31
31
fn resolve ( & self , projection : CurveProjection ) -> Result < Point , CurveError > ;
32
32
33
- /// Bounding box of the curve with a buffer of `max_extent`
33
+ /// Bounding box of the `Curve` with a buffer of `max_extent`.
34
34
fn bbox ( & self ) -> Rect ;
35
35
36
- /// The length of the curve
36
+ /// The length of the `Curve`.
37
37
fn length ( & self ) -> f64 ;
38
38
39
- /// Computes the normal at a given offset on the curve
40
- /// Will return an error if the curve is invalid or the offset is outside of the curve
41
- /// Points to the positive side (left)
39
+ /// Computes the normal at a given offset on the `Curve`.
40
+ /// Will return an error if the `Curve` is invalid or the offset is outside of the `Curve`.
41
+ /// Points to the positive side (left).
42
42
fn get_normal ( & self , offset : f64 ) -> Result < ( f64 , f64 ) , CurveError > ;
43
43
44
- /// Returns the point where the curve and the segment intersect
45
- /// If the segment intersects the curve multiple times, an intersection is chosen randomly
46
- /// When the segment is colinear with the curve it is ignored
44
+ /// Returns the [Point] where the `Curve` and the segment intersect.
45
+ /// If the segment intersects the `Curve` multiple times, an intersection is chosen randomly.
46
+ /// When the segment is colinear with the `Curve` it is ignored.
47
47
fn intersect_segment ( & self , segment : Line ) -> Option < Point > ;
48
48
49
- /// Is the geometry valid. Depending on the representation
50
- /// It must have at least two coordinates
51
- /// If there are exactly two coordinates, they must be different
49
+ /// Is the geometry valid. Depending on the representation.
50
+ /// It must have at least two coordinates.
51
+ /// If there are exactly two coordinates, they must be different.
52
52
fn is_valid ( & self ) -> bool ;
53
53
54
- /// How far from the curve could be considered to be still on the curve
54
+ /// How far from the `Curve` could be considered to be still on the `Curve`.
55
55
fn max_extent ( & self ) -> f64 ;
56
56
}
57
57
58
- /// Errors when manipulating the curves
58
+ /// Errors when manipulating the [Curve] objects.
59
59
#[ derive( Error , Debug , PartialEq ) ]
60
60
pub enum CurveError {
61
- /// Depeding on the curve implementation the condition of validity might differ
61
+ /// The condition of validity might differ depending on the [Curve] implementation.
62
62
#[ error( "the curve geometry is not valid" ) ]
63
63
InvalidGeometry ,
64
- /// At least a coordinate is non a finite number (NaN, inifinite)
64
+ /// At least one coordinate is non a finite number (` NaN`, `infinite`).
65
65
#[ error( "the coordinates are not finite" ) ]
66
66
NotFiniteCoordinates ,
67
- /// A considered point is not on the curve
67
+ /// The considered [Point] is not on the [Curve].
68
68
#[ error( "the point is not on the curve" ) ]
69
69
NotOnTheCurve ,
70
70
}
71
71
72
72
/// Implementation based on [LineString]:
73
- /// the curve is a string of continous [Line]
74
- /// The coordinates are reprensented by f64.
75
- /// That means a precison of about 1_000_000th of a mm for a curve that spans around the Earth
73
+ /// the [Curve] is a string of continous [Line].
74
+ /// The coordinates are reprensented by ` f64` .
75
+ /// That means a precison of about 1_000_000th of a mm for a `Curve` that spans around the Earth.
76
76
pub struct LineStringCurve {
77
- /// When curve might be a piece of a longer curve
78
- /// then the start_offset allows to know how fare along the longer curve we are
77
+ /// When a [Curve] might be a piece of a longer `Curve`
78
+ /// then the ` start_offset` allows to know how fare along the longer `Curve` we are.
79
79
pub start_offset : f64 ,
80
80
81
- /// The max distance that is considered of being part of the curve
82
- /// It is used to compute the bounding box
81
+ /// The max distance that is considered of being part of the [Curve].
82
+ /// It is used to compute the bounding box.
83
83
pub max_extent : f64 ,
84
84
85
- /// The coordinates are considered as being planar
86
- /// All distance and length computations are in units of those coordinates
85
+ /// The coordinates are considered to be planar.
86
+ /// All distance and length calculations are expressed in the same units as coordinates.
87
87
pub geom : LineString ,
88
88
89
89
length : f64 ,
90
90
}
91
91
92
92
impl LineStringCurve {
93
- /// Splits the LineString into smaller curves of at most `max_len` length
94
- /// If the initial geometry is invalid, it returns an empty vector
93
+ /// Splits the [ LineString] into smaller [Curve] objects of at most `max_len` length.
94
+ /// If the initial geometry is invalid, it returns an empty vector.
95
95
pub fn new_fragmented ( geom : LineString , max_len : f64 , max_extent : f64 ) -> Vec < Self > {
96
96
let n = ( geom. euclidean_length ( ) / max_len) . ceil ( ) as usize ;
97
97
geom. line_segmentize ( n)
@@ -187,17 +187,17 @@ impl Curve for LineStringCurve {
187
187
}
188
188
189
189
fn get_normal ( & self , offset : f64 ) -> Result < ( f64 , f64 ) , CurveError > {
190
- // We find the point where the normal is computed
190
+ // We find the Point where the normal is computed
191
191
let point = self . resolve ( CurveProjection {
192
192
distance_along_curve : offset,
193
193
offset : 0. ,
194
194
} ) ?;
195
195
196
- // We find the line where the point is located
196
+ // We find the line where the Point is located
197
197
// This line will be used to construct the normal:
198
198
// - we translate it so that it starts at `0,0`
199
- // - we rotated it by 90°
200
- // - we scale it in order to be a unit vector
199
+ // - we rotate it by 90°
200
+ // - we scale it in order to become a unit vector
201
201
let line = self
202
202
. geom
203
203
. lines_iter ( )
@@ -222,16 +222,16 @@ impl Curve for LineStringCurve {
222
222
}
223
223
}
224
224
225
- /// Represents a point in space projected on the curve
225
+ /// Represents a [Point] in space projected on the [Curve]
226
226
#[ derive( Clone , Copy ) ]
227
227
pub struct CurveProjection {
228
- /// How far from the curve start is located the point
229
- /// If the curve is part of a larger curve, start_offset is strictly positive
230
- /// and the start_offset will be considered
228
+ /// How far from the [Curve] start is located the [Point]
229
+ /// If the `Curve` is part of a larger `Curve`, ` start_offset` is strictly positive
230
+ /// and the ` start_offset` will be considered
231
231
pub distance_along_curve : f64 ,
232
- /// How far is the point from the curve (euclidian distance)
233
- /// It is positive if the point is located on the left of the curve
234
- /// and negative if the point is on the right
232
+ /// How far is the [Point] from the [Curve] (euclidian distance)
233
+ /// It is positive if the `Point` is located on the left of the `Curve`
234
+ /// and negative if the `Point` is on the right
235
235
pub offset : f64 ,
236
236
}
237
237
@@ -306,7 +306,7 @@ mod tests {
306
306
let segment = Line :: new ( coord ! { x: 10. , y: 10. } , coord ! { x: 20. , y: 10. } ) ;
307
307
assert ! ( c. intersect_segment( segment) . is_none( ) ) ;
308
308
309
- // Colinear
309
+ // Collinear
310
310
let segment = Line :: new ( coord ! { x: 0. , y: 0. , } , coord ! { x: 1. , y: 0. } ) ;
311
311
assert ! ( c. intersect_segment( segment) . is_none( ) ) ;
312
312
0 commit comments