From 982d64f9a26e1d1862ad478eca506306d3b190d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 29 Dec 2020 16:28:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- System/Snowflake.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/System/Snowflake.php b/System/Snowflake.php index cd19b3fc..5fa15562 100644 --- a/System/Snowflake.php +++ b/System/Snowflake.php @@ -287,6 +287,30 @@ class Snowflake } + /** + * @param $v1 + * @param $v2 + * @return float + */ + public static function distance(array $v1, array $v2): float + { + $maxX = max($v1['x'], $v2['x']); + $minX = min($v1['x'], $v2['x']); + + $maxZ = max($v1['z'], $v2['z']); + $minZ = min($v1['z'], $v2['z']); + + $dx = abs($maxX - $minX); + $dy = abs($maxZ - $minZ); + + $sqrt = sqrt($dx * $dx + $dy * $dy); + if ($sqrt < 0) { + $sqrt = abs($sqrt); + } + return (float)$sqrt; + } + + /** * @param $process */