[][src]Struct gdnative::api::AStar

pub struct AStar { /* fields omitted */ }

core class AStar inherits Reference (reference counted).

Official documentation

See the documentation of this class in the Godot engine's official documentation.

Memory management

The lifetime of this object is automatically managed through reference counting.

Class hierarchy

AStar inherits methods from:

Safety

All types in the Godot API have "interior mutability" in Rust parlance. To enforce that the official thread-safety guidelines are followed, the typestate pattern is used in the Ref and TRef smart pointers, and the Instance API. The typestate Access in these types tracks whether the access is unique, shared, or exclusive to the current thread. For more information, see the type-level documentation on Ref.

Implementations

impl AStar[src]

pub fn new() -> Ref<AStar, Unique>[src]

Creates a new instance of this object.

This is a reference-counted type. The returned object is automatically managed by Ref.

pub fn add_point(
    &self,
    id: i64,
    position: Vector3D<f32, UnknownUnit>,
    weight_scale: f64
)
[src]

Adds a new point at the given position with the given identifier. The algorithm prefers points with lower [code]weight_scale[/code] to form a path. The [code]id[/code] must be 0 or larger, and the [code]weight_scale[/code] must be 1 or larger.
				[codeblock]
				var astar = AStar.new()
				astar.add_point(1, Vector3(1, 0, 0), 4) # Adds the point (1, 0, 0) with weight_scale 4 and id 1
				[/codeblock]
				If there already exists a point for the given [code]id[/code], its position and weight scale are updated to the given values.

Default Arguments

  • weight_scale - 1.0

pub fn are_points_connected(
    &self,
    id: i64,
    to_id: i64,
    bidirectional: bool
) -> bool
[src]

Returns whether the two given points are directly connected by a segment. If [code]bidirectional[/code] is [code]false[/code], returns whether movement from [code]id[/code] to [code]to_id[/code] is possible through this segment.

Default Arguments

  • bidirectional - true

pub fn clear(&self)[src]

Clears all the points and segments.

pub fn connect_points(&self, id: i64, to_id: i64, bidirectional: bool)[src]

Creates a segment between the given points. If [code]bidirectional[/code] is [code]false[/code], only movement from [code]id[/code] to [code]to_id[/code] is allowed, not the reverse direction.
				[codeblock]
				var astar = AStar.new()
				astar.add_point(1, Vector3(1, 1, 0))
				astar.add_point(2, Vector3(0, 5, 0))
				astar.connect_points(1, 2, false)
				[/codeblock]

Default Arguments

  • bidirectional - true

pub fn disconnect_points(&self, id: i64, to_id: i64, bidirectional: bool)[src]

Deletes the segment between the given points. If [code]bidirectional[/code] is [code]false[/code], only movement from [code]id[/code] to [code]to_id[/code] is prevented, and a unidirectional segment possibly remains.

Default Arguments

  • bidirectional - true

pub fn get_available_point_id(&self) -> i64[src]

Returns the next available point ID with no point associated to it.

pub fn get_closest_point(
    &self,
    to_position: Vector3D<f32, UnknownUnit>,
    include_disabled: bool
) -> i64
[src]

Returns the ID of the closest point to [code]to_position[/code], optionally taking disabled points into account. Returns [code]-1[/code] if there are no points in the points pool.
				[b]Note:[/b] If several points are the closest to [code]to_position[/code], the one with the smallest ID will be returned, ensuring a deterministic result.

Default Arguments

  • include_disabled - false

pub fn get_closest_position_in_segment(
    &self,
    to_position: Vector3D<f32, UnknownUnit>
) -> Vector3D<f32, UnknownUnit>
[src]

Returns the closest position to [code]to_position[/code] that resides inside a segment between two connected points.
				[codeblock]
				var astar = AStar.new()
				astar.add_point(1, Vector3(0, 0, 0))
				astar.add_point(2, Vector3(0, 5, 0))
				astar.connect_points(1, 2)
				var res = astar.get_closest_position_in_segment(Vector3(3, 3, 0)) # Returns (0, 3, 0)
				[/codeblock]
				The result is in the segment that goes from [code]y = 0[/code] to [code]y = 5[/code]. It's the closest position in the segment to the given point.

pub fn get_id_path(&self, from_id: i64, to_id: i64) -> TypedArray<i32>[src]

Returns an array with the IDs of the points that form the path found by AStar between the given points. The array is ordered from the starting point to the ending point of the path.
				[codeblock]
				var astar = AStar.new()
				astar.add_point(1, Vector3(0, 0, 0))
				astar.add_point(2, Vector3(0, 1, 0), 1) # Default weight is 1
				astar.add_point(3, Vector3(1, 1, 0))
				astar.add_point(4, Vector3(2, 0, 0))

				astar.connect_points(1, 2, false)
				astar.connect_points(2, 3, false)
				astar.connect_points(4, 3, false)
				astar.connect_points(1, 4, false)

				var res = astar.get_id_path(1, 3) # Returns [1, 2, 3]
				[/codeblock]
				If you change the 2nd point's weight to 3, then the result will be [code][1, 4, 3][/code] instead, because now even though the distance is longer, it's "easier" to get through point 4 than through point 2.

pub fn get_point_capacity(&self) -> i64[src]

Returns the capacity of the structure backing the points, useful in conjunction with [code]reserve_space[/code].

pub fn get_point_connections(&self, id: i64) -> TypedArray<i32>[src]

Returns an array with the IDs of the points that form the connection with the given point.
				[codeblock]
				var astar = AStar.new()
				astar.add_point(1, Vector3(0, 0, 0))
				astar.add_point(2, Vector3(0, 1, 0))
				astar.add_point(3, Vector3(1, 1, 0))
				astar.add_point(4, Vector3(2, 0, 0))

				astar.connect_points(1, 2, true)
				astar.connect_points(1, 3, true)

				var neighbors = astar.get_point_connections(1) # Returns [2, 3]
				[/codeblock]

pub fn get_point_count(&self) -> i64[src]

Returns the number of points currently in the points pool.

pub fn get_point_path(
    &self,
    from_id: i64,
    to_id: i64
) -> TypedArray<Vector3D<f32, UnknownUnit>>
[src]

Returns an array with the points that are in the path found by AStar between the given points. The array is ordered from the starting point to the ending point of the path.

pub fn get_point_position(&self, id: i64) -> Vector3D<f32, UnknownUnit>[src]

Returns the position of the point associated with the given [code]id[/code].

pub fn get_point_weight_scale(&self, id: i64) -> f64[src]

Returns the weight scale of the point associated with the given [code]id[/code].

pub fn get_points(&self) -> VariantArray<Shared>[src]

Returns an array of all points.

pub fn has_point(&self, id: i64) -> bool[src]

Returns whether a point associated with the given [code]id[/code] exists.

pub fn is_point_disabled(&self, id: i64) -> bool[src]

Returns whether a point is disabled or not for pathfinding. By default, all points are enabled.

pub fn remove_point(&self, id: i64)[src]

Removes the point associated with the given [code]id[/code] from the points pool.

pub fn reserve_space(&self, num_nodes: i64)[src]

Reserves space internally for [code]num_nodes[/code] points, useful if you're adding a known large number of points at once, for a grid for instance. New capacity must be greater or equals to old capacity.

pub fn set_point_disabled(&self, id: i64, disabled: bool)[src]

Disables or enables the specified point for pathfinding. Useful for making a temporary obstacle.

Default Arguments

  • disabled - true

pub fn set_point_position(&self, id: i64, position: Vector3D<f32, UnknownUnit>)[src]

Sets the [code]position[/code] for the point with the given [code]id[/code].

pub fn set_point_weight_scale(&self, id: i64, weight_scale: f64)[src]

Sets the [code]weight_scale[/code] for the point with the given [code]id[/code].

Methods from Deref<Target = Reference>

pub fn init_ref(&self) -> bool[src]

Initializes the internal reference counter. Use this only if you really know what you are doing.
				Returns whether the initialization was successful.

Trait Implementations

impl Debug for AStar[src]

impl Deref for AStar[src]

type Target = Reference

The resulting type after dereferencing.

impl DerefMut for AStar[src]

impl GodotObject for AStar[src]

type RefKind = RefCounted

The memory management kind of this type. This modifies the behavior of the Ref smart pointer. See its type-level documentation for more information. Read more

impl Instanciable for AStar[src]

impl SubClass<Object> for AStar[src]

impl SubClass<Reference> for AStar[src]

Auto Trait Implementations

impl RefUnwindSafe for AStar

impl !Send for AStar

impl !Sync for AStar

impl Unpin for AStar

impl UnwindSafe for AStar

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SubClass<T> for T where
    T: GodotObject
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.