From 59cfbed9eed3ac89c1e8fef5d7e3ca03fed88946 Mon Sep 17 00:00:00 2001 From: Martin Indra Date: Tue, 10 Oct 2023 23:14:26 +0200 Subject: [PATCH] Change visibilities --- crates/pathing/src/geometry.rs | 1 - crates/pathing/src/graph.rs | 20 ++++++++++---------- crates/pathing/src/interval.rs | 24 ++++++++++++------------ crates/pathing/src/node.rs | 2 +- crates/pathing/src/polyanya.rs | 4 ++-- crates/pathing/src/segmentproj.rs | 13 ++++++------- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/crates/pathing/src/geometry.rs b/crates/pathing/src/geometry.rs index 52d82671..628d8ca4 100644 --- a/crates/pathing/src/geometry.rs +++ b/crates/pathing/src/geometry.rs @@ -46,7 +46,6 @@ impl RayProjection { let ray_perp_dir = ray.dir.perp(&segment_dir); let dir_perp_origin = segment_dir.perp(&origin_diff); - // TODO constant // This is true when the ray is parallel with the segment. let is_parallel = ray_perp_dir.abs() < 0.0001; // This is true when the ray points away from the line given by the diff --git a/crates/pathing/src/graph.rs b/crates/pathing/src/graph.rs index 951aca37..f0099c4c 100644 --- a/crates/pathing/src/graph.rs +++ b/crates/pathing/src/graph.rs @@ -30,12 +30,12 @@ pub struct VisibilityGraph { impl VisibilityGraph { /// Returns a new empty visibility graph. - pub(crate) fn new() -> Self { + pub(super) fn new() -> Self { Self { nodes: Vec::new() } } /// Returns number of nodes in the visibility graph. - pub(crate) fn len(&self) -> usize { + pub(super) fn len(&self) -> usize { self.nodes.len() } @@ -48,7 +48,7 @@ impl VisibilityGraph { /// # Arguments /// /// * `segment` - line segment of the triangle edge. - pub(crate) fn new_node(&mut self, segment: Segment) -> u32 { + pub(super) fn new_node(&mut self, segment: Segment) -> u32 { let id = self.nodes.len().try_into().unwrap(); self.nodes.push(GraphNode::new(segment)); id @@ -71,7 +71,7 @@ impl VisibilityGraph { /// # Panics /// /// Panics if `edge_id` already stores more than two neighbours. - pub(crate) fn add_neighbours( + pub(super) fn add_neighbours( &mut self, edge_id: u32, triangle_id: u32, @@ -85,13 +85,13 @@ impl VisibilityGraph { } /// Returns a geometry of a graph node (triangle edge). - pub(crate) fn segment(&self, edge_id: u32) -> Segment { + pub(super) fn segment(&self, edge_id: u32) -> Segment { let index: usize = edge_id.try_into().unwrap(); self.nodes[index].segment() } /// Returns all neighbors of a graph node (triangle edge). - pub(crate) fn neighbours(&self, edge_id: u32) -> &[Step] { + pub(super) fn neighbours(&self, edge_id: u32) -> &[Step] { let index: usize = edge_id.try_into().unwrap(); self.nodes[index].neighbours() } @@ -138,13 +138,13 @@ impl GraphNode { /// 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 { +pub(super) struct Step { edge_id: u32, triangle_id: u32, } impl Step { - pub(crate) fn new(edge_id: u32, triangle_id: u32) -> Self { + pub(super) fn new(edge_id: u32, triangle_id: u32) -> Self { Self { edge_id, triangle_id, @@ -152,12 +152,12 @@ impl Step { } /// A target edge ID (reached from neighboring edge). - pub(crate) fn edge_id(&self) -> u32 { + pub(super) fn edge_id(&self) -> u32 { self.edge_id } /// ID of the traversed triangle (to reach [`Self::edge_id()`]. - pub(crate) fn triangle_id(&self) -> u32 { + pub(super) fn triangle_id(&self) -> u32 { self.triangle_id } } diff --git a/crates/pathing/src/interval.rs b/crates/pathing/src/interval.rs index 0eab413c..b117033d 100644 --- a/crates/pathing/src/interval.rs +++ b/crates/pathing/src/interval.rs @@ -7,7 +7,7 @@ use parry2d::{ use crate::segmentproj::{ParamPair, SegmentOnSegmentProjection}; #[derive(Clone)] -pub(crate) struct SegmentInterval { +pub(super) struct SegmentInterval { segment: Segment, is_a_corner: bool, is_b_corner: bool, @@ -32,7 +32,7 @@ impl SegmentInterval { /// May panic if projection parameters are not between 0 and 1 (inclusive) /// or if first projection parameter is larger or equal to the second /// projection parameter. - pub(crate) fn from_projection(segment: Segment, projection: ParamPair, edge_id: u32) -> Self { + pub(super) fn from_projection(segment: Segment, projection: ParamPair, edge_id: u32) -> Self { Self::new( projection.apply(segment), projection.includes_corner_a(), @@ -46,7 +46,7 @@ impl SegmentInterval { /// # Panics /// /// May panic if `segment` has zero length. - pub(crate) fn new( + pub(super) fn new( segment: Segment, is_a_corner: bool, is_b_corner: bool, @@ -63,7 +63,7 @@ impl SegmentInterval { /// Returns the corner point of the original edge (see [`Self::edge_id()`]) /// if it corresponds to the endpoint of `self`. - pub(crate) fn a_corner(&self) -> Option> { + pub(super) fn a_corner(&self) -> Option> { if self.is_a_corner { Some(self.segment.a) } else { @@ -73,7 +73,7 @@ impl SegmentInterval { /// Returns the corner point of the original edge (see [`Self::edge_id()`]) /// if it corresponds to the endpoint of `self`. - pub(crate) fn b_corner(&self) -> Option> { + pub(super) fn b_corner(&self) -> Option> { if self.is_b_corner { Some(self.segment.b) } else { @@ -82,21 +82,21 @@ impl SegmentInterval { } /// Returns edge ID of the original edge. - pub(crate) fn edge_id(&self) -> u32 { + pub(super) fn edge_id(&self) -> u32 { self.edge_id } - pub(crate) fn distance_to_point(&self, point: Point) -> f32 { + pub(super) fn distance_to_point(&self, point: Point) -> f32 { self.segment.distance_to_local_point(&point, false) } - pub(crate) fn project_point(&self, point: Point) -> Point { + pub(super) fn project_point(&self, point: Point) -> Point { self.segment.project_local_point(&point, false).point } /// Calculates the cross point of an optimal path from a point `a` to a /// point `b` via the interval. - pub(crate) fn cross(&self, a: Point, b: Point) -> SegmentCross { + pub(super) fn cross(&self, a: Point, b: Point) -> SegmentCross { let ray = Ray::new(a, b - a); let direct_cross = self .segment @@ -126,7 +126,7 @@ impl SegmentInterval { /// * `eye` - projection perspective. /// /// * `target` - self is projected onto this target. - pub(crate) fn project_onto_segment( + pub(super) fn project_onto_segment( &self, eye: Point, target: Segment, @@ -136,7 +136,7 @@ impl SegmentInterval { } #[derive(Clone, Copy)] -pub(crate) enum SegmentCross { +pub(super) enum SegmentCross { /// The crossed line segment intersects with the line segment between the /// points `a` and `b`. Direct(Point), @@ -148,7 +148,7 @@ pub(crate) enum SegmentCross { impl SegmentCross { /// Returns the crossing point. - pub(crate) fn point(&self) -> Point { + pub(super) fn point(&self) -> Point { match self { Self::Direct(point) => *point, Self::Corner(point) => *point, diff --git a/crates/pathing/src/node.rs b/crates/pathing/src/node.rs index c4de3a87..307b506b 100644 --- a/crates/pathing/src/node.rs +++ b/crates/pathing/src/node.rs @@ -97,7 +97,7 @@ impl SearchNode { } } - pub(crate) fn triangle_id(&self) -> u32 { + pub(super) fn triangle_id(&self) -> u32 { self.triangle_id } diff --git a/crates/pathing/src/polyanya.rs b/crates/pathing/src/polyanya.rs index e541efd3..85d563ef 100644 --- a/crates/pathing/src/polyanya.rs +++ b/crates/pathing/src/polyanya.rs @@ -108,7 +108,7 @@ pub(crate) fn find_path( } } -pub(crate) struct PointContext { +pub(super) struct PointContext { point: Point, neighbours: Vec, } @@ -123,7 +123,7 @@ impl PointContext { /// * `neighbours` - steps to all neighboring edges. If the point lies /// on an edge or its end points, the edge should not be included in the /// vector. - pub(crate) fn new(point: Point, neighbours: Vec) -> Self { + pub(super) fn new(point: Point, neighbours: Vec) -> Self { Self { point, neighbours } } diff --git a/crates/pathing/src/segmentproj.rs b/crates/pathing/src/segmentproj.rs index 40334b04..f04bb075 100644 --- a/crates/pathing/src/segmentproj.rs +++ b/crates/pathing/src/segmentproj.rs @@ -1,4 +1,3 @@ -// TODO pub(crate) -> pub(super) use parry2d::{math::Point, query::Ray, shape::Segment}; use crate::geometry::{which_side, RayProjection, Side}; @@ -7,14 +6,14 @@ use crate::geometry::{which_side, RayProjection, Side}; /// of an eye (a point). The projection can be looked at as a shadow cast by /// the one segment onto the other segment with the source of light placed at /// the eye. -pub(crate) struct SegmentOnSegmentProjection { +pub(super) struct SegmentOnSegmentProjection { side_a: Option, middle: Option, side_b: Option, } impl SegmentOnSegmentProjection { - pub(crate) fn construct(eye: Point, source: Segment, target: Segment) -> Self { + pub(super) fn construct(eye: Point, source: Segment, target: Segment) -> Self { let target_length = target.length(); if eye == source.a || eye == source.b { @@ -106,27 +105,27 @@ impl SegmentOnSegmentProjection { /// Non-visible part of the target line segment adjacent to endpoint a. /// This is None when all of target is visible. - pub(crate) fn side_a(&self) -> Option { + pub(super) fn side_a(&self) -> Option { self.side_a } /// Visible part of the target line segment. This is None in None if no /// point of the target line segment is visible (from eye via the source /// line segment). - pub(crate) fn middle(&self) -> Option { + pub(super) fn middle(&self) -> Option { self.middle } /// Non-visible part of the target line segment adjacent to endpoint b. /// This is None when all of target is visible. - pub(crate) fn side_b(&self) -> Option { + pub(super) fn side_b(&self) -> Option { self.side_b } } /// Parameters of a (sub-)segment of a line segment. #[derive(Clone, Copy, Debug, PartialEq)] -pub(crate) struct ParamPair(f32, f32); +pub(super) struct ParamPair(f32, f32); impl ParamPair { /// Round parameters very close to 0 or 1 to exact 0 or 1.