Skip to content

Commit

Permalink
Improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Indy2222 committed Oct 10, 2023
1 parent f162d50 commit 4539c8c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
7 changes: 5 additions & 2 deletions crates/pathing/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ impl VisibilityGraph {
id
}

/// Add 2 neighbours to a graph node (triangle edge).
/// Adds 2 neighbours accessible via one of the adjacent triangles to a
/// graph node (triangle edge).
///
/// # Arguments
///
Expand Down Expand Up @@ -133,7 +134,9 @@ impl Node {
}
}

/// A step in the triangle edge neighbor graph.
/// A step in the triangle edge neighbor graph. Id est triangle traversal from
/// a set of points in the triangle (one point or a line segment) to (part of)
/// an edge of the triangle.
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq)]
pub(crate) struct Step {
edge_id: u32,
Expand Down
43 changes: 42 additions & 1 deletion crates/pathing/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,29 @@ impl Node {
self.min_distance
}

/// Constructs and returns expansion of self onto a next (adjacent) edge.
///
/// # Arguments
///
/// * `segment` - full line segment of the next edge.
///
/// * `step` - single triangle traversal step.
///
/// * `target` - path searching target point.
///
/// # Panics
///
/// Panics if the last crossed triangle on the path to this node
/// corresponds to the triangle of the next step (i.e. if the expansion
/// goes backwards).
pub(super) fn expand_to_edge(
&self,
segment: Segment,
step: Step,
target: Point<f32>,
) -> [Option<Self>; 3] {
assert!(step.triangle_id() != self.triangle_id);

let Interval::Segment(ref interval) = self.interval else {
panic!("Cannot expand point interval.")
};
Expand Down Expand Up @@ -148,14 +165,32 @@ impl Node {
[node_a, node_mid, node_b]
}

/// Creates a new node whose prefix is equal to the prefix of self with
/// potential addition of `corner` (as the new node root) in the case it
/// differs from root of self.
///
/// # Arguments
///
/// * `step` - the one additional step from self to reach the to be created
/// node.
///
/// * `segment` - line segment corresponding to the full edge directly
/// reached (i.e. via a single triangle) from self.
///
/// * `corner` - last path bend / corner to reach `projection` onto
/// `segment`. Id est root of the to be created node.
///
/// * `projection` - part of the target edge.
///
/// * `target` - searched path target.
fn corner(
&self,
step: Step,
segment: Segment,
corner: Point<f32>,
projection: ParamPair,
target: Point<f32>,
) -> Node {
) -> Self {
let interval = SegmentInterval::from_projection(segment, projection, step.edge_id());
let prefix = if self.root() == corner {
Rc::clone(&self.prefix)
Expand Down Expand Up @@ -185,6 +220,12 @@ impl Node {
})
}

/// Constructs path from the search node.
///
/// The resulting path is a full path from source to target if the node
/// (self) corresponds to the target point. Otherwise, it corresponds to
/// the path from source to the closest point to target in the point set of
/// self (on the nodes line segment).
pub(super) fn close(self, target: Point<f32>) -> Path {
let chain = match self.interval {
Interval::Target => PointChain::extended(&self.prefix, target),
Expand Down

0 comments on commit 4539c8c

Please sign in to comment.