Skip to content

Commit

Permalink
LrmScale: fix typo + doc on comment
Browse files Browse the repository at this point in the history
  • Loading branch information
louisgreiner committed Apr 5, 2024
1 parent 979f393 commit efa0420
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ The schema is described in [schema/lrs.fbs](schema/lrs.fbs). The library is writ

If your contribution changes the schema, you will need to generate the file with flatc. The version must be the release 23.5.26. Do not use a version built from master.

`flatc -o src --rust schema/lrs.fbs`
`flatc -o src --rust schema/lrs.fbs`

## Norms

### Comment convention

See [How to write documentation in Rust](https://doc.rust-lang.org/rustdoc/how-to-write-documentation.html) to keep the code clean and clear (also [this](https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text) for other examples).
18 changes: 9 additions & 9 deletions src/lrm_scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct NamedAnchor {
curve_position: CurvePosition,
}

/// A helper to build a scale by adding consecutives anchors with relative distances
/// A helper to build a scale by adding consecutive anchors with relative distances
/// When having all the anchors and their distances in both scale and real position,
/// it is simpler to directly build the LrmScale from an Vec<Anchor>
/// Using the builder will however ensure that the scale is valid
Expand All @@ -87,14 +87,14 @@ pub struct ScaleBuilder {
}

impl ScaleBuilder {
/// Create a new scale with an initial anchor
/// Creates a new scale with an initial anchor
pub fn new(anchor: Anchor) -> Self {
Self {
anchors: vec![anchor],
}
}

/// Builds a named anchor and adds it to the scale builder
/// Builds a named anchor and add it to the scale builder
/// Distances are relative to previous anchor
pub fn add_named(self, id: &str, scale_dist: ScalePosition, curve_dist: CurvePosition) -> Self {
self.add(Some(id.to_owned()), scale_dist, curve_dist)
Expand Down Expand Up @@ -164,7 +164,7 @@ pub struct LrmScaleMeasure {
}

impl LrmScaleMeasure {
/// Build a new LrmMeasure from an anchor name and the offset on the scale
/// Builds a new LrmMeasure from an anchor name and the offset on the scale
pub fn new(anchor_name: &str, scale_offset: ScalePosition) -> Self {
Self {
anchor_name: anchor_name.to_owned(),
Expand All @@ -173,7 +173,7 @@ impl LrmScaleMeasure {
}
}

/// Represents an a LRM Scale and allows to map [Measure] to a position along a curve
/// Represents an LRM Scale and allows to map [Measure] to a position along a curve
#[derive(PartialEq, Debug)]
pub struct LrmScale {
/// Unique identifier
Expand All @@ -183,7 +183,7 @@ pub struct LrmScale {
}

impl LrmScale {
/// Locates a point along a curve given an anchor and a offset
/// Locates a point along a curve given an anchor and an offset
/// The offset might be negative
pub fn locate_point(&self, measure: &LrmScaleMeasure) -> Result<CurvePosition, LrmScaleError> {
let named_anchor = self
Expand All @@ -207,7 +207,7 @@ impl LrmScale {
&self,
curve_position: CurvePosition,
) -> Result<LrmScaleMeasure, LrmScaleError> {
// First we find the nearest named anchor to the curve
// First, we find the nearest named anchor to the curve
let named_anchor = self
.nearest_named(curve_position)
.ok_or(LrmScaleError::NoAnchorFound)?;
Expand Down Expand Up @@ -247,7 +247,7 @@ impl LrmScale {
.or_else(|| self.iter_named().next())
}

// Find the closest anchor before the anchor having the name `name`
// Finds the closest anchor before the anchor having the name `name`
fn previous_anchor(&self, name: &str) -> Option<&Anchor> {
self.anchors
.iter()
Expand All @@ -256,7 +256,7 @@ impl LrmScale {
.nth(1)
}

// Find the closest anchor after the anchor having the name `name`
// Finds the closest anchor after the anchor having the name `name`
fn next_anchor(&self, name: &str) -> Option<&Anchor> {
self.anchors
.iter()
Expand Down

0 comments on commit efa0420

Please sign in to comment.