expression
Calculate a displacement between two points
A point describes a location in a coordinate system. A displacement vector describes a change of position. Subtract the starting point from the destination to find the movement. This example uses a Cartesian plane with x pointing right and y pointing up; values are in arbitrary units. The array has two coordinates, not two objects stored in a Vec. Expected result (NOT RUN): [3, -2] Common mistake: Subtracting in the opposite order or confusing a mathematical vector with Rust Vec<T>. Static Rust example; not a verified ByteMind executable assessment.
Formal Syntax & Structure
rust syntaxrust
[end_x - start_x, end_y - start_y]Working Example
Example Snippetrust
fn main() { let start = [2i32, 3]; let end = [5, 1]; let movement = [end[0] - start[0], end[1] - start[1]]; println!("{movement:?}");}