Skip to content

Commit 9b624db

Browse files
committed
Moved distance function to core
1 parent fa4f1bb commit 9b624db

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

pumpkin-core/src/math/distance.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use super::vector3::Vector3;
2+
3+
pub fn distance(p1: &Vector3<f64>, p2: &Vector3<f64>) -> f64 {
4+
let dx = p1.x - p2.x;
5+
let dy = p1.y - p2.y;
6+
let dz = p1.z - p2.z;
7+
8+
dz.mul_add(dz, dx.mul_add(dx, dy * dy)).sqrt()
9+
}

pumpkin-core/src/math/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod position;
33
pub mod vector2;
44
pub mod vector3;
55
pub mod voxel_shape;
6+
pub mod distance;
67

78
pub fn wrap_degrees(var: f32) -> f32 {
89
let mut var1 = var % 360.0;

pumpkin/src/server/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use connection_cache::{CachedBranding, CachedStatus};
22
use key_store::KeyStore;
33
use parking_lot::{Mutex, RwLock};
44
use pumpkin_config::BASIC_CONFIG;
5+
use pumpkin_core::math::distance::distance;
56
use pumpkin_core::math::vector3::Vector3;
67
use pumpkin_core::text::TextComponent;
78
use pumpkin_core::GameMode;
@@ -146,13 +147,6 @@ impl Server {
146147
// TODO respect which world the player is in
147148
let world = self.worlds.first()?;
148149

149-
fn distance(p1: &Vector3<f64>, p2: &Vector3<f64>) -> f64 {
150-
let dx = p1.x - p2.x;
151-
let dy = p1.y - p2.y;
152-
let dz = p1.z - p2.z;
153-
dz.mul_add(dz, dx.mul_add(dx, dy * dy)).sqrt()
154-
}
155-
156150
world
157151
.current_players
158152
.lock()

0 commit comments

Comments
 (0)