Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
36.36% |
4 / 11 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| FeDiffuseLighting | |
36.36% |
4 / 11 |
|
80.00% |
4 / 5 |
24.49 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| lightingColor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| surfaceScale | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| diffuseConstant | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| kernelUnitLength | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Svg\Filter; |
| 6 | |
| 7 | /** |
| 8 | * SVG 2 Filter Effects §15.15 — `<feDiffuseLighting>`. Renders |
| 9 | * a height-map of the input under a Lambertian diffuse-light |
| 10 | * model. Surface "height" comes from the input alpha channel. |
| 11 | * |
| 12 | * The light source comes from one child light-source element |
| 13 | * (`<feDistantLight>`, `<fePointLight>`, or `<feSpotLight>`). |
| 14 | * |
| 15 | * lighting-color: colour of incident light (default white) |
| 16 | * surfaceScale: height-map vertical scale, default 1 |
| 17 | * diffuseConstant: Lambertian coefficient kd, default 1 |
| 18 | * kernelUnitLength: derivative kernel size, default 1 |
| 19 | */ |
| 20 | final class FeDiffuseLighting extends FilterPrimitive |
| 21 | { |
| 22 | public function __construct() |
| 23 | { |
| 24 | parent::__construct('feDiffuseLighting'); |
| 25 | } |
| 26 | |
| 27 | public function lightingColor(): string |
| 28 | { |
| 29 | return $this->getAttribute('lighting-color') ?? 'white'; |
| 30 | } |
| 31 | |
| 32 | public function surfaceScale(): float |
| 33 | { |
| 34 | return (float) ($this->getAttribute('surfaceScale') ?? 1); |
| 35 | } |
| 36 | |
| 37 | public function diffuseConstant(): float |
| 38 | { |
| 39 | return max(0.0, (float) ($this->getAttribute('diffuseConstant') ?? 1)); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @return array{0: float, 1: float}|null |
| 44 | * [dx, dy] kernel sample spacing, or null when unspecified. |
| 45 | */ |
| 46 | public function kernelUnitLength(): ?array |
| 47 | { |
| 48 | $raw = trim($this->getAttribute('kernelUnitLength') ?? ''); |
| 49 | if ($raw === '') { |
| 50 | return null; |
| 51 | } |
| 52 | $parts = preg_split('/[\s,]+/', $raw) ?: []; |
| 53 | $dx = max(0.0, (float) ($parts[0] ?? 1)); |
| 54 | $dy = isset($parts[1]) ? max(0.0, (float) $parts[1]) : $dx; |
| 55 | return [$dx, $dy]; |
| 56 | } |
| 57 | } |