Parcourir la source

:octocat: clamp SVG circle radius

smiley il y a 3 ans
Parent
commit
0e2eb33af8
2 fichiers modifiés avec 27 ajouts et 0 suppressions
  1. 7 0
      src/QROptionsTrait.php
  2. 20 0
      tests/QROptionsTest.php

+ 7 - 0
src/QROptionsTrait.php

@@ -475,4 +475,11 @@ trait QROptionsTrait{
 		$this->logoSpaceStartY = $value === null ? null : $this->clampLogoSpaceValue($value);
 		$this->logoSpaceStartY = $value === null ? null : $this->clampLogoSpaceValue($value);
 	}
 	}
 
 
+	/**
+	 * clamp/set SVG circle radius
+	 */
+	protected function set_circleRadius(float $circleRadius):void{
+		$this->circleRadius = max(0.1, min(0.75, $circleRadius));
+	}
+
 }
 }

+ 20 - 0
tests/QROptionsTest.php

@@ -178,4 +178,24 @@ final class QROptionsTest extends TestCase{
 		$this::assertNull($o->logoSpaceStartY);
 		$this::assertNull($o->logoSpaceStartY);
 	}
 	}
 
 
+	/**
+	 * @return float[][]
+	 */
+	public function circleRadiusProvider():array{
+		return [
+			[0.0, 0.1],
+			[0.5, 0.5],
+			[1.5, 0.75],
+		];
+	}
+
+	/**
+	 * @dataProvider circleRadiusProvider
+	 */
+	public function testClampCircleRadius(float $value, float $expected):void{
+		$o = new QROptions(['circleRadius' => $value]);
+
+		$this::assertSame($expected, $o->circleRadius);
+	}
+
 }
 }