Skip to content

Commit 2ac0195

Browse files
louisgreinerTristramg
authored andcommitted
Curves: fix typo + doc on curves.rs
1 parent 9d5fd7f commit 2ac0195

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

src/curves.rs

+53-53
Original file line numberDiff line numberDiff line change
@@ -9,89 +9,89 @@ use geo::prelude::*;
99
use geo::{coord, Line, LineString, Point, Rect};
1010
use thiserror::Error;
1111

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.
1616
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.
2020
fn new(geom: LineString, max_extent: f64) -> Self;
2121

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.
2727
fn project(&self, point: Point) -> Result<CurveProjection, CurveError>;
2828

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`.
3131
fn resolve(&self, projection: CurveProjection) -> Result<Point, CurveError>;
3232

33-
/// Bounding box of the curve with a buffer of `max_extent`
33+
/// Bounding box of the `Curve` with a buffer of `max_extent`.
3434
fn bbox(&self) -> Rect;
3535

36-
/// The length of the curve
36+
/// The length of the `Curve`.
3737
fn length(&self) -> f64;
3838

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).
4242
fn get_normal(&self, offset: f64) -> Result<(f64, f64), CurveError>;
4343

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.
4747
fn intersect_segment(&self, segment: Line) -> Option<Point>;
4848

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.
5252
fn is_valid(&self) -> bool;
5353

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`.
5555
fn max_extent(&self) -> f64;
5656
}
5757

58-
/// Errors when manipulating the curves
58+
/// Errors when manipulating the [Curve] objects.
5959
#[derive(Error, Debug, PartialEq)]
6060
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.
6262
#[error("the curve geometry is not valid")]
6363
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`).
6565
#[error("the coordinates are not finite")]
6666
NotFiniteCoordinates,
67-
/// A considered point is not on the curve
67+
/// The considered [Point] is not on the [Curve].
6868
#[error("the point is not on the curve")]
6969
NotOnTheCurve,
7070
}
7171

7272
/// 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.
7676
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.
7979
pub start_offset: f64,
8080

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.
8383
pub max_extent: f64,
8484

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.
8787
pub geom: LineString,
8888

8989
length: f64,
9090
}
9191

9292
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.
9595
pub fn new_fragmented(geom: LineString, max_len: f64, max_extent: f64) -> Vec<Self> {
9696
let n = (geom.euclidean_length() / max_len).ceil() as usize;
9797
geom.line_segmentize(n)
@@ -187,17 +187,17 @@ impl Curve for LineStringCurve {
187187
}
188188

189189
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
191191
let point = self.resolve(CurveProjection {
192192
distance_along_curve: offset,
193193
offset: 0.,
194194
})?;
195195

196-
// We find the line where the point is located
196+
// We find the line where the Point is located
197197
// This line will be used to construct the normal:
198198
// - 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
201201
let line = self
202202
.geom
203203
.lines_iter()
@@ -222,16 +222,16 @@ impl Curve for LineStringCurve {
222222
}
223223
}
224224

225-
/// Represents a point in space projected on the curve
225+
/// Represents a [Point] in space projected on the [Curve]
226226
#[derive(Clone, Copy)]
227227
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
231231
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
235235
pub offset: f64,
236236
}
237237

@@ -306,7 +306,7 @@ mod tests {
306306
let segment = Line::new(coord! {x: 10., y: 10.}, coord! {x:20., y: 10.});
307307
assert!(c.intersect_segment(segment).is_none());
308308

309-
// Colinear
309+
// Collinear
310310
let segment = Line::new(coord! {x: 0., y:0.,}, coord! {x: 1., y:0.});
311311
assert!(c.intersect_segment(segment).is_none());
312312

0 commit comments

Comments
 (0)