1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Distance operations for positions in a 2D space.
use crate::;
/// Calculates an _approximate_ [Euclidean][] distance between two positions.
///
/// [Euclidean]: https://en.wikipedia.org/wiki/Euclidean_distance
///
/// ## Examples
///
/// ```rust
/// use ixy::{Pos, ops::distance};
///
/// let a = Pos::new(3, 4);
/// let b = Pos::new(6, 8);
/// assert_eq!(distance::euclidean_approx(a, b), 5);
/// ```
/// Calculates the _squared_ [Euclidean][] distance between two positions.
///
/// [Euclidean]: https://en.wikipedia.org/wiki/Euclidean_distance
///
/// The squared Euclidean distance is the square of the straight-line distance between two points in
/// a 2D space, or `(x₂ - x₁)² + (y₂ - y₁)²`. This is useful for comparing distances without needing
/// to calculate the square root, i.e. when doing a comparison between distances but not using the
/// actual distance value.
///
/// ## Examples
///
/// ```rust
/// use ixy::{Pos, ops::distance};
///
/// let a = Pos::new(3, 4);
/// let b = Pos::new(6, 8);
/// assert_eq!(distance::euclidean_squared(a, b), 25);
/// ```