Skip to content

Commit 4dbe1b6

Browse files
Merge pull request #18562 from MoonE/scale-data
Refactor / rename in Gis
2 parents d05bb47 + 4e7d94b commit 4dbe1b6

26 files changed

Lines changed: 936 additions & 854 deletions

libraries/classes/Controllers/GisDataEditorController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public function __invoke(ServerRequest $request): void
5858
$geomType = $gisData['gis_type'];
5959

6060
// Generate parameters from value passed.
61-
$gisObj = GisFactory::factory($geomType);
62-
if ($gisObj === false) {
61+
$gisObj = GisFactory::fromType($geomType);
62+
if ($gisObj === null) {
6363
return;
6464
}
6565

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Gis\Ds;
6+
7+
use function max;
8+
use function min;
9+
10+
use const INF;
11+
12+
class Extent
13+
{
14+
public static function empty(): Extent
15+
{
16+
return new Extent(minX: +INF, minY: +INF, maxX: -INF, maxY: -INF);
17+
}
18+
19+
public function __construct(
20+
public readonly float $minX,
21+
public readonly float $minY,
22+
public readonly float $maxX,
23+
public readonly float $maxY,
24+
) {
25+
}
26+
27+
public function merge(Extent $extent): Extent
28+
{
29+
return new Extent(
30+
minX: min($this->minX, $extent->minX),
31+
minY: min($this->minY, $extent->minY),
32+
maxX: max($this->maxX, $extent->maxX),
33+
maxY: max($this->maxY, $extent->maxY),
34+
);
35+
}
36+
37+
public function isEmpty(): bool
38+
{
39+
return $this->minX > $this->maxX || $this->minY > $this->maxY;
40+
}
41+
}

libraries/classes/Gis/Ds/ScaleData.php

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,13 @@
44

55
namespace PhpMyAdmin\Gis\Ds;
66

7-
use function max;
8-
use function min;
9-
107
class ScaleData
118
{
129
public function __construct(
13-
public readonly float $maxX,
14-
public readonly float $minX,
15-
public readonly float $maxY,
16-
public readonly float $minY,
10+
public readonly float $scale,
11+
public readonly float $offsetX,
12+
public readonly float $offsetY,
13+
public readonly int $height,
1714
) {
1815
}
19-
20-
public function expand(float $x, float $y): ScaleData
21-
{
22-
return new ScaleData(
23-
max($this->maxX, $x),
24-
min($this->minX, $x),
25-
max($this->maxY, $y),
26-
min($this->minY, $y),
27-
);
28-
}
29-
30-
public function merge(ScaleData $scaleData): ScaleData
31-
{
32-
return new ScaleData(
33-
max($this->maxX, $scaleData->maxX),
34-
min($this->minX, $scaleData->minX),
35-
max($this->maxY, $scaleData->maxY),
36-
min($this->minY, $scaleData->minY),
37-
);
38-
}
3916
}

libraries/classes/Gis/GisFactory.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace PhpMyAdmin\Gis;
99

10+
use function mb_strpos;
11+
use function mb_substr;
1012
use function strtoupper;
1113

1214
/**
@@ -19,9 +21,9 @@ class GisFactory
1921
*
2022
* @param string $type type of the geometric object
2123
*
22-
* @return GisGeometry|false the singleton instance of geometric class of the given type
24+
* @return GisGeometry|null the singleton instance of geometric class of the given type
2325
*/
24-
public static function factory(string $type): GisGeometry|false
26+
public static function fromType(string $type): GisGeometry|null
2527
{
2628
return match (strtoupper($type)) {
2729
'MULTIPOLYGON' => GisMultiPolygon::singleton(),
@@ -31,7 +33,22 @@ public static function factory(string $type): GisGeometry|false
3133
'MULTILINESTRING' => GisMultiLineString::singleton(),
3234
'LINESTRING' => GisLineString::singleton(),
3335
'GEOMETRYCOLLECTION' => GisGeometryCollection::singleton(),
34-
default => false,
36+
default => null,
3537
};
3638
}
39+
40+
/**
41+
* Returns the singleton instance of geometric class of the given wkt type.
42+
*/
43+
public static function fromWkt(string $wkt): GisGeometry|null
44+
{
45+
$typePos = mb_strpos($wkt, '(');
46+
if ($typePos === false) {
47+
return null;
48+
}
49+
50+
$type = mb_substr($wkt, 0, $typePos);
51+
52+
return self::fromType($type);
53+
}
3754
}

0 commit comments

Comments
 (0)