mirror of
https://github.com/bdelespierre/php-kmeans.git
synced 2025-01-29 10:21:48 +01:00
adding precision parameter on Point::getDistanceWith
This commit is contained in:
parent
81b8ed27b9
commit
18dd78bafe
@ -49,7 +49,7 @@ class Point implements ArrayAccess
|
||||
);
|
||||
}
|
||||
|
||||
public function getDistanceWith(self $point)
|
||||
public function getDistanceWith(self $point, $precise = true)
|
||||
{
|
||||
if ($point->space !== $this->space)
|
||||
throw new LogicException("can only calculate distances from points in the same space");
|
||||
@ -60,13 +60,13 @@ class Point implements ArrayAccess
|
||||
$distance += $difference * $difference;
|
||||
}
|
||||
|
||||
return $distance;
|
||||
return $precise ? sqrt($distance) : $distance;
|
||||
}
|
||||
|
||||
public function getClosest($points)
|
||||
{
|
||||
foreach($points as $point) {
|
||||
$distance = $this->getDistanceWith($point);
|
||||
$distance = $this->getDistanceWith($point, false);
|
||||
|
||||
if (!isset($minDistance)) {
|
||||
$minDistance = $distance;
|
||||
|
Loading…
x
Reference in New Issue
Block a user