@@ -99,9 +99,10 @@ public function testScaleDataSet(): void
9999 );
100100 self ::assertEquals (
101101 new ScaleData (
102- offsetX: - 45.35714285714286 ,
103- offsetY: 42.85714285714286 ,
102+ offsetX: 95.24999999999999 ,
103+ offsetY: - 540.0 ,
104104 scale: 2.1 ,
105+ width: 600 ,
105106 height: 450 ,
106107 ),
107108 $ dataSet ,
@@ -122,8 +123,9 @@ public function testScaleDataSet(): void
122123 self ::assertEquals (
123124 new ScaleData (
124125 scale: 32.30769230769231 ,
125- offsetX: -2.7857142857142865 ,
126- offsetY: -0.4642857142857143 ,
126+ offsetX: 90.0 ,
127+ offsetY: -435.0 ,
128+ width: 600 ,
127129 height: 450 ,
128130 ),
129131 $ dataSet ,
@@ -307,6 +309,55 @@ public function testModifyQueryMariaDB(): void
307309 );
308310 }
309311
312+ #[DataProvider('providerForTestScale ' )]
313+ public function testScale (ScaleData |null $ expected , array $ data ): void
314+ {
315+ $ vis = GisVisualization::getByData (
316+ $ data ,
317+ new GisVisualizationSettings (width: 200 , height: 150 , spatialColumn: 'wkt ' ),
318+ );
319+ $ scaleData = (new ReflectionClass ($ vis ))->getMethod ('scaleDataSet ' )->invoke (
320+ $ vis ,
321+ array_map (static fn (string $ wkt ): array => ['wkt ' => $ wkt ], $ data ),
322+ );
323+ $ this ->assertEquals ($ expected , $ scaleData );
324+ }
325+
326+ public static function providerForTestScale (): array
327+ {
328+ return [
329+ 'empty ' => [null , []],
330+ 'Point - centered ' => [
331+ new ScaleData (scale: 1.0 , offsetX: 100.0 , offsetY: -75.0 , width: 200 , height: 150 ),
332+ ['POINT(0 0) ' ],
333+ ],
334+ 'Linestring - vertically centered ' => [
335+ new ScaleData (scale: 0.1 , offsetX: 0.0 , offsetY: -76.0 , width: 200 , height: 150 ),
336+ ['LINESTRING(150 10,1850 10) ' ],
337+ ],
338+ 'Polygon - empty space at the top and bottom ' => [
339+ new ScaleData (scale: 17.0 , offsetX: -155.0 , offsetY: -75.0 , width: 200 , height: 150 ),
340+ ['POLYGON((10 -1,20 -1,20 1,10 1,10 -1)) ' ],
341+ ],
342+ 'MultiPoint - horizontally centered ' => [
343+ new ScaleData (scale: 10.0 , offsetX: -99900.0 , offsetY: -135.0 , width: 200 , height: 150 ),
344+ ['MULTIPOINT(10000 0,10000 12) ' ],
345+ ],
346+ 'MultiLineString - fitting exactly ' => [
347+ new ScaleData (scale: 1.0 , offsetX: 0.0 , offsetY: -150.0 , width: 200 , height: 150 ),
348+ ['MULTILINESTRING((15 15,100 100),(185 135,100 50)) ' ],
349+ ],
350+ 'MultiPolygon - fitting exactly ' => [
351+ new ScaleData (scale: 60.0 , offsetX: 40.0 , offsetY: -75.0 , width: 200 , height: 150 ),
352+ ['MULTIPOLYGON(((0 0,1 1,0 1,0 0)),((1 -1,2 -1,2 0,1 -1))) ' ],
353+ ],
354+ 'GeometryCollection - empty space at either side ' => [
355+ new ScaleData (scale: 6.0 , offsetX: 1000.0 , offsetY: -1335.0 , width: 200 , height: 150 ),
356+ ['GEOMETRYCOLLECTION(MULTIPOINT(-149 201,-151 219),LINESTRING(-150 200,-150 220)) ' ],
357+ ],
358+ ];
359+ }
360+
310361 public static function providerTestGisData (): array
311362 {
312363 return [
0 commit comments