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

Commit e51ca77

Browse files
committed
replaces \d in with [+-]?([0-9]+([.][0-9]*)?|[.][0-9]+) to support floating point values
1 parent 7cf7e58 commit e51ca77

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Geometries/MultiPoint.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public static function fromString($wktArgument)
4545
{
4646
if (!strpos(trim($wktArgument), '(')) {
4747
$points = explode(',', $wktArgument);
48-
$wktArgument = implode(", ", array_map(function ($pair) {
48+
$wktArgument = implode(',', array_map(function ($pair) {
4949
return '(' . trim($pair) . ')';
5050
}, $points));
5151
};
5252

5353
$matches = [];
54-
preg_match_all('/\(\s*(\d+\s+\d+(\s+\d+)?)\s*\)/', trim($wktArgument), $matches);
54+
preg_match_all('/\(\s*([+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)+\s+[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)+(\s+[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)+)?)\s*\)/', trim($wktArgument), $matches);
5555

5656
if (count($matches) < 2) {
5757
return new static([]);

tests/Geometries/MultiPointTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ public function testFromWKT()
1616
$this->assertEquals(3, $multipoint->count());
1717
}
1818

19+
public function testFromWKTWithFloatingPoint()
20+
{
21+
$multipoint = MultiPoint::fromWKT('MULTIPOINT((1.0 1.0),(2.0 1.0),(2.0 2.0))');
22+
$this->assertInstanceOf(MultiPoint::class, $multipoint);
23+
24+
$this->assertEquals(3, $multipoint->count());
25+
}
26+
1927
public function testFromWKTWithoutNestedParentesis()
2028
{
2129
$multipoint = MultiPoint::fromWKT('MULTIPOINT(1 1, 2 1, 2 2)');

0 commit comments

Comments
 (0)