From dbfbffac140e722d57a1e18bcaa27b25f839f950 Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 14 Jun 2023 23:43:54 -0500 Subject: Vec3::distance_to and clippy --- azalea-core/src/position.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'azalea-core/src') 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)] -- cgit v1.2.3