From 03d268030504b44aa5107f9be6f3d4118c5c53cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Wed, 2 Mar 2022 19:02:29 +0100 Subject: [PATCH 1/5] =?UTF-8?q?documentation:=20Die=20nat=C3=BCrlichen=20T?= =?UTF-8?q?ransformations-Klassen=20sind=20in=20ihrer=20Abh=C3=A4ngigkeit?= =?UTF-8?q?=20und=20Darstellung=20definiert=20worden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++++- resources/uml/Klassen-Aufbau.puml | 35 ++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 9 deletions(-) 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 From 92cbb1eb463cf87b366d86812ce995eaf954d56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Wed, 2 Mar 2022 19:29:19 +0100 Subject: [PATCH 2/5] =?UTF-8?q?tests:=20Tests=20f=C3=BCr=20nat=C3=BCrliche?= =?UTF-8?q?n=20Transformations-Klassen=20hinzuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ValidNaturallyColorValuesProvider.php | 128 ++++++++++++++++++ .../CyanMagentaYellowKeyTransformerTest.php | 121 +++++++++++++++++ .../HueSaturationValueTransformerTest.php | 118 ++++++++++++++++ .../RedGreenBlueTransformerTest.php | 118 ++++++++++++++++ 4 files changed, 485 insertions(+) create mode 100644 tests/_support/Helper/ValidNaturallyColorValuesProvider.php create mode 100644 tests/unit/NaturallyTransformer/CyanMagentaYellowKeyTransformerTest.php create mode 100644 tests/unit/NaturallyTransformer/HueSaturationValueTransformerTest.php create mode 100644 tests/unit/NaturallyTransformer/RedGreenBlueTransformerTest.php 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/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()); + } +} From 5941c17a8a933fe4332cff6721938fad6133c24d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Thu, 3 Mar 2022 15:08:01 +0100 Subject: [PATCH 3/5] =?UTF-8?q?tests:=20Tests=20f=C3=BCr=20die=20Ausgabe?= =?UTF-8?q?=20der=20puren=20Modell-Klasse=20hinzuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CyanMagentaYellowKeyTest.php | 15 +++++++++++++++ .../HueSaturationValueTest.php | 13 +++++++++++++ .../NaturallyColorModels/RedGreenBlueTest.php | 13 +++++++++++++ 3 files changed, 41 insertions(+) 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()); + } } From 49ef3b83f6fc52d096cc87fba9add98b01752628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Thu, 3 Mar 2022 15:09:09 +0100 Subject: [PATCH 4/5] =?UTF-8?q?feature:=20nat=C3=BCrliche=20Modellklassen?= =?UTF-8?q?=20k=C3=B6nnen=20in=20andere=20Farbsysteme=20transformiert=20we?= =?UTF-8?q?rden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CyanMagentaYellowKey.php | 8 +++ .../Helper/GradValues.php | 2 +- .../Helper/PercentValues.php | 2 +- .../HueSaturationValue.php | 8 +++ src/NaturallyColorModels/RedGreenBlue.php | 8 +++ .../AbstractNaturallyTransformer.php | 54 +++++++++++++++++++ .../ColorModelTransformInterface.php | 18 +++++++ .../CyanMagentaYellowKeyTransformer.php | 21 ++++++++ .../HueSaturationValueTransformer.php | 21 ++++++++ .../RedGreenBlueTransformer.php | 21 ++++++++ 10 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 src/NaturallyTransformer/AbstractNaturallyTransformer.php create mode 100644 src/NaturallyTransformer/ColorModelTransformInterface.php create mode 100644 src/NaturallyTransformer/CyanMagentaYellowKeyTransformer.php create mode 100644 src/NaturallyTransformer/HueSaturationValueTransformer.php create mode 100644 src/NaturallyTransformer/RedGreenBlueTransformer.php 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 From def806637424c4d10fbc072c3409124f5fd100f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Thu, 3 Mar 2022 16:05:51 +0100 Subject: [PATCH 5/5] refactor: kleinere Fehler Beseitigen --- .../Utilities/AbstractHueSaturationValueToUtility.php | 2 +- src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) 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: