From b524b841c5e923cf9c85a4ac893ab12ee4e24140 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 14 Oct 2017 11:01:00 +0100 Subject: [PATCH] Reduced duplicated code in AxisAlignedBB->calculateIntercept() --- src/pocketmine/math/AxisAlignedBB.php | 29 ++++++--------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/pocketmine/math/AxisAlignedBB.php b/src/pocketmine/math/AxisAlignedBB.php index d36b9aa5c..8bf49c775 100644 --- a/src/pocketmine/math/AxisAlignedBB.php +++ b/src/pocketmine/math/AxisAlignedBB.php @@ -397,30 +397,13 @@ class AxisAlignedBB{ } $vector = null; + $distance = PHP_INT_MAX; - - if($v1 !== null and ($vector === null or $pos1->distanceSquared($v1) < $pos1->distanceSquared($vector))){ - $vector = $v1; - } - - if($v2 !== null and ($vector === null or $pos1->distanceSquared($v2) < $pos1->distanceSquared($vector))){ - $vector = $v2; - } - - if($v3 !== null and ($vector === null or $pos1->distanceSquared($v3) < $pos1->distanceSquared($vector))){ - $vector = $v3; - } - - if($v4 !== null and ($vector === null or $pos1->distanceSquared($v4) < $pos1->distanceSquared($vector))){ - $vector = $v4; - } - - if($v5 !== null and ($vector === null or $pos1->distanceSquared($v5) < $pos1->distanceSquared($vector))){ - $vector = $v5; - } - - if($v6 !== null and ($vector === null or $pos1->distanceSquared($v6) < $pos1->distanceSquared($vector))){ - $vector = $v6; + foreach([$v1, $v2, $v3, $v4, $v5, $v6] as $v){ + if($v !== null and ($d = $pos1->distanceSquared($v)) < $distance){ + $vector = $v; + $distance = $d; + } } if($vector === null){