Skip to content

Commit

Permalink
Change visibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Indy2222 committed Oct 10, 2023
1 parent d92842c commit 59cfbed
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
1 change: 0 additions & 1 deletion crates/pathing/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions crates/pathing/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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()
}
Expand Down Expand Up @@ -138,26 +138,26 @@ 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,
}
}

/// 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
}
}
Expand Down
24 changes: 12 additions & 12 deletions crates/pathing/src/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand All @@ -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,
Expand All @@ -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<Point<f32>> {
pub(super) fn a_corner(&self) -> Option<Point<f32>> {
if self.is_a_corner {
Some(self.segment.a)
} else {
Expand All @@ -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<Point<f32>> {
pub(super) fn b_corner(&self) -> Option<Point<f32>> {
if self.is_b_corner {
Some(self.segment.b)
} else {
Expand All @@ -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>) -> f32 {
pub(super) fn distance_to_point(&self, point: Point<f32>) -> f32 {
self.segment.distance_to_local_point(&point, false)
}

pub(crate) fn project_point(&self, point: Point<f32>) -> Point<f32> {
pub(super) fn project_point(&self, point: Point<f32>) -> Point<f32> {
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<f32>, b: Point<f32>) -> SegmentCross {
pub(super) fn cross(&self, a: Point<f32>, b: Point<f32>) -> SegmentCross {
let ray = Ray::new(a, b - a);
let direct_cross = self
.segment
Expand Down Expand Up @@ -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<f32>,
target: Segment,
Expand All @@ -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<f32>),
Expand All @@ -148,7 +148,7 @@ pub(crate) enum SegmentCross {

impl SegmentCross {
/// Returns the crossing point.
pub(crate) fn point(&self) -> Point<f32> {
pub(super) fn point(&self) -> Point<f32> {
match self {
Self::Direct(point) => *point,
Self::Corner(point) => *point,
Expand Down
2 changes: 1 addition & 1 deletion crates/pathing/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl SearchNode {
}
}

pub(crate) fn triangle_id(&self) -> u32 {
pub(super) fn triangle_id(&self) -> u32 {
self.triangle_id
}

Expand Down
4 changes: 2 additions & 2 deletions crates/pathing/src/polyanya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub(crate) fn find_path(
}
}

pub(crate) struct PointContext {
pub(super) struct PointContext {
point: Point<f32>,
neighbours: Vec<Step>,
}
Expand All @@ -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<f32>, neighbours: Vec<Step>) -> Self {
pub(super) fn new(point: Point<f32>, neighbours: Vec<Step>) -> Self {
Self { point, neighbours }
}

Expand Down
13 changes: 6 additions & 7 deletions crates/pathing/src/segmentproj.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO pub(crate) -> pub(super)
use parry2d::{math::Point, query::Ray, shape::Segment};

use crate::geometry::{which_side, RayProjection, Side};
Expand All @@ -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<ParamPair>,
middle: Option<ParamPair>,
side_b: Option<ParamPair>,
}

impl SegmentOnSegmentProjection {
pub(crate) fn construct(eye: Point<f32>, source: Segment, target: Segment) -> Self {
pub(super) fn construct(eye: Point<f32>, source: Segment, target: Segment) -> Self {
let target_length = target.length();

if eye == source.a || eye == source.b {
Expand Down Expand Up @@ -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<ParamPair> {
pub(super) fn side_a(&self) -> Option<ParamPair> {
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<ParamPair> {
pub(super) fn middle(&self) -> Option<ParamPair> {
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<ParamPair> {
pub(super) fn side_b(&self) -> Option<ParamPair> {
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.
Expand Down

0 comments on commit 59cfbed

Please sign in to comment.