diff --git a/src/Transformer/ColorModelTransformInterface.php b/src/Transformer/ColorModelTransformInterface.php index 71fd556..1d50e3b 100644 --- a/src/Transformer/ColorModelTransformInterface.php +++ b/src/Transformer/ColorModelTransformInterface.php @@ -5,6 +5,7 @@ namespace TorstenHettstedt\Colors\Transformer; use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey; +use TorstenHettstedt\Colors\ColorModels\HueSaturationValue; use TorstenHettstedt\Colors\ColorModels\RedGreenBlue; interface ColorModelTransformInterface @@ -12,4 +13,6 @@ interface ColorModelTransformInterface public function toRedGreenBlue(): RedGreenBlue; public function toCyanMagentaYellowKey(): CyanMagentaYellowKey; + + public function toHueSaturationValue(): HueSaturationValue; } \ No newline at end of file diff --git a/tests/unit/Transformer/CyanMagentaYellowKeyTransformerTest.php b/tests/unit/Transformer/CyanMagentaYellowKeyTransformerTest.php index 831888b..2367306 100644 --- a/tests/unit/Transformer/CyanMagentaYellowKeyTransformerTest.php +++ b/tests/unit/Transformer/CyanMagentaYellowKeyTransformerTest.php @@ -112,6 +112,106 @@ class CyanMagentaYellowKeyTransformerTest extends Unit ]; } + /** + * @return float[][][] + */ + public function validHsvValuesProvider(): array + { + return [ + 'weiß' => [ + [ + 'cyan' => 0.0, + 'magenta' => 0.0, + 'yellow' => 0.0, + 'key' => 0.0, + ], + [ + 'hue' => 0.0, + 'saturation' => 0.0, + 'value' => 1.0, + ] + ], + 'schwarz' => [ + [ + 'cyan' => 0.0, + 'magenta' => 0.0, + 'yellow' => 0.0, + 'key' => 1.0, + ], + [ + 'hue' => 0.0, + 'saturation' => 0.0, + 'value' => 0.0, + ] + ], + 'cyan' => [ + [ + 'cyan' => 1.0, + 'magenta' => 0.0, + 'yellow' => 0.0, + 'key' => 0.0, + ], + [ + 'hue' => 0.5, + 'saturation' => 1.0, + 'value' => 1.0, + ] + ], + 'magenta' => [ + [ + 'cyan' => 0.0, + 'magenta' => 1.0, + 'yellow' => 0.0, + 'key' => 0.0, + ], + [ + 'hue' => 0.833, + 'saturation' => 1.0, + 'value' => 1.0, + ] + ], + 'gelb' => [ + [ + 'cyan' => 0.0, + 'magenta' => 0.0, + 'yellow' => 1.0, + 'key' => 0.0, + ], + [ + 'hue' => 0.167, + 'saturation' => 1.0, + 'value' => 1.0, + ] + ], + 'gold' => [ + [ + 'cyan' => 0.0, + 'magenta' => 0.13, + 'yellow' => 0.76, + 'key' => 0.13, + ], + [ + 'hue' => 0.139, + 'saturation' => 0.76, + 'value' => 0.87, + ] + ], + 'violet' => [ + [ + 'cyan' => 0.19, + 'magenta' => 0.32, + 'yellow' => 0.0, + 'key' => 0.29, + ], + [ + 'hue' => 0.733, + 'saturation' => 0.32, + 'value' => 0.71, + ] + ], + ]; + } + /** * @param array $cmyk * @param array $rgb @@ -157,4 +257,26 @@ class CyanMagentaYellowKeyTransformerTest extends Unit $this->assertEquals($cmyk['yellow'], $color->getYellow()); $this->assertEquals($cmyk['key'], $color->getKey()); } + + /** + * @param array $cmyk + * @param array $hsv + * + * @throws Exception + * + * @dataProvider validHsvValuesProvider + * + */ + public function testToHueSaturationValue(array $cmyk, array $hsv) + { + $this->color = $this->make(CyanMagentaYellowKey::class, $cmyk); + + $transformer = new CyanMagentaYellowKeyTransformer($this->color); + + $color = $transformer->toHueSaturationValue(); + + $this->assertEquals($hsv['hue'], $color->getHue()); + $this->assertEquals($hsv['saturation'], $color->getSaturation()); + $this->assertEquals($hsv['value'], $color->getValue()); + } }