Skip to content

Commit

Permalink
A couple of quick fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasmullie committed Sep 11, 2023
1 parent e7b1a6e commit 745be10
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
11 changes: 8 additions & 3 deletions src/Clusterer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct(Bounds $bounds)
$this->spanBoundsLat = $bounds->ne->latitude < $bounds->sw->latitude;

$this->bounds = $this->fixBounds($bounds);
$this->createMatrix();
$this->setNumberOfClusters($this->numberOfClusters);
}

/**
Expand Down Expand Up @@ -115,7 +115,12 @@ public function setMinClusterLocations($limit)
*/
public function setNumberOfClusters($number)
{
if (count($this->clusters) || count($this->coordinates)) {
throw new Exception('Sorry, it is not possible to change the number of clusters after you have already added coordinates.');
}

$this->numberOfClusters = $number;
$this->createMatrix();
}

public function addCoordinate(Coordinate $coordinate)
Expand Down Expand Up @@ -246,7 +251,7 @@ protected function fixBounds(Bounds $bounds)

if ($this->spanBoundsLat) {
// workaround for crossover bounds being rounded too aggressively
if ($bounds->sw->latitude === 0) {
if ($bounds->sw->latitude <= 0.0) {
$bounds->sw->latitude += 180;
}

Expand All @@ -256,7 +261,7 @@ protected function fixBounds(Bounds $bounds)
}
if ($this->spanBoundsLng) {
// workaround for crossover bounds being rounded too aggressively
if ($bounds->sw->longitude === 0) {
if ($bounds->sw->longitude <= 0.0) {
$bounds->sw->longitude += 360;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Coordinate.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Coordinate
*/
public function __construct($latitude, $longitude, $data = array())
{
$this->latitude = $latitude;
$this->longitude = $longitude;
$this->latitude = (float) $latitude;
$this->longitude = (float) $longitude;
$this->data = $data;
}
}
10 changes: 5 additions & 5 deletions tests/ClustererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ClustererTest extends CompatTestCase
{
public function dataProvider()
public static function dataProvider()
{
return array(
array(
Expand Down Expand Up @@ -48,7 +48,7 @@ public function testClusterCoordinatesException()
public function testExtraData(Bounds $bounds, $coordinates)
{
$clusterer = new Clusterer($bounds);
$clusterer->setNumberOfClusters(12);
$clusterer->setNumberOfClusters(50);
$clusterer->setMinClusterLocations(3);
$clusterer->setSaveCoordinates(true);

Expand All @@ -72,7 +72,7 @@ public function testExtraData(Bounds $bounds, $coordinates)
public function testClustered(Bounds $bounds, $coordinates)
{
$clusterer = new Clusterer($bounds);
$clusterer->setNumberOfClusters(12);
$clusterer->setNumberOfClusters(50);

// 1 location per cell is enough to form a cluster
$clusterer->setMinClusterLocations(1);
Expand All @@ -97,7 +97,7 @@ public function testClustered(Bounds $bounds, $coordinates)
public function testPartiallyClustered(Bounds $bounds, $coordinates)
{
$clusterer = new Clusterer($bounds);
$clusterer->setNumberOfClusters(12);
$clusterer->setNumberOfClusters(50);

// some coordinates should be clustered, as soon as there's > 1 per
// matrix cell
Expand All @@ -121,7 +121,7 @@ public function testPartiallyClustered(Bounds $bounds, $coordinates)
public function testUnclustered(Bounds $bounds, $coordinates)
{
$clusterer = new Clusterer($bounds);
$clusterer->setNumberOfClusters(12);
$clusterer->setNumberOfClusters(50);

// make sure coordinates aren't clustered!
$clusterer->setMinClusterLocations(99);
Expand Down
4 changes: 2 additions & 2 deletions tests/GeoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class GeoTest extends CompatTestCase
{
public function dataProviderDistance()
public static function dataProviderDistance()
{
return array(
array(
Expand All @@ -30,7 +30,7 @@ public function dataProviderDistance()
);
}

public function dataProviderBounds()
public static function dataProviderBounds()
{
return array(
array(
Expand Down

0 comments on commit 745be10

Please sign in to comment.