aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/position.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-11 22:58:41 -0630
committermat <git@matdoes.dev>2025-06-11 22:58:41 -0630
commita2606569bb79867d07a075bcf7b05730e4264d72 (patch)
treefb97fb52aa0c4d7575f6bd5e4e36c2f01c87f942 /azalea-core/src/position.rs
parent89ddd5e85f4f2fb98697df15528df6e07a3ddd07 (diff)
downloadazalea-drasl-a2606569bb79867d07a075bcf7b05730e4264d72.tar.xz
use owned instead of borrowed Vec3 more
Diffstat (limited to 'azalea-core/src/position.rs')
-rw-r--r--azalea-core/src/position.rs57
1 files changed, 20 insertions, 37 deletions
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index d6e67dc2..5a8d3e0c 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -34,7 +34,7 @@ macro_rules! vec3_impl {
/// Get the squared distance from this position to another position.
/// Equivalent to `(self - other).length_squared()`.
#[inline]
- pub fn distance_squared_to(&self, other: &Self) -> $type {
+ pub fn distance_squared_to(self, other: Self) -> $type {
(self - other).length_squared()
}
@@ -44,7 +44,7 @@ macro_rules! vec3_impl {
}
#[inline]
- pub fn horizontal_distance_squared_to(&self, other: &Self) -> $type {
+ pub fn horizontal_distance_squared_to(self, other: Self) -> $type {
(self - other).horizontal_distance_squared()
}
@@ -115,6 +115,23 @@ macro_rules! vec3_impl {
self.x * other.x + self.y * other.y + self.z * other.z
}
+ /// Make a new position with the lower coordinates for each axis.
+ pub fn min(&self, other: Self) -> Self {
+ Self {
+ x: self.x.min(other.x),
+ y: self.x.min(other.y),
+ z: self.x.min(other.z),
+ }
+ }
+ /// Make a new position with the higher coordinates for each axis.
+ pub fn max(&self, other: Self) -> Self {
+ Self {
+ x: self.x.max(other.x),
+ y: self.x.max(other.y),
+ z: self.x.max(other.z),
+ }
+ }
+
/// Replace the Y with 0.
#[inline]
pub fn xz(&self) -> Self {
@@ -298,7 +315,7 @@ impl Vec3 {
/// Get the distance from this position to another position.
/// Equivalent to `(self - other).length()`.
- pub fn distance_to(&self, other: &Self) -> f64 {
+ pub fn distance_to(self, other: Self) -> f64 {
(self - other).length()
}
@@ -382,40 +399,6 @@ impl BlockPos {
(self.x.abs() + self.y.abs() + self.z.abs()) as u32
}
- /// Make a new BlockPos with the lower coordinates for each axis.
- ///
- /// ```
- /// # use azalea_core::position::BlockPos;
- /// assert_eq!(
- /// BlockPos::min(&BlockPos::new(1, 20, 300), &BlockPos::new(50, 40, 30),),
- /// BlockPos::new(1, 20, 30),
- /// );
- /// ```
- pub fn min(&self, other: &Self) -> Self {
- Self {
- x: self.x.min(other.x),
- y: self.y.min(other.y),
- z: self.z.min(other.z),
- }
- }
-
- /// Make a new BlockPos with the higher coordinates for each axis.
- ///
- /// ```
- /// # use azalea_core::position::BlockPos;
- /// assert_eq!(
- /// BlockPos::max(&BlockPos::new(1, 20, 300), &BlockPos::new(50, 40, 30),),
- /// BlockPos::new(50, 40, 300),
- /// );
- /// ```
- pub fn max(&self, other: &Self) -> Self {
- Self {
- x: self.x.max(other.x),
- y: self.y.max(other.y),
- z: self.z.max(other.z),
- }
- }
-
pub fn offset_with_direction(self, direction: Direction) -> Self {
self + direction.normal()
}