diff options
| author | mat <git@matdoes.dev> | 2023-06-14 23:43:54 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-06-14 23:43:54 -0500 |
| commit | dbfbffac140e722d57a1e18bcaa27b25f839f950 (patch) | |
| tree | 6fd0af00c7e024c6d161ab5624237d7cd44d908f /azalea-core | |
| parent | a514b2c9e57c39ee0a183ce2d539d2cdfc8d2e05 (diff) | |
| download | azalea-drasl-dbfbffac140e722d57a1e18bcaa27b25f839f950.tar.xz | |
Vec3::distance_to and clippy
Diffstat (limited to 'azalea-core')
| -rwxr-xr-x | azalea-core/src/position.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index 766c38d6..6f17ec18 100755 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -131,6 +131,20 @@ pub struct Vec3 { } vec3_impl!(Vec3, f64); +impl Vec3 { + /// Get the distance of this vector to the origin by doing + /// `sqrt(x^2 + y^2 + z^2)`. + pub fn length(&self) -> f64 { + self.x * self.x + self.y * self.y + self.z * self.z + } + + /// Get the squared distance from this position to another position. + /// Equivalent to `(self - other).length()`. + pub fn distance_to(&self, other: &Self) -> f64 { + (self - other).length() + } +} + /// The coordinates of a block in the world. For entities (if the coordinate /// with decimals), use [`Vec3`] instead. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] |
