From 524fdbb2689f0b11921cc77583e81594ee2ad4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 1 Mar 2022 14:53:07 +0100 Subject: [PATCH 1/4] =?UTF-8?q?documentation:=20Die=20neuen=20Modelle=20si?= =?UTF-8?q?nd=20in=20ihrer=20Abh=C3=A4ngigkeit=20und=20Darstellung=20defin?= =?UTF-8?q?iert=20worden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 16 +++++++++ resources/uml/Klassen-Aufbau.puml | 58 +++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 resources/uml/Klassen-Aufbau.puml diff --git a/README.md b/README.md index 6be27d1..7879610 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,22 @@ Die Modelle müssen mit den Informationen gefüllt werden. Ein nicht geändertes Die Werte sind immer reelle Zahlen von '0.0' bis '1.0'. Dadurch sind die Modele vom eigentlichen Einsatz unabhängig. Die Klassen haben keinen Alphakanal. +### Natürliche Modelle + +Die Modelle werden auch in der 'natürlichen' Darstellung bereitgestellt. + +#### CyanMagentaYellowKey + +Alle Werte werden in der Prozent-Schreibweise zur Verfügung gestellt. + +#### HueSaturationValue + +*Hue* wird als Gradzahl und die anderen Werte als Prozent-Schreibweise zur Verfügung gestellt. + +#### RedGreenBlue + +Die Werte werden als Hexadecimal Zahlen und in der Webschreibweise zur Verfügung gestellt. + ## Hinweise zu den Transformer-Klassen Das Vorgehen der Umwandlung nimmt die Informationen von diff --git a/resources/uml/Klassen-Aufbau.puml b/resources/uml/Klassen-Aufbau.puml new file mode 100644 index 0000000..1884d7a --- /dev/null +++ b/resources/uml/Klassen-Aufbau.puml @@ -0,0 +1,58 @@ +@startuml +'https://plantuml.com/class-diagram + +namespace NaturallyColorModels { + class CyanMagentaYellowKey + class HueSaturationValue + class RedGreenBlue +} + +namespace ColorModels { + abstract AbstractColorModel + class CyanMagentaYellowKey + class HueSaturationValue + class RedGreenBlue + CyanMagentaYellowKey --|> AbstractColorModel + HueSaturationValue --|> AbstractColorModel + RedGreenBlue --|> AbstractColorModel +} +NaturallyColorModels.CyanMagentaYellowKey o-- ColorModels.CyanMagentaYellowKey +NaturallyColorModels.HueSaturationValue o-- ColorModels.HueSaturationValue +NaturallyColorModels.RedGreenBlue o-- ColorModels.RedGreenBlue + + +namespace Transformer { + interface ColorModelTransformInterface { + + toRedGreenBlue(): RedGreenBlue; + + toCyanMagentaYellowKey(): CyanMagentaYellowKey; + + toHueSaturationValue(): HueSaturationValue; + } + class CyanMagentaYellowKeyTransformer + class HueSaturationValueTransformer + class RedGreenBlueTransformer + ColorModelTransformInterface <|-- CyanMagentaYellowKeyTransformer + ColorModelTransformInterface <|-- HueSaturationValueTransformer + ColorModelTransformInterface <|-- RedGreenBlueTransformer + namespace Utilities { + abstract AbstractHueSaturationValueToUtility + class CyanMagentaYellowKeyToHueSaturationValue + class HueSaturationValueToCyanMagentaYellowKey + class HueSaturationValueToRedGreenBlue + class RedGreenBlueToHueSaturationValue + Transformer.Utilities.CyanMagentaYellowKeyToHueSaturationValue --|> Transformer.Utilities.AbstractHueSaturationValueToUtility + Transformer.Utilities.HueSaturationValueToCyanMagentaYellowKey --|> Transformer.Utilities.AbstractHueSaturationValueToUtility + Transformer.Utilities.HueSaturationValueToRedGreenBlue --|> Transformer.Utilities.AbstractHueSaturationValueToUtility + Transformer.Utilities.RedGreenBlueToHueSaturationValue --|> Transformer.Utilities.AbstractHueSaturationValueToUtility + } + CyanMagentaYellowKeyTransformer o-- Transformer.Utilities.CyanMagentaYellowKeyToHueSaturationValue + CyanMagentaYellowKeyTransformer o-- Transformer.Utilities.HueSaturationValueToRedGreenBlue + + HueSaturationValueTransformer o-- Transformer.Utilities.HueSaturationValueToRedGreenBlue + HueSaturationValueTransformer o-- Transformer.Utilities.HueSaturationValueToCyanMagentaYellowKey + + RedGreenBlueTransformer o-- Transformer.Utilities.RedGreenBlueToHueSaturationValue + RedGreenBlueTransformer o-- Transformer.Utilities.HueSaturationValueToCyanMagentaYellowKey +} +ColorModels.AbstractColorModel --o Transformer.ColorModelTransformInterface + +@enduml \ No newline at end of file From ef824f64ebf0610be09dd0adfc8b391cab2b0b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 1 Mar 2022 15:17:01 +0100 Subject: [PATCH 2/4] =?UTF-8?q?tests:=20Tests=20f=C3=BCr=20nat=C3=BCrliche?= =?UTF-8?q?n=20Werte-Klassen=20hinzuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractColorModelUnit.php | 82 +++++++++++ .../CyanMagentaYellowKeyTest.php | 128 ++++++++++++++++++ .../HueSaturationValueTest.php | 100 ++++++++++++++ .../NaturallyColorModels/RedGreenBlueTest.php | 109 +++++++++++++++ 4 files changed, 419 insertions(+) create mode 100644 tests/unit/NaturallyColorModels/AbstractColorModelUnit.php create mode 100644 tests/unit/NaturallyColorModels/CyanMagentaYellowKeyTest.php create mode 100644 tests/unit/NaturallyColorModels/HueSaturationValueTest.php create mode 100644 tests/unit/NaturallyColorModels/RedGreenBlueTest.php diff --git a/tests/unit/NaturallyColorModels/AbstractColorModelUnit.php b/tests/unit/NaturallyColorModels/AbstractColorModelUnit.php new file mode 100644 index 0000000..844f0bc --- /dev/null +++ b/tests/unit/NaturallyColorModels/AbstractColorModelUnit.php @@ -0,0 +1,82 @@ + [-1], + 'zu gross' => [101], + ]; + } + + /** + * @return int[][] + */ + public function validPercentValueProvider(): array + { + return [ + 'niedrigster Wert' => [0], + 'mittlerer Wert' => [45], + 'maximaler Wert' => [100], + ]; + } + + /** + * @return int[][] + */ + public function invalidGradValueProvider(): array + { + return [ + 'zu klein' => [-1], + 'zu gross' => [361], + ]; + } + + /** + * @return int[][] + */ + public function validGradValueProvider(): array + { + return [ + 'niedrigster Wert' => [0], + 'mittlerer Wert' => [45], + 'maximaler Wert' => [360], + ]; + } + + /** + * @return int[][] + */ + public function invalidHexadecimalValueProvider(): array + { + return [ + 'zu klein' => [-0x1], + 'zu gross' => [0x100], + ]; + } + + /** + * @return int[][] + */ + public function validHexadecimalValueProvider(): array + { + return [ + 'niedrigster Wert' => [0x0], + 'mittlerer Wert' => [0xD9], + 'maximaler Wert' => [0xFF], + ]; + } + +} \ No newline at end of file diff --git a/tests/unit/NaturallyColorModels/CyanMagentaYellowKeyTest.php b/tests/unit/NaturallyColorModels/CyanMagentaYellowKeyTest.php new file mode 100644 index 0000000..5c2a8a5 --- /dev/null +++ b/tests/unit/NaturallyColorModels/CyanMagentaYellowKeyTest.php @@ -0,0 +1,128 @@ +assertIsInt($color->getCyan()); + $this->assertEquals(0, $color->getCyan()); + $this->assertIsInt($color->getMagenta()); + $this->assertEquals(0, $color->getMagenta()); + $this->assertIsInt($color->getCyan()); + $this->assertEquals(0, $color->getYellow()); + $this->assertIsInt($color->getKey()); + $this->assertEquals(0, $color->getKey()); + } + + /** + * @param int $value + * + * @dataProvider validPercentValueProvider + */ + public function testSetCyanWithValidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $color->setCyan($value); + $this->assertEquals($value, $color->getCyan()); + } + + /** + * @param int $value + * + * @dataProvider validPercentValueProvider + */ + public function testSetMagentaWithValidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $color->setMagenta($value); + $this->assertEquals($value, $color->getMagenta()); + } + + /** + * @param int $value + * + * @dataProvider validPercentValueProvider + */ + public function testSetYellowWithValidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $color->setYellow($value); + $this->assertEquals($value, $color->getYellow()); + } + + /** + * @param int $value + * + * @dataProvider validPercentValueProvider + */ + public function testSetKeyWithValidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $color->setKey($value); + $this->assertEquals($value, $color->getKey()); + } + + /** + * @param int $value + * + * @dataProvider invalidPercentValueProvider + */ + public function testSetCyanWithInvalidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $this->expectException(InvalidArgumentException::class); + $color->setCyan($value); + } + + /** + * @param int $value + * + * @dataProvider invalidPercentValueProvider + */ + public function testSetMagentaWithInvalidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $this->expectException(InvalidArgumentException::class); + $color->setMagenta($value); + } + + /** + * @param int $value + * + * @dataProvider invalidPercentValueProvider + */ + public function testSetYellowWithInvalidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $this->expectException(InvalidArgumentException::class); + $color->setYellow($value); + } + + /** + * @param int $value + * + * @dataProvider invalidPercentValueProvider + */ + public function testSetKeyWithInvalidValue(int $value): void + { + $color = new CyanMagentaYellowKey(); + + $this->expectException(InvalidArgumentException::class); + $color->setKey($value); + } +} diff --git a/tests/unit/NaturallyColorModels/HueSaturationValueTest.php b/tests/unit/NaturallyColorModels/HueSaturationValueTest.php new file mode 100644 index 0000000..614e254 --- /dev/null +++ b/tests/unit/NaturallyColorModels/HueSaturationValueTest.php @@ -0,0 +1,100 @@ +assertIsInt($color->getHue()); + $this->assertEquals(0, $color->getHue()); + $this->assertIsInt($color->getSaturation()); + $this->assertEquals(0, $color->getSaturation()); + $this->assertIsInt($color->getValue()); + $this->assertEquals(100, $color->getValue()); + } + + /** + * @param int $value + * + * @dataProvider validGradValueProvider + */ + public function testSetHueWithValidValue(int $value): void + { + $color = new HueSaturationValue(); + + $color->setHue($value); + $this->assertEquals($value, $color->getHue()); + } + + /** + * @param int $value + * + * @dataProvider invalidGradValueProvider + */ + public function testSetHueWithInvalidValue(int $value): void + { + $color = new HueSaturationValue(); + + $this->expectException(InvalidArgumentException::class); + $color->setHue($value); + } + + /** + * @param int $value + * + * @dataProvider validPercentValueProvider + */ + public function testSetSaturationWithValidValue(int $value): void + { + $color = new HueSaturationValue(); + + $color->setSaturation($value); + $this->assertEquals($value, $color->getSaturation()); + } + + /** + * @param int $value + * + * @dataProvider invalidPercentValueProvider + */ + public function testSetSaturationWithInvalidValue(int $value): void + { + $color = new HueSaturationValue(); + + $this->expectException(InvalidArgumentException::class); + $color->setSaturation($value); + } + + /** + * @param int $value + * + * @dataProvider validPercentValueProvider + */ + public function testSetValueWithValidValue(int $value): void + { + $color = new HueSaturationValue(); + + $color->setValue($value); + $this->assertEquals($value, $color->getValue()); + } + + /** + * @param int $value + * + * @dataProvider invalidPercentValueProvider + */ + public function testSetValueWithInvalidValue(int $value): void + { + $color = new HueSaturationValue(); + + $this->expectException(InvalidArgumentException::class); + $color->setValue($value); + } +} diff --git a/tests/unit/NaturallyColorModels/RedGreenBlueTest.php b/tests/unit/NaturallyColorModels/RedGreenBlueTest.php new file mode 100644 index 0000000..f33cb1a --- /dev/null +++ b/tests/unit/NaturallyColorModels/RedGreenBlueTest.php @@ -0,0 +1,109 @@ +assertEquals(0xFF, $color->getRed()); + $this->assertEquals(0xFF, $color->getGreen()); + $this->assertEquals(0xFF, $color->getBlue()); + } + + /** + * @param int $value + * + * @dataProvider validHexadecimalValueProvider + */ + public function testSetRedWithValidValue(int $value): void + { + $color = new RedGreenBlue(); + + $color->setRed($value); + $this->assertEquals($value, $color->getRed()); + } + + /** + * @param int $value + * + * @dataProvider invalidHexadecimalValueProvider + */ + public function testSetRedWithInvalidValue(int $value): void + { + $color = new RedGreenBlue(); + + $this->expectException(InvalidArgumentException::class); + $color->setRed($value); + } + /** + * @param int $value + * + * @dataProvider validHexadecimalValueProvider + */ + public function testSetGreenWithValidValue(int $value): void + { + $color = new RedGreenBlue(); + + $color->setGreen($value); + $this->assertEquals($value, $color->getGreen()); + } + + /** + * @param int $value + * + * @dataProvider invalidHexadecimalValueProvider + */ + public function testSetGreenWithInvalidValue(int $value): void + { + $color = new RedGreenBlue(); + + $this->expectException(InvalidArgumentException::class); + $color->setGreen($value); + } + + /** + * @param int $value + * + * @dataProvider validHexadecimalValueProvider + */ + public function testSetBlueWithValidValue(int $value): void + { + $color = new RedGreenBlue(); + + $color->setBlue($value); + $this->assertEquals($value, $color->getBlue()); + } + + /** + * @param int $value + * + * @dataProvider invalidHexadecimalValueProvider + */ + public function testSetBlueWithInvalidValue(int $value): void + { + $color = new RedGreenBlue(); + + $this->expectException(InvalidArgumentException::class); + $color->setBlue($value); + } + + public function testHtmlNotation(): void + { + $color = new RedGreenBlue(); + $color->setRed(0xA1); + $color->setGreen(0xB2); + $color->setBlue(0xC3); + + $html = $color->asHtmlNotation(); + + $this->assertIsString($html); + $this->assertEquals('#A1B2C3', $html); + } +} From 039d780d8517ebf43aaea725140228b10ab09b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 1 Mar 2022 20:55:52 +0100 Subject: [PATCH 3/4] =?UTF-8?q?feature:=20nat=C3=BCrlichen=20Werte-Klassen?= =?UTF-8?q?=20hinzuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractColorModel.php | 71 +++++++++++++ .../CyanMagentaYellowKey.php | 99 +++++++++++++++++++ .../HueSaturationValue.php | 82 +++++++++++++++ src/NaturallyColorModels/RedGreenBlue.php | 84 ++++++++++++++++ 4 files changed, 336 insertions(+) create mode 100644 src/NaturallyColorModels/AbstractColorModel.php create mode 100644 src/NaturallyColorModels/CyanMagentaYellowKey.php create mode 100644 src/NaturallyColorModels/HueSaturationValue.php create mode 100644 src/NaturallyColorModels/RedGreenBlue.php diff --git a/src/NaturallyColorModels/AbstractColorModel.php b/src/NaturallyColorModels/AbstractColorModel.php new file mode 100644 index 0000000..faf7af4 --- /dev/null +++ b/src/NaturallyColorModels/AbstractColorModel.php @@ -0,0 +1,71 @@ + 100) { + throw new InvalidArgumentException('Ein Wert größer als 100% ist nicht definierbar.'); + } + if ($value < 0) { + throw new InvalidArgumentException('Ein Wert kleiner als 0% ist nicht definierbar.'); + } + } + + protected function asGradValue(float $value): int + { + return intval($value * 360); + } + + protected function fromGradValue(int $value): float + { + return $value / 360.0; + } + + protected function checkGradValue(int $value): void + { + if ($value > 360) { + throw new InvalidArgumentException('Ein Wert größer als 360° ist nicht definierbar.'); + } + if ($value < 0) { + throw new InvalidArgumentException('Ein Wert kleiner als 0° ist nicht definierbar.'); + } + } + + protected function asHexadecimalValue(float $value): int + { + return intval($value * 0xFF); + } + + protected function fromHexadecimalValue(int $value): float + { + return $value / 0xFF; + } + + protected function checkHexadecimalValue(int $value): void + { + if ($value > 0xFF) { + throw new InvalidArgumentException('Ein Wert größer als "0xFF" ist nicht definierbar.'); + } + if ($value < 0) { + throw new InvalidArgumentException('Ein Wert kleiner als "0x00" ist nicht definierbar.'); + } + } + +} \ No newline at end of file diff --git a/src/NaturallyColorModels/CyanMagentaYellowKey.php b/src/NaturallyColorModels/CyanMagentaYellowKey.php new file mode 100644 index 0000000..44a5f38 --- /dev/null +++ b/src/NaturallyColorModels/CyanMagentaYellowKey.php @@ -0,0 +1,99 @@ +pureColor = new PureCyanMagentaYellowKey(); + } + + /** + * @return int + */ + #[Pure] public function getCyan(): int + { + return $this->asPercentValue($this->pureColor->getCyan()); + } + + /** + * @param int $cyan + * @return CyanMagentaYellowKey + */ + public function setCyan(int $cyan): CyanMagentaYellowKey + { + $this->checkPercentValue($cyan); + $this->pureColor->setCyan($this->fromPercentValue($cyan)); + return $this; + } + + /** + * @return int + */ + #[Pure] public function getMagenta(): int + { + return $this->asPercentValue($this->pureColor->getMagenta()); + } + + /** + * @param int $magenta + * @return CyanMagentaYellowKey + */ + public function setMagenta(int $magenta): CyanMagentaYellowKey + { + $this->checkPercentValue($magenta); + $this->pureColor->setMagenta($this->fromPercentValue($magenta)); + return $this; + } + + /** + * @return int + */ + #[Pure] public function getYellow(): int + { + return $this->asPercentValue($this->pureColor->getYellow()); + } + + /** + * @param int $yellow + * @return CyanMagentaYellowKey + */ + public function setYellow(int $yellow): CyanMagentaYellowKey + { + $this->checkPercentValue($yellow); + $this->pureColor->setYellow($this->fromPercentValue($yellow)); + return $this; + } + + /** + * @return int + */ + #[Pure] public function getKey(): int + { + return $this->asPercentValue($this->pureColor->getKey()); + } + + /** + * @param int $key + * @return CyanMagentaYellowKey + */ + public function setKey(int $key): CyanMagentaYellowKey + { + $this->checkPercentValue($key); + $this->pureColor->setKey($this->fromPercentValue($key)); + return $this; + } + +} \ No newline at end of file diff --git a/src/NaturallyColorModels/HueSaturationValue.php b/src/NaturallyColorModels/HueSaturationValue.php new file mode 100644 index 0000000..9c30a63 --- /dev/null +++ b/src/NaturallyColorModels/HueSaturationValue.php @@ -0,0 +1,82 @@ +pureColor = new PureHueSaturationValue(); + } + + /** + * @return int + */ + #[Pure] public function getHue(): int + { + return $this->asGradValue($this->pureColor->getHue()); + } + + /** + * @param int $hue + * @return HueSaturationValue + */ + public function setHue(int $hue): HueSaturationValue + { + $this->checkGradValue($hue); + $this->pureColor->setHue($this->fromGradValue($hue)); + return $this; + } + + /** + * @return int + */ + #[Pure] public function getSaturation(): int + { + return $this->asPercentValue($this->pureColor->getSaturation()); + } + + /** + * @param int $saturation + * @return HueSaturationValue + */ + public function setSaturation(int $saturation): HueSaturationValue + { + $this->checkPercentValue($saturation); + $this->pureColor->setSaturation($this->fromPercentValue($saturation)); + return $this; + } + + /** + * @return int + */ + #[Pure] public function getValue(): int + { + return $this->asPercentValue($this->pureColor->getValue()); + } + + /** + * @param int $value + * @return HueSaturationValue + */ + public function setValue(int $value): HueSaturationValue + { + $this->checkPercentValue($value); + $this->pureColor->setValue($this->fromPercentValue($value)); + return $this; + } + + +} \ No newline at end of file diff --git a/src/NaturallyColorModels/RedGreenBlue.php b/src/NaturallyColorModels/RedGreenBlue.php new file mode 100644 index 0000000..9769489 --- /dev/null +++ b/src/NaturallyColorModels/RedGreenBlue.php @@ -0,0 +1,84 @@ +pureColor = new PureRedGreenBlue(); + } + + /** + * @return int + */ + #[Pure] public function getRed(): int + { + return $this->asHexadecimalValue($this->pureColor->getRed()); + } + + /** + * @param int $red + * @return RedGreenBlue + */ + public function setRed(int $red): RedGreenBlue + { + $this->checkHexadecimalValue($red); + $this->pureColor->setRed($this->fromHexadecimalValue($red)); + return $this; + } + + /** + * @return int + */ + #[Pure] public function getGreen(): int + { + return $this->asHexadecimalValue($this->pureColor->getGreen()); + } + + /** + * @param int $green + * @return RedGreenBlue + */ + public function setGreen(int $green): RedGreenBlue + { + $this->checkHexadecimalValue($green); + $this->pureColor->setGreen($this->fromHexadecimalValue($green)); + return $this; + } + + /** + * @return int + */ + public function getBlue(): int + { + return $this->asHexadecimalValue($this->pureColor->getBlue()); + } + + /** + * @param int $blue + * @return RedGreenBlue + */ + public function setBlue(int $blue): RedGreenBlue + { + $this->checkHexadecimalValue($blue); + $this->pureColor->setBlue($this->fromHexadecimalValue($blue)); + return $this; + } + + public function asHtmlNotation(): string + { + return sprintf('#%X%X%X', $this->getRed(), $this->getGreen(), $this->getBlue()); + } + +} \ No newline at end of file From 9505be376a6b43954bb21227578d991776156f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 1 Mar 2022 21:17:52 +0100 Subject: [PATCH 4/4] refactor: Helfer-Klassen ersetzten eine abstrakte Klasse --- .../AbstractColorModel.php | 71 ------------------- .../CyanMagentaYellowKey.php | 28 ++++---- .../Helper/GradValues.php | 31 ++++++++ .../Helper/HexadecimalValues.php | 31 ++++++++ .../Helper/PercentValues.php | 31 ++++++++ .../HueSaturationValue.php | 24 ++++--- src/NaturallyColorModels/RedGreenBlue.php | 24 ++++--- 7 files changed, 135 insertions(+), 105 deletions(-) delete mode 100644 src/NaturallyColorModels/AbstractColorModel.php create mode 100644 src/NaturallyColorModels/Helper/GradValues.php create mode 100644 src/NaturallyColorModels/Helper/HexadecimalValues.php create mode 100644 src/NaturallyColorModels/Helper/PercentValues.php diff --git a/src/NaturallyColorModels/AbstractColorModel.php b/src/NaturallyColorModels/AbstractColorModel.php deleted file mode 100644 index faf7af4..0000000 --- a/src/NaturallyColorModels/AbstractColorModel.php +++ /dev/null @@ -1,71 +0,0 @@ - 100) { - throw new InvalidArgumentException('Ein Wert größer als 100% ist nicht definierbar.'); - } - if ($value < 0) { - throw new InvalidArgumentException('Ein Wert kleiner als 0% ist nicht definierbar.'); - } - } - - protected function asGradValue(float $value): int - { - return intval($value * 360); - } - - protected function fromGradValue(int $value): float - { - return $value / 360.0; - } - - protected function checkGradValue(int $value): void - { - if ($value > 360) { - throw new InvalidArgumentException('Ein Wert größer als 360° ist nicht definierbar.'); - } - if ($value < 0) { - throw new InvalidArgumentException('Ein Wert kleiner als 0° ist nicht definierbar.'); - } - } - - protected function asHexadecimalValue(float $value): int - { - return intval($value * 0xFF); - } - - protected function fromHexadecimalValue(int $value): float - { - return $value / 0xFF; - } - - protected function checkHexadecimalValue(int $value): void - { - if ($value > 0xFF) { - throw new InvalidArgumentException('Ein Wert größer als "0xFF" ist nicht definierbar.'); - } - if ($value < 0) { - throw new InvalidArgumentException('Ein Wert kleiner als "0x00" ist nicht definierbar.'); - } - } - -} \ No newline at end of file diff --git a/src/NaturallyColorModels/CyanMagentaYellowKey.php b/src/NaturallyColorModels/CyanMagentaYellowKey.php index 44a5f38..1df9034 100644 --- a/src/NaturallyColorModels/CyanMagentaYellowKey.php +++ b/src/NaturallyColorModels/CyanMagentaYellowKey.php @@ -10,14 +10,16 @@ use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey as PureCyanMagentaY * Definition des allgemeinen CMYK-Farbraumes. Die Werte für die eigenschaften sind reelle Zahlen von 0 bis einschließlich 1. * Ohne Änderung der Eigenschaften wird die Farbe *weiß* dargestellt. */ -class CyanMagentaYellowKey extends AbstractColorModel +class CyanMagentaYellowKey { /** @var PureCyanMagentaYellowKey : Standard-Color-Modell */ protected PureCyanMagentaYellowKey $pureColor; + protected Helper\PercentValues $percentValuesHelper; #[Pure] public function __construct() { $this->pureColor = new PureCyanMagentaYellowKey(); + $this->percentValuesHelper = new Helper\PercentValues(); } /** @@ -25,7 +27,7 @@ class CyanMagentaYellowKey extends AbstractColorModel */ #[Pure] public function getCyan(): int { - return $this->asPercentValue($this->pureColor->getCyan()); + return $this->percentValuesHelper->asPercentValue($this->pureColor->getCyan()); } /** @@ -34,8 +36,8 @@ class CyanMagentaYellowKey extends AbstractColorModel */ public function setCyan(int $cyan): CyanMagentaYellowKey { - $this->checkPercentValue($cyan); - $this->pureColor->setCyan($this->fromPercentValue($cyan)); + $this->percentValuesHelper->checkPercentValue($cyan); + $this->pureColor->setCyan($this->percentValuesHelper->fromPercentValue($cyan)); return $this; } @@ -44,7 +46,7 @@ class CyanMagentaYellowKey extends AbstractColorModel */ #[Pure] public function getMagenta(): int { - return $this->asPercentValue($this->pureColor->getMagenta()); + return $this->percentValuesHelper->asPercentValue($this->pureColor->getMagenta()); } /** @@ -53,8 +55,8 @@ class CyanMagentaYellowKey extends AbstractColorModel */ public function setMagenta(int $magenta): CyanMagentaYellowKey { - $this->checkPercentValue($magenta); - $this->pureColor->setMagenta($this->fromPercentValue($magenta)); + $this->percentValuesHelper->checkPercentValue($magenta); + $this->pureColor->setMagenta($this->percentValuesHelper->fromPercentValue($magenta)); return $this; } @@ -63,7 +65,7 @@ class CyanMagentaYellowKey extends AbstractColorModel */ #[Pure] public function getYellow(): int { - return $this->asPercentValue($this->pureColor->getYellow()); + return $this->percentValuesHelper->asPercentValue($this->pureColor->getYellow()); } /** @@ -72,8 +74,8 @@ class CyanMagentaYellowKey extends AbstractColorModel */ public function setYellow(int $yellow): CyanMagentaYellowKey { - $this->checkPercentValue($yellow); - $this->pureColor->setYellow($this->fromPercentValue($yellow)); + $this->percentValuesHelper->checkPercentValue($yellow); + $this->pureColor->setYellow($this->percentValuesHelper->fromPercentValue($yellow)); return $this; } @@ -82,7 +84,7 @@ class CyanMagentaYellowKey extends AbstractColorModel */ #[Pure] public function getKey(): int { - return $this->asPercentValue($this->pureColor->getKey()); + return $this->percentValuesHelper->asPercentValue($this->pureColor->getKey()); } /** @@ -91,8 +93,8 @@ class CyanMagentaYellowKey extends AbstractColorModel */ public function setKey(int $key): CyanMagentaYellowKey { - $this->checkPercentValue($key); - $this->pureColor->setKey($this->fromPercentValue($key)); + $this->percentValuesHelper->checkPercentValue($key); + $this->pureColor->setKey($this->percentValuesHelper->fromPercentValue($key)); return $this; } diff --git a/src/NaturallyColorModels/Helper/GradValues.php b/src/NaturallyColorModels/Helper/GradValues.php new file mode 100644 index 0000000..75e9c0b --- /dev/null +++ b/src/NaturallyColorModels/Helper/GradValues.php @@ -0,0 +1,31 @@ + 360) { + throw new InvalidArgumentException('Ein Wert größer als 360° ist nicht definierbar.'); + } + if ($value < 0) { + throw new InvalidArgumentException('Ein Wert kleiner als 0° ist nicht definierbar.'); + } + } + +} \ No newline at end of file diff --git a/src/NaturallyColorModels/Helper/HexadecimalValues.php b/src/NaturallyColorModels/Helper/HexadecimalValues.php new file mode 100644 index 0000000..9477e39 --- /dev/null +++ b/src/NaturallyColorModels/Helper/HexadecimalValues.php @@ -0,0 +1,31 @@ + 0xFF) { + throw new InvalidArgumentException('Ein Wert größer als "0xFF" ist nicht definierbar.'); + } + if ($value < 0) { + throw new InvalidArgumentException('Ein Wert kleiner als "0x00" ist nicht definierbar.'); + } + } + +} \ No newline at end of file diff --git a/src/NaturallyColorModels/Helper/PercentValues.php b/src/NaturallyColorModels/Helper/PercentValues.php new file mode 100644 index 0000000..b9350fa --- /dev/null +++ b/src/NaturallyColorModels/Helper/PercentValues.php @@ -0,0 +1,31 @@ + 100) { + throw new InvalidArgumentException('Ein Wert größer als 100% ist nicht definierbar.'); + } + if ($value < 0) { + throw new InvalidArgumentException('Ein Wert kleiner als 0% ist nicht definierbar.'); + } + } + +} \ No newline at end of file diff --git a/src/NaturallyColorModels/HueSaturationValue.php b/src/NaturallyColorModels/HueSaturationValue.php index 9c30a63..0870523 100644 --- a/src/NaturallyColorModels/HueSaturationValue.php +++ b/src/NaturallyColorModels/HueSaturationValue.php @@ -11,14 +11,18 @@ use TorstenHettstedt\Colors\ColorModels\HueSaturationValue as PureHueSaturationV * Definition des allgemeinen HSV-Farbraumes. Die Werte für die Eigenschaften sind reelle Zahlen von 0 bis einschließlich 1. * Ohne Änderung der Eigenschaften wird die Farbe *weiß* dargestellt. */ -class HueSaturationValue extends AbstractColorModel +class HueSaturationValue { /** @var PureHueSaturationValue : Standard-Color-Modell */ protected PureHueSaturationValue $pureColor; + protected Helper\PercentValues $percentValuesHelper; + protected Helper\GradValues $gradValuesHelper; #[Pure] public function __construct() { $this->pureColor = new PureHueSaturationValue(); + $this->percentValuesHelper = new Helper\PercentValues(); + $this->gradValuesHelper = new Helper\GradValues(); } /** @@ -26,7 +30,7 @@ class HueSaturationValue extends AbstractColorModel */ #[Pure] public function getHue(): int { - return $this->asGradValue($this->pureColor->getHue()); + return $this->gradValuesHelper->asGradValue($this->pureColor->getHue()); } /** @@ -35,8 +39,8 @@ class HueSaturationValue extends AbstractColorModel */ public function setHue(int $hue): HueSaturationValue { - $this->checkGradValue($hue); - $this->pureColor->setHue($this->fromGradValue($hue)); + $this->gradValuesHelper->checkGradValue($hue); + $this->pureColor->setHue($this->gradValuesHelper->fromGradValue($hue)); return $this; } @@ -45,7 +49,7 @@ class HueSaturationValue extends AbstractColorModel */ #[Pure] public function getSaturation(): int { - return $this->asPercentValue($this->pureColor->getSaturation()); + return $this->percentValuesHelper->asPercentValue($this->pureColor->getSaturation()); } /** @@ -54,8 +58,8 @@ class HueSaturationValue extends AbstractColorModel */ public function setSaturation(int $saturation): HueSaturationValue { - $this->checkPercentValue($saturation); - $this->pureColor->setSaturation($this->fromPercentValue($saturation)); + $this->percentValuesHelper->checkPercentValue($saturation); + $this->pureColor->setSaturation($this->percentValuesHelper->fromPercentValue($saturation)); return $this; } @@ -64,7 +68,7 @@ class HueSaturationValue extends AbstractColorModel */ #[Pure] public function getValue(): int { - return $this->asPercentValue($this->pureColor->getValue()); + return $this->percentValuesHelper->asPercentValue($this->pureColor->getValue()); } /** @@ -73,8 +77,8 @@ class HueSaturationValue extends AbstractColorModel */ public function setValue(int $value): HueSaturationValue { - $this->checkPercentValue($value); - $this->pureColor->setValue($this->fromPercentValue($value)); + $this->percentValuesHelper->checkPercentValue($value); + $this->pureColor->setValue($this->percentValuesHelper->fromPercentValue($value)); return $this; } diff --git a/src/NaturallyColorModels/RedGreenBlue.php b/src/NaturallyColorModels/RedGreenBlue.php index 9769489..852b151 100644 --- a/src/NaturallyColorModels/RedGreenBlue.php +++ b/src/NaturallyColorModels/RedGreenBlue.php @@ -9,14 +9,16 @@ use TorstenHettstedt\Colors\ColorModels\RedGreenBlue as PureRedGreenBlue; * Definition des allgemeinen RGB-Farbraumes. Die Werte für die eigenschaften sind reelle Zahlen von 0 bis einschließlich 1. * Ohne Änderung der Eigenschaften wird die Farbe *weiß* dargestellt. */ -class RedGreenBlue extends AbstractColorModel +class RedGreenBlue { /** @var PureRedGreenBlue : Standard-Color-Modell */ - protected PureRedGreenBlue $pureColor; + protected PureRedGreenBlue $pureColor; + protected Helper\HexadecimalValues $hexadecimalValuesHelper; #[Pure] public function __construct() { $this->pureColor = new PureRedGreenBlue(); + $this->hexadecimalValuesHelper = new Helper\HexadecimalValues(); } /** @@ -24,7 +26,7 @@ class RedGreenBlue extends AbstractColorModel */ #[Pure] public function getRed(): int { - return $this->asHexadecimalValue($this->pureColor->getRed()); + return $this->hexadecimalValuesHelper->asHexadecimalValue($this->pureColor->getRed()); } /** @@ -33,8 +35,8 @@ class RedGreenBlue extends AbstractColorModel */ public function setRed(int $red): RedGreenBlue { - $this->checkHexadecimalValue($red); - $this->pureColor->setRed($this->fromHexadecimalValue($red)); + $this->hexadecimalValuesHelper->checkHexadecimalValue($red); + $this->pureColor->setRed($this->hexadecimalValuesHelper->fromHexadecimalValue($red)); return $this; } @@ -43,7 +45,7 @@ class RedGreenBlue extends AbstractColorModel */ #[Pure] public function getGreen(): int { - return $this->asHexadecimalValue($this->pureColor->getGreen()); + return $this->hexadecimalValuesHelper->asHexadecimalValue($this->pureColor->getGreen()); } /** @@ -52,8 +54,8 @@ class RedGreenBlue extends AbstractColorModel */ public function setGreen(int $green): RedGreenBlue { - $this->checkHexadecimalValue($green); - $this->pureColor->setGreen($this->fromHexadecimalValue($green)); + $this->hexadecimalValuesHelper->checkHexadecimalValue($green); + $this->pureColor->setGreen($this->hexadecimalValuesHelper->fromHexadecimalValue($green)); return $this; } @@ -62,7 +64,7 @@ class RedGreenBlue extends AbstractColorModel */ public function getBlue(): int { - return $this->asHexadecimalValue($this->pureColor->getBlue()); + return $this->hexadecimalValuesHelper->asHexadecimalValue($this->pureColor->getBlue()); } /** @@ -71,8 +73,8 @@ class RedGreenBlue extends AbstractColorModel */ public function setBlue(int $blue): RedGreenBlue { - $this->checkHexadecimalValue($blue); - $this->pureColor->setBlue($this->fromHexadecimalValue($blue)); + $this->hexadecimalValuesHelper->checkHexadecimalValue($blue); + $this->pureColor->setBlue($this->hexadecimalValuesHelper->fromHexadecimalValue($blue)); return $this; }