pub struct Delta {
pub dx: i32,
pub dy: i32,
}
Expand description
§Delta
A Delta
represents a signed 2D offset — a difference in position, movement, or translation across a grid.
It is typically used to describe relative shifts between Coordinates
, direction-based motion, or area translation.
§Example
use rpgx::prelude::*;
let d1 = Delta::new(3, -2);
let d2 = Delta::new(-1, 1);
let combined = d1 + d2; // Delta { dx: 2, dy: -1 }
§Fields
§dx: i32
The horizontal delta (positive is rightward, negative is leftward).
§dy: i32
The vertical delta (positive is downward, negative is upward).
§Constructors
§Delta::new(dx: i32, dy: i32) -> Self
Creates a new delta with the specified components.
use rpgx::prelude::*;
let d = Delta::new(2, -1);
§Delta::zero() -> Self
Returns a delta representing no movement: (0, 0)
.
§Methods
§fn invert(self) -> Self
Returns a new delta with inverted components (-dx
, -dy
).
§fn is_zero(self) -> bool
Returns true
if both components are zero.
§fn manhattan(self) -> u32
Computes the Manhattan distance, i.e., the sum of absolute values of dx
and dy
.
use rpgx::prelude::*;
let d = Delta::new(-2, 3);
assert_eq!(d.manhattan(), 5);
§fn is_axis_aligned(self) -> bool
Returns true
if the delta moves only in one direction (either horizontal or vertical).
§fn is_diagonal(self) -> bool
Returns true
if both dx
and dy
are nonzero, i.e., the movement is diagonal.
§Design Notes
Delta
is signed and supports flexible offsetting in all directions.- Used heavily in coordinate math, pathfinding, area translation, and movement logic.
- Use
Coordinates::offseted()
ortry_offseted()
to apply deltas to unsigned positions.
§See Also
Coordinates
: Grid position values.Shape
: Region dimensions.Rect
: Rectangular areas of the grid.Layer
,Map
Represents a 2D movement or directional offset with signed deltas.
Fields§
§dx: i32
§dy: i32
Implementations§
Source§impl Delta
Utilities
impl Delta
Utilities
Sourcepub fn is_axis_aligned(self) -> bool
pub fn is_axis_aligned(self) -> bool
Returns true if the delta moves in only one axis.
Sourcepub fn is_diagonal(self) -> bool
pub fn is_diagonal(self) -> bool
Returns true if this delta is diagonal (nonzero dx and dy).
Trait Implementations§
Source§impl Add<Delta> for Coordinates
impl Add<Delta> for Coordinates
Source§impl AddAssign for Delta
impl AddAssign for Delta
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl Sub<Delta> for Coordinates
impl Sub<Delta> for Coordinates
Source§impl SubAssign for Delta
impl SubAssign for Delta
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read moreimpl Copy for Delta
impl Eq for Delta
impl StructuralPartialEq for Delta
Auto Trait Implementations§
impl Freeze for Delta
impl RefUnwindSafe for Delta
impl Send for Delta
impl Sync for Delta
impl Unpin for Delta
impl UnwindSafe for Delta
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.