diff --git a/README.md b/README.md index 7879610..9115fe0 100644 --- a/README.md +++ b/README.md @@ -31,4 +31,8 @@ Die Werte werden als Hexadecimal Zahlen und in der Webschreibweise zur Verfügun Das Vorgehen der Umwandlung nimmt die Informationen von [Wikipedia - Liste der Farbräume](https://de.wikipedia.org/wiki/Liste_der_Farbr%C3%A4ume) -und [Die Chemie-Schule - HSV-Farbraum](https://www.chemie-schule.de/KnowHow/HSV-Farbraum) auf. \ No newline at end of file +und [Die Chemie-Schule - HSV-Farbraum](https://www.chemie-schule.de/KnowHow/HSV-Farbraum) auf. + +### Transformation natürlicher Modelle + +Die Klassen benötigen natürliche Modelle und geben auch nur solche raus. \ No newline at end of file diff --git a/resources/uml/Klassen-Aufbau.puml b/resources/uml/Klassen-Aufbau.puml index 1884d7a..bf6a6e5 100644 --- a/resources/uml/Klassen-Aufbau.puml +++ b/resources/uml/Klassen-Aufbau.puml @@ -20,19 +20,38 @@ NaturallyColorModels.CyanMagentaYellowKey o-- ColorModels.CyanMagentaYellowKey NaturallyColorModels.HueSaturationValue o-- ColorModels.HueSaturationValue NaturallyColorModels.RedGreenBlue o-- ColorModels.RedGreenBlue - -namespace Transformer { +namespace NaturallyTransformer { interface ColorModelTransformInterface { - + toRedGreenBlue(): RedGreenBlue; - + toCyanMagentaYellowKey(): CyanMagentaYellowKey; - + toHueSaturationValue(): HueSaturationValue; + + toRedGreenBlue(): NaturallyColorModels.RedGreenBlue + + toCyanMagentaYellowKey(): NaturallyColorModels.CyanMagentaYellowKey + + toHueSaturationValue(): NaturallyColorModels.HueSaturationValue } class CyanMagentaYellowKeyTransformer class HueSaturationValueTransformer class RedGreenBlueTransformer - ColorModelTransformInterface <|-- CyanMagentaYellowKeyTransformer - ColorModelTransformInterface <|-- HueSaturationValueTransformer - ColorModelTransformInterface <|-- RedGreenBlueTransformer + + NaturallyTransformer.ColorModelTransformInterface o-- Transformer.ColorModelTransformInterface + + NaturallyTransformer.ColorModelTransformInterface <|-- NaturallyTransformer.CyanMagentaYellowKeyTransformer + NaturallyTransformer.ColorModelTransformInterface <|-- NaturallyTransformer.HueSaturationValueTransformer + NaturallyTransformer.ColorModelTransformInterface <|-- NaturallyTransformer.RedGreenBlueTransformer + NaturallyTransformer.RedGreenBlueTransformer o-- NaturallyColorModels.RedGreenBlue + NaturallyTransformer.CyanMagentaYellowKeyTransformer o-- NaturallyColorModels.CyanMagentaYellowKey + NaturallyTransformer.HueSaturationValueTransformer o-- NaturallyColorModels.HueSaturationValue +} + +namespace Transformer { + interface ColorModelTransformInterface { + + toRedGreenBlue(): ColorModels.RedGreenBlue + + toCyanMagentaYellowKey(): ColorModels.CyanMagentaYellowKey + + toHueSaturationValue(): ColorModels.HueSaturationValue + } + class CyanMagentaYellowKeyTransformer + class HueSaturationValueTransformer + class RedGreenBlueTransformer + Transformer.ColorModelTransformInterface <|-- Transformer.CyanMagentaYellowKeyTransformer + Transformer.ColorModelTransformInterface <|-- Transformer.HueSaturationValueTransformer + Transformer.ColorModelTransformInterface <|-- Transformer.RedGreenBlueTransformer namespace Utilities { abstract AbstractHueSaturationValueToUtility class CyanMagentaYellowKeyToHueSaturationValue diff --git a/src/NaturallyColorModels/CyanMagentaYellowKey.php b/src/NaturallyColorModels/CyanMagentaYellowKey.php index 1df9034..05af337 100644 --- a/src/NaturallyColorModels/CyanMagentaYellowKey.php +++ b/src/NaturallyColorModels/CyanMagentaYellowKey.php @@ -22,6 +22,14 @@ class CyanMagentaYellowKey $this->percentValuesHelper = new Helper\PercentValues(); } + /** + * @return PureCyanMagentaYellowKey + */ + public function getPureColor(): PureCyanMagentaYellowKey + { + return $this->pureColor; + } + /** * @return int */ diff --git a/src/NaturallyColorModels/Helper/GradValues.php b/src/NaturallyColorModels/Helper/GradValues.php index 75e9c0b..a0cdb2f 100644 --- a/src/NaturallyColorModels/Helper/GradValues.php +++ b/src/NaturallyColorModels/Helper/GradValues.php @@ -10,7 +10,7 @@ class GradValues public function asGradValue(float $value): int { - return intval($value * 360); + return intval(round($value * 360, 0, PHP_ROUND_HALF_UP)); } public function fromGradValue(int $value): float diff --git a/src/NaturallyColorModels/Helper/PercentValues.php b/src/NaturallyColorModels/Helper/PercentValues.php index b9350fa..7d3b60b 100644 --- a/src/NaturallyColorModels/Helper/PercentValues.php +++ b/src/NaturallyColorModels/Helper/PercentValues.php @@ -10,7 +10,7 @@ class PercentValues public function asPercentValue(float $value): int { - return intval($value * 100); + return intval(round($value * 100, 0, PHP_ROUND_HALF_UP)); } public function fromPercentValue(int $value): float diff --git a/src/NaturallyColorModels/HueSaturationValue.php b/src/NaturallyColorModels/HueSaturationValue.php index 0870523..6619b41 100644 --- a/src/NaturallyColorModels/HueSaturationValue.php +++ b/src/NaturallyColorModels/HueSaturationValue.php @@ -25,6 +25,14 @@ class HueSaturationValue $this->gradValuesHelper = new Helper\GradValues(); } + /** + * @return PureHueSaturationValue + */ + public function getPureColor(): PureHueSaturationValue + { + return $this->pureColor; + } + /** * @return int */ diff --git a/src/NaturallyColorModels/RedGreenBlue.php b/src/NaturallyColorModels/RedGreenBlue.php index 852b151..2c60e70 100644 --- a/src/NaturallyColorModels/RedGreenBlue.php +++ b/src/NaturallyColorModels/RedGreenBlue.php @@ -21,6 +21,14 @@ class RedGreenBlue $this->hexadecimalValuesHelper = new Helper\HexadecimalValues(); } + /** + * @return PureRedGreenBlue + */ + public function getPureColor(): PureRedGreenBlue + { + return $this->pureColor; + } + /** * @return int */ diff --git a/src/NaturallyTransformer/AbstractNaturallyTransformer.php b/src/NaturallyTransformer/AbstractNaturallyTransformer.php new file mode 100644 index 0000000..4f992e3 --- /dev/null +++ b/src/NaturallyTransformer/AbstractNaturallyTransformer.php @@ -0,0 +1,54 @@ +transformer->toRedGreenBlue(); + $naturally_color = new RedGreenBlue(); + $naturally_color->setRed($hex_helper->asHexadecimalValue($convert_color->getRed())); + $naturally_color->setGreen($hex_helper->asHexadecimalValue($convert_color->getGreen())); + $naturally_color->setBlue($hex_helper->asHexadecimalValue($convert_color->getBlue())); + return $naturally_color; + } + + public function toCyanMagentaYellowKey(): CyanMagentaYellowKey + { + $percent_helper = new PercentValues(); + $convert_color = $this->transformer->toCyanMagentaYellowKey(); + $naturally_color = new CyanMagentaYellowKey(); + $naturally_color->setCyan($percent_helper->asPercentValue($convert_color->getCyan())); + $naturally_color->setYellow($percent_helper->asPercentValue($convert_color->getYellow())); + $naturally_color->setMagenta($percent_helper->asPercentValue($convert_color->getMagenta())); + $naturally_color->setKey($percent_helper->asPercentValue($convert_color->getKey())); + return $naturally_color; + } + + public function toHueSaturationValue(): HueSaturationValue + { + $percent_helper = new PercentValues(); + $grad_helper = new GradValues(); + $convert_color = $this->transformer->toHueSaturationValue(); + $naturally_color = new HueSaturationValue(); + $naturally_color->setHue($grad_helper->asGradValue($convert_color->getHue())); + $naturally_color->setSaturation($percent_helper->asPercentValue($convert_color->getSaturation())); + $naturally_color->setValue($percent_helper->asPercentValue($convert_color->getValue())); + return $naturally_color; + } +} \ No newline at end of file diff --git a/src/NaturallyTransformer/ColorModelTransformInterface.php b/src/NaturallyTransformer/ColorModelTransformInterface.php new file mode 100644 index 0000000..596c38c --- /dev/null +++ b/src/NaturallyTransformer/ColorModelTransformInterface.php @@ -0,0 +1,18 @@ +transformer = new PureTransformer($color->getPureColor()); + } +} \ No newline at end of file diff --git a/src/NaturallyTransformer/HueSaturationValueTransformer.php b/src/NaturallyTransformer/HueSaturationValueTransformer.php new file mode 100644 index 0000000..c029c02 --- /dev/null +++ b/src/NaturallyTransformer/HueSaturationValueTransformer.php @@ -0,0 +1,21 @@ +transformer = new PureTransformer($color->getPureColor()); + } +} \ No newline at end of file diff --git a/src/NaturallyTransformer/RedGreenBlueTransformer.php b/src/NaturallyTransformer/RedGreenBlueTransformer.php new file mode 100644 index 0000000..d84b437 --- /dev/null +++ b/src/NaturallyTransformer/RedGreenBlueTransformer.php @@ -0,0 +1,21 @@ +transformer = new PureTransformer($color->getPureColor()); + } +} \ No newline at end of file diff --git a/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php b/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php index d578fe5..0588376 100644 --- a/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php +++ b/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php @@ -49,7 +49,7 @@ abstract class AbstractHueSaturationValueToUtility * * @return float */ - protected function calcColorValue($reciprocal = false): float + protected function calcColorValue(bool $reciprocal = false): float { // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' $remainder_grad = $this->hueAsPercentGrad % self::INTERVAL; diff --git a/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php b/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php index b4b8f9b..d243770 100644 --- a/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php +++ b/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php @@ -114,7 +114,6 @@ class RedGreenBlueToHueSaturationValue switch ($property) { case self::PROPERTY_RED: - $amount = 0.0; // 0.0 $dividend = $this->green - $this->blu; break; case self::PROPERTY_GREEN: diff --git a/tests/_support/Helper/ValidNaturallyColorValuesProvider.php b/tests/_support/Helper/ValidNaturallyColorValuesProvider.php new file mode 100644 index 0000000..8fc9bb6 --- /dev/null +++ b/tests/_support/Helper/ValidNaturallyColorValuesProvider.php @@ -0,0 +1,128 @@ +[]> + */ + protected array $definitions = [ + 'weiß' => [ + self::CMYK => [ + 'cyan' => 0, + 'magenta' => 0, + 'yellow' => 0, + 'key' => 0, + ], + self::RGB => [ + 'red' => 0xFF, + 'green' => 0xFF, + 'blue' => 0xFF, + ], + self::HSV => [ + 'hue' => 0, + 'saturation' => 0, + 'value' => 100, + ], + ], + 'hellgrau' => [ + self::CMYK => [ + 'cyan' => 0, + 'magenta' => 0, + 'yellow' => 0, + 'key' => 67, + ], + self::RGB => [ + 'red' => 0x55, + 'green' => 0x55, + 'blue' => 0x55, + ], + self::HSV => [ + 'hue' => 0, + 'saturation' => 0, + 'value' => 33, + ], + ], + 'dunkelgrau' => [ + self::CMYK => [ + 'cyan' => 0, + 'magenta' => 0, + 'yellow' => 0, + 'key' => 33, + ], + self::RGB => [ + 'red' => 0xAA, + 'green' => 0xAA, + 'blue' => 0xAA, + ], + self::HSV => [ + 'hue' => 0, + 'saturation' => 0, + 'value' => 67, + ], + ], + 'schwarz' => [ + self::CMYK => [ + 'cyan' => 0, + 'magenta' => 0, + 'yellow' => 0, + 'key' => 100, + ], + self::RGB => [ + 'red' => 0, + 'green' => 0, + 'blue' => 0, + ], + self::HSV => [ + 'hue' => 0, + 'saturation' => 0, + 'value' => 0, + ], + ], + 'aquamarin' => [ + self::CMYK => [ + 'cyan' => 50, + 'magenta' => 0, + 'yellow' => 17, + 'key' => 0, + ], + self::RGB => [ + 'red' => 0x7F, + 'green' => 0xFF, + 'blue' => 0xD4, + ], + self::HSV => [ + 'hue' => 160, + 'saturation' => 50, + 'value' => 100, + ], + ], + ]; + + /** + * @param string $pure_color + * @param string $test_color + * + * @return array[]> + */ + public function getValidColorValues(string $pure_color, string $test_color): array + { + $values = []; + $pure_values = (new ValidColorValuesProvider())->getValidColorValues([$pure_color]); + foreach ($this->definitions as $color => $definition) { + $values[$color] = [ + $pure_values[$color][0], + $definition[$test_color] + ]; + } + return $values; + } +} \ No newline at end of file diff --git a/tests/unit/NaturallyColorModels/CyanMagentaYellowKeyTest.php b/tests/unit/NaturallyColorModels/CyanMagentaYellowKeyTest.php index 5c2a8a5..73fec3b 100644 --- a/tests/unit/NaturallyColorModels/CyanMagentaYellowKeyTest.php +++ b/tests/unit/NaturallyColorModels/CyanMagentaYellowKeyTest.php @@ -125,4 +125,19 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit $this->expectException(InvalidArgumentException::class); $color->setKey($value); } + + public function testGetPureColor(): void + { + $naturally_color = new CyanMagentaYellowKey(); + $naturally_color + ->setCyan(12) + ->setMagenta(28) + ->setYellow(37) + ->setKey(56); + $pure_color = $naturally_color->getPureColor(); + $this->assertEquals(0.12, $pure_color->getCyan()); + $this->assertEquals(0.28, $pure_color->getMagenta()); + $this->assertEquals(0.37, $pure_color->getYellow()); + $this->assertEquals(0.56, $pure_color->getKey()); + } } diff --git a/tests/unit/NaturallyColorModels/HueSaturationValueTest.php b/tests/unit/NaturallyColorModels/HueSaturationValueTest.php index 614e254..f76b4ec 100644 --- a/tests/unit/NaturallyColorModels/HueSaturationValueTest.php +++ b/tests/unit/NaturallyColorModels/HueSaturationValueTest.php @@ -97,4 +97,17 @@ class HueSaturationValueTest extends AbstractColorModelUnit $this->expectException(InvalidArgumentException::class); $color->setValue($value); } + + public function testGetPureColor(): void + { + $naturally_color = new HueSaturationValue(); + $naturally_color + ->setHue(45) + ->setSaturation(28) + ->setValue(56); + $pure_color = $naturally_color->getPureColor(); + $this->assertEquals(0.125, $pure_color->getHue()); + $this->assertEquals(0.28, $pure_color->getSaturation()); + $this->assertEquals(0.56, $pure_color->getValue()); + } } diff --git a/tests/unit/NaturallyColorModels/RedGreenBlueTest.php b/tests/unit/NaturallyColorModels/RedGreenBlueTest.php index f33cb1a..209acc9 100644 --- a/tests/unit/NaturallyColorModels/RedGreenBlueTest.php +++ b/tests/unit/NaturallyColorModels/RedGreenBlueTest.php @@ -106,4 +106,17 @@ class RedGreenBlueTest extends AbstractColorModelUnit $this->assertIsString($html); $this->assertEquals('#A1B2C3', $html); } + + public function testGetPureColor(): void + { + $naturally_color = new RedGreenBlue(); + $naturally_color + ->setRed(0x33) + ->setBlue(0x66) + ->setGreen(0x99); + $pure_color = $naturally_color->getPureColor(); + $this->assertEquals(0.2, $pure_color->getRed()); + $this->assertEquals(0.4, $pure_color->getBlue()); + $this->assertEquals(0.6, $pure_color->getGreen()); + } } diff --git a/tests/unit/NaturallyTransformer/CyanMagentaYellowKeyTransformerTest.php b/tests/unit/NaturallyTransformer/CyanMagentaYellowKeyTransformerTest.php new file mode 100644 index 0000000..835b1db --- /dev/null +++ b/tests/unit/NaturallyTransformer/CyanMagentaYellowKeyTransformerTest.php @@ -0,0 +1,121 @@ +[]> + */ + public function validRgbValuesProvider(): array + { + return (new ValidNaturallyColorValuesProvider())->getValidColorValues( + ValidNaturallyColorValuesProvider::CMYK, + ValidNaturallyColorValuesProvider::RGB + ); + } + + /** + * @return array[]> + */ + public function validHsvValuesProvider(): array + { + return (new ValidNaturallyColorValuesProvider())->getValidColorValues( + ValidNaturallyColorValuesProvider::CMYK, + ValidNaturallyColorValuesProvider::HSV + ); + } + + /** + * @return array[]> + */ + public function validCmykValuesProvider(): array + { + return (new ValidNaturallyColorValuesProvider())->getValidColorValues( + ValidNaturallyColorValuesProvider::CMYK, + ValidNaturallyColorValuesProvider::CMYK + ); + } + + /** + * @param array $pure_color + * @param array $rgb + * + * @dataProvider validRgbValuesProvider + * + * @throws Exception + */ + public function testToRedGreenBlue(array $pure_color, array $rgb): void + { + $this->color = $this->make(CyanMagentaYellowKey::class, [ + 'getPureColor' => $this->make(\TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey::class, $pure_color) + ]); + + $transformer = new CyanMagentaYellowKeyTransformer($this->color); + + $color = $transformer->toRedGreenBlue(); + + $this->assertEquals($rgb['red'], $color->getRed()); + $this->assertEquals($rgb['green'], $color->getGreen()); + $this->assertEquals($rgb['blue'], $color->getBlue()); + + } + + /** + * @param array $pure_color + * @param array $cmyk + * + * @dataProvider validCmykValuesProvider + * + * @throws Exception + */ + public function testToCyanMagentaYellowKey(array $pure_color, array $cmyk): void + { + + $this->color = $this->make(CyanMagentaYellowKey::class, [ + 'getPureColor' => $this->make(\TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey::class, $pure_color) + ]); + + $transformer = new CyanMagentaYellowKeyTransformer($this->color); + + $color = $transformer->toCyanMagentaYellowKey(); + + $this->assertEquals($cmyk['cyan'], $color->getCyan()); + $this->assertEquals($cmyk['magenta'], $color->getMagenta()); + $this->assertEquals($cmyk['yellow'], $color->getYellow()); + $this->assertEquals($cmyk['key'], $color->getKey()); + } + + /** + * @param array $pure_color + * @param array $hsv + * + * @throws Exception + * + * @dataProvider validHsvValuesProvider + * + */ + public function testToHueSaturationValue(array $pure_color, array $hsv): void + { + $this->color = $this->make(CyanMagentaYellowKey::class, [ + 'getPureColor' => $this->make(\TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey::class, $pure_color) + ]); + + $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()); + } +} diff --git a/tests/unit/NaturallyTransformer/HueSaturationValueTransformerTest.php b/tests/unit/NaturallyTransformer/HueSaturationValueTransformerTest.php new file mode 100644 index 0000000..b30a793 --- /dev/null +++ b/tests/unit/NaturallyTransformer/HueSaturationValueTransformerTest.php @@ -0,0 +1,118 @@ +[]> + */ + public function validCmykValuesProvider(): array + { + return (new ValidNaturallyColorValuesProvider())->getValidColorValues( + ValidNaturallyColorValuesProvider::HSV, + ValidNaturallyColorValuesProvider::CMYK, + ); + } + + /** + * @return array[]> + */ + public function validRgbValuesProvider(): array + { + return (new ValidNaturallyColorValuesProvider())->getValidColorValues( + ValidNaturallyColorValuesProvider::HSV, + ValidNaturallyColorValuesProvider::RGB, + ); + } + + /** + * @return array[]> + */ + public function validHsvValuesProvider(): array + { + return (new ValidNaturallyColorValuesProvider())->getValidColorValues( + ValidNaturallyColorValuesProvider::HSV, + ValidNaturallyColorValuesProvider::HSV, + ); + } + + /** + * @param array $pure_color + * @param array $rgb + * + * @dataProvider validRgbValuesProvider + * + * @throws Exception + */ + public function testToRedGreenBlue(array $pure_color, array $rgb): void + { + $this->color = $this->make(HueSaturationValue::class, [ + 'getPureColor' => $this->make(\TorstenHettstedt\Colors\ColorModels\HueSaturationValue::class, $pure_color) + ]); + + $transformer = new HueSaturationValueTransformer($this->color); + + $color = $transformer->toRedGreenBlue(); + + $this->assertEquals($rgb['red'], $color->getRed()); + $this->assertEquals($rgb['green'], $color->getGreen()); + $this->assertEquals($rgb['blue'], $color->getBlue()); + + } + + /** + * @param array $pure_color + * @param array $cmyk + * + * @throws Exception + * @dataProvider validCmykValuesProvider + * + */ + public function testToCyanMagentaYellowKey(array $pure_color, array $cmyk): void + { + $this->color = $this->make(HueSaturationValue::class, [ + 'getPureColor' => $this->make(\TorstenHettstedt\Colors\ColorModels\HueSaturationValue::class, $pure_color) + ]); + + $transformer = new HueSaturationValueTransformer($this->color); + + $color = $transformer->toCyanMagentaYellowKey(); + + $this->assertEquals($cmyk['cyan'], $color->getCyan()); + $this->assertEquals($cmyk['magenta'], $color->getMagenta()); + $this->assertEquals($cmyk['yellow'], $color->getYellow()); + $this->assertEquals($cmyk['key'], $color->getKey()); + } + + /** + * @param array $pure_color + * @param array $hsv + * + * @throws Exception + * @dataProvider validHsvValuesProvider + */ + public function testToHueSaturationValue(array $pure_color, array $hsv): void + { + $this->color = $this->make(HueSaturationValue::class, [ + 'getPureColor' => $this->make(\TorstenHettstedt\Colors\ColorModels\HueSaturationValue::class, $pure_color) + ]); + + $transformer = new HueSaturationValueTransformer($this->color); + + $color = $transformer->toHueSaturationValue(); + + $this->assertEquals($hsv['hue'], $color->getHue()); + $this->assertEquals($hsv['saturation'], $color->getSaturation()); + $this->assertEquals($hsv['value'], $color->getValue()); + } +} diff --git a/tests/unit/NaturallyTransformer/RedGreenBlueTransformerTest.php b/tests/unit/NaturallyTransformer/RedGreenBlueTransformerTest.php new file mode 100644 index 0000000..15f8e9f --- /dev/null +++ b/tests/unit/NaturallyTransformer/RedGreenBlueTransformerTest.php @@ -0,0 +1,118 @@ +[]> + */ + public function validCmykValuesProvider(): array + { + return (new ValidNaturallyColorValuesProvider())->getValidColorValues( + ValidNaturallyColorValuesProvider::RGB, + ValidNaturallyColorValuesProvider::CMYK, + ); + } + + /** + * @return array[]> + */ + public function validHsvValuesProvider(): array + { + return (new ValidNaturallyColorValuesProvider())->getValidColorValues( + ValidNaturallyColorValuesProvider::RGB, + ValidNaturallyColorValuesProvider::HSV, + ); + } + + /** + * @return array[]> + */ + public function validRgbValuesProvider(): array + { + return (new ValidNaturallyColorValuesProvider())->getValidColorValues( + ValidNaturallyColorValuesProvider::RGB, + ValidNaturallyColorValuesProvider::RGB, + ); + } + + /** + * @param array $pure_color + * @param array $rgb + * + * @dataProvider validRgbValuesProvider + * + * @throws Exception + */ + public function testToRedGreenBlue(array $pure_color, array $rgb): void + { + $this->color = $this->make(RedGreenBlue::class, [ + 'getPureColor' => $this->make(\TorstenHettstedt\Colors\ColorModels\RedGreenBlue::class, $pure_color) + ]); + + $transformer = new RedGreenBlueTransformer($this->color); + + $color = $transformer->toRedGreenBlue(); + + $this->assertEquals($rgb['red'], $color->getRed()); + $this->assertEquals($rgb['green'], $color->getGreen()); + $this->assertEquals($rgb['blue'], $color->getBlue()); + + } + + /** + * @param array $pure_color + * @param array $cmyk + * + * @throws Exception + * @dataProvider validCmykValuesProvider + * + */ + public function testToCyanMagentaYellowKey(array $pure_color, array $cmyk): void + { + $this->color = $this->make(RedGreenBlue::class, [ + 'getPureColor' => $this->make(\TorstenHettstedt\Colors\ColorModels\RedGreenBlue::class, $pure_color) + ]); + + $transformer = new RedGreenBlueTransformer($this->color); + + $color = $transformer->toCyanMagentaYellowKey(); + + $this->assertEquals($cmyk['cyan'], $color->getCyan()); + $this->assertEquals($cmyk['magenta'], $color->getMagenta()); + $this->assertEquals($cmyk['yellow'], $color->getYellow()); + $this->assertEquals($cmyk['key'], $color->getKey()); + } + + /** + * @param array $pure_color + * @param array $hsv + * + * @throws Exception + * @dataProvider validHsvValuesProvider + */ + public function testToHueSaturationValue(array $pure_color, array $hsv): void + { + $this->color = $this->make(RedGreenBlue::class, [ + 'getPureColor' => $this->make(\TorstenHettstedt\Colors\ColorModels\RedGreenBlue::class, $pure_color) + ]); + + $transformer = new RedGreenBlueTransformer($this->color); + + $color = $transformer->toHueSaturationValue(); + + $this->assertEquals($hsv['hue'], $color->getHue()); + $this->assertEquals($hsv['saturation'], $color->getSaturation()); + $this->assertEquals($hsv['value'], $color->getValue()); + } +}