Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 79e6906

Browse files
committed
Merge pull request #9 from MetalMatze/feature/point-float
Cast all inputs of point to floats. Closes #8
2 parents 065cb69 + bd32444 commit 79e6906

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/Geometries/Point.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class Point extends Geometry
77

88
public function __construct($lat, $lng)
99
{
10-
$this->lat = $lat;
11-
$this->lng = $lng;
10+
$this->lat = (float)$lat;
11+
$this->lng = (float)$lng;
1212
}
1313

1414
public function getLat()
@@ -18,7 +18,7 @@ public function getLat()
1818

1919
public function setLat($lat)
2020
{
21-
$this->lat = $lat;
21+
$this->lat = (float)$lat;
2222
}
2323

2424
public function getLng()
@@ -28,7 +28,7 @@ public function getLng()
2828

2929
public function setLng($lng)
3030
{
31-
$this->lng = $lng;
31+
$this->lng = (float)$lng;
3232
}
3333

3434
public function toPair()
@@ -40,7 +40,7 @@ public static function fromPair($pair)
4040
{
4141
list($lng, $lat) = explode(' ', trim($pair));
4242

43-
return new static($lat, $lng);
43+
return new static((float)$lat, (float)$lng);
4444
}
4545

4646
public function toWKT()

tests/Geometries/PointTest.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use Phaza\LaravelPostgis\Geometries\Geometry;
43
use Phaza\LaravelPostgis\Geometries\Point;
54

65
class PointTest extends BaseTestCase
@@ -21,10 +20,36 @@ public function testToWKT()
2120
$this->assertEquals('POINT(2 1)', $point->toWKT());
2221
}
2322

24-
public function testToString()
23+
public function testGettersAndSetters()
2524
{
2625
$point = new Point(1, 2);
26+
$this->assertSame(1.0, $point->getLat());
27+
$this->assertSame(2.0, $point->getLng());
28+
29+
$point->setLat('3');
30+
$point->setLng('4');
31+
32+
$this->assertSame(3.0, $point->getLat());
33+
$this->assertSame(4.0, $point->getLng());
34+
}
35+
36+
public function testPair()
37+
{
38+
$point = Point::fromPair('1.5 2');
39+
40+
$this->assertSame(1.5, $point->getLng());
41+
$this->assertSame(2.0, $point->getLat());
42+
43+
$this->assertSame('1.5 2', $point->toPair());
44+
}
45+
46+
public function testToString()
47+
{
48+
$point = Point::fromString('1.3 2');
49+
50+
$this->assertSame(1.3, $point->getLng());
51+
$this->assertSame(2.0, $point->getLat());
2752

28-
$this->assertEquals('2 1', (string)$point);
53+
$this->assertEquals('1.3 2', (string)$point);
2954
}
3055
}

0 commit comments

Comments
 (0)