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] =?UTF-8?q?feature:=20nat=C3=BCrliche=20Modellklassen=20k?= =?UTF-8?q?=C3=B6nnen=20in=20andere=20Farbsysteme=20transformiert=20werden?= 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