Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| FeTurbulence | |
100.00% |
14 / 14 |
|
100.00% |
6 / 6 |
11 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| baseFrequency | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
| numOctaves | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| seed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| stitchTiles | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| type | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Svg\Filter; |
| 6 | |
| 7 | /** |
| 8 | * SVG 2 Filter Effects §15.17 — `<feTurbulence>`. Procedurally |
| 9 | * generates a Perlin / fractal noise tile in the primitive |
| 10 | * subregion. Used for organic-looking textures, paper grain, |
| 11 | * surface noise, etc. |
| 12 | * |
| 13 | * baseFrequency: base frequency, one or two values |
| 14 | * numOctaves: positive integer, default 1 |
| 15 | * seed: PRNG seed, default 0 |
| 16 | * stitchTiles: stitch | noStitch (default) |
| 17 | * type: fractalNoise | turbulence (default) |
| 18 | */ |
| 19 | final class FeTurbulence extends FilterPrimitive |
| 20 | { |
| 21 | public function __construct() |
| 22 | { |
| 23 | parent::__construct('feTurbulence'); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @return array{0: float, 1: float} [fx, fy] |
| 28 | */ |
| 29 | public function baseFrequency(): array |
| 30 | { |
| 31 | $raw = trim($this->getAttribute('baseFrequency') ?? ''); |
| 32 | if ($raw === '') { |
| 33 | return [0.0, 0.0]; |
| 34 | } |
| 35 | $parts = preg_split('/[\s,]+/', $raw) ?: []; |
| 36 | $fx = max(0.0, (float) ($parts[0] ?? 0)); |
| 37 | $fy = isset($parts[1]) ? max(0.0, (float) $parts[1]) : $fx; |
| 38 | return [$fx, $fy]; |
| 39 | } |
| 40 | |
| 41 | public function numOctaves(): int |
| 42 | { |
| 43 | return max(1, (int) ($this->getAttribute('numOctaves') ?? 1)); |
| 44 | } |
| 45 | |
| 46 | public function seed(): float |
| 47 | { |
| 48 | return (float) ($this->getAttribute('seed') ?? 0); |
| 49 | } |
| 50 | |
| 51 | public function stitchTiles(): string |
| 52 | { |
| 53 | $v = strtolower($this->getAttribute('stitchTiles') ?? 'nostitch'); |
| 54 | return $v === 'stitch' ? 'stitch' : 'noStitch'; |
| 55 | } |
| 56 | |
| 57 | public function type(): string |
| 58 | { |
| 59 | $v = strtolower($this->getAttribute('type') ?? 'turbulence'); |
| 60 | return $v === 'fractalnoise' ? 'fractalNoise' : 'turbulence'; |
| 61 | } |
| 62 | } |