Struct Route3

Source
pub struct Route3 { /* private fields */ }
Expand description

Reusable piecewise-linear world-space route. Arc lengths are f64, repeated points are legal, and updates validate the complete input before mutation.

Implementations§

Source§

impl Route3

Source

pub fn new(capacity: usize) -> Result<Route3, NavigationError>

Source

pub fn set(&mut self, points: &[Vec3]) -> Result<(), NavigationError>

Replaces the route with an open polyline, including after set_closed. Invalid input leaves the previous geometry and topology unchanged.

Source

pub fn set_closed(&mut self, points: &[Vec3]) -> Result<(), NavigationError>

Replaces the route with a closed polyline, adding a last-to-first segment without storing another point or consuming capacity. Repeating the first point at the end is also legal. Empty and zero-length loops are legal. Invalid input leaves the previous route unchanged.

Closed distance samples and cursors wrap at the seam and never complete. WaypointFollower retains its finite traversal of the authored vertices. No query, cursor operation or successful replacement allocates.

use ferravex_math::Vec3;
use ferravex_play::navigation::{PathCursor, Route3};
let mut route = Route3::new(4)?;
route.set_closed(&[Vec3::ZERO, Vec3::X * 2., Vec3::new(2., 2., 0.), Vec3::Y * 2.])?;
assert!(route.is_closed());
assert_eq!(route.length(), 8.);
assert_eq!(route.sample(9.)?.unwrap().position, Vec3::X);
let mut cursor = PathCursor::default();
cursor.seek(&route, 7.)?;
assert_eq!(cursor.advance(&route, 2., 1.)?.unwrap().distance, 1.);
route.clear();
assert!(!route.is_closed());
Source

pub fn is_closed(&self) -> bool

Whether samples wrap over a last-to-first segment. See Self::set_closed.

Source

pub fn clear(&mut self)

Source

pub fn points(&self) -> &[Vec3]

Source

pub fn length(&self) -> f64

Source

pub fn sample( &self, travel: f64, ) -> Result<Option<RouteSample>, NavigationError>

Samples a finite nonnegative distance. Open routes clamp at the endpoint; closed routes wrap, with zero-length loops staying at their sole position. Empty routes return None. See Self::set_closed for a loop example.

Source

pub fn sample_progress( &self, progress: f64, ) -> Result<Option<RouteSample>, NavigationError>

Samples a normalized arc fraction in 0..=1; out-of-range and non-finite inputs return InvalidInput, even on an empty route. One is the endpoint for an open route and the start of a closed route.

use ferravex_math::Vec3;
use ferravex_play::navigation::Route3;
let mut route = Route3::new(2)?;
route.set(&[Vec3::ZERO, Vec3::X * 10.])?;
assert_eq!(route.sample_progress(0.25)?.unwrap().position, Vec3::X * 2.5);
assert!(route.sample_progress(1.)?.unwrap().complete);
assert!(route.sample_progress(1.1).is_err());
Source

pub fn project( &self, position: Vec3, ) -> Result<Option<RouteProjection>, NavigationError>

Projects a finite world position onto the entire route in O(point count) time and constant scratch space. Empty routes return None. Calculations use f64, including differences between extreme finite f32 coordinates.

Zero-length segments are skipped. Equal squared distances select the lowest index of a nonzero-length segment, including at corners or intersections. A point-only route returns its first point, zero progress and zero tangent. Projection is global: teleports and nearby branches can change progress discontinuously. It does not infer motion, laps or checkpoint visits.

use ferravex_math::Vec3;
use ferravex_play::navigation::{Route3, RouteProjection};
let mut route = Route3::new(3)?;
route.set(&[Vec3::ZERO, Vec3::ZERO, Vec3::X * 10.])?;
let hit: RouteProjection = route.project(Vec3::new(4., 3., 0.))?.unwrap();
assert_eq!(hit.position, Vec3::X * 4.);
assert_eq!(hit.segment, 1);
assert_eq!(hit.distance, 4.);
assert_eq!(hit.progress, 0.4);
assert_eq!(hit.distance_to_route, 3.);

Auto Trait Implementations§

§

impl Freeze for Route3

§

impl RefUnwindSafe for Route3

§

impl Send for Route3

§

impl Sync for Route3

§

impl Unpin for Route3

§

impl UnwindSafe for Route3

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.