diff --git a/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php b/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php new file mode 100644 index 0000000..d237a04 --- /dev/null +++ b/src/Transformer/Utilities/AbstractHueSaturationValueToUtility.php @@ -0,0 +1,56 @@ +hue = $from_color->getHue(); + $this->hueAsPercentGrad = intval($this->hue * self::INTERVAL * 6.0); + $this->saturation = $from_color->getSaturation(); + $this->value = $from_color->getValue(); + } + + + protected function processConvert(): void + { + if ($this->saturation > 0.0) { + $this->splitColor(); + } + } + + abstract protected function splitColor(): void; + + protected function calcColorValue($reciprocal = false): float + { + // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' + $remainder_grad = $this->hueAsPercentGrad % self::INTERVAL; + // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' + $remainder = $remainder_grad / self::INTERVAL; + return $this->saturation * ($reciprocal ? (1 - $remainder) : $remainder); + } + +} \ No newline at end of file diff --git a/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php b/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php index a8e9d0a..bfced30 100644 --- a/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php +++ b/src/Transformer/Utilities/HueSaturationValueToCyanMagentaYellowKey.php @@ -5,23 +5,9 @@ namespace TorstenHettstedt\Colors\Transformer\Utilities; use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey; -use TorstenHettstedt\Colors\ColorModels\HueSaturationValue; -class HueSaturationValueToCyanMagentaYellowKey +class HueSaturationValueToCyanMagentaYellowKey extends AbstractHueSaturationValueToUtility { - /** @var int : Größe des Intervals in 1/100 Grad */ - protected const INTERVAL = 60.0 * 100.0; - - // Daten für HSV - /** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */ - protected float $hue; - /** @var float : Anteil am Vollkreis in 1/100 Grad */ - protected float $hueAsPercentGrad; - /** @var float : Definition der Sättigung der Farbe */ - protected float $saturation; - /** @var float : Definition der Helligkeit der Farbe */ - protected float $value; - // Daten für CMYK /** @var float : Definition des Cyan-Anteil */ protected float $cyan = 0.0; @@ -32,19 +18,6 @@ class HueSaturationValueToCyanMagentaYellowKey /** @var float : Definition des Schwarzanteil */ protected float $key = 0.0; - /** - * HueSaturationValueToRedGreenBlue constructor. - * @param HueSaturationValue $from_color - * @noinspection PhpPureAttributeCanBeAddedInspection - */ - public function __construct(HueSaturationValue $from_color) - { - $this->hue = $from_color->getHue(); - $this->hueAsPercentGrad = intval($this->hue * self::INTERVAL * 6); - $this->saturation = $from_color->getSaturation(); - $this->value = $from_color->getValue(); - } - public function convert(): CyanMagentaYellowKey { $this->processConvert(); @@ -60,9 +33,7 @@ class HueSaturationValueToCyanMagentaYellowKey protected function processConvert(): void { $this->key = 1 - $this->value; - if ($this->saturation !== 0.0) { - $this->splitColor(); - } + parent::processConvert(); } protected function splitColor(): void @@ -98,13 +69,4 @@ class HueSaturationValueToCyanMagentaYellowKey } } - protected function calcColorValue($reciprocal = false): float - { - // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' - $remainder_grad = $this->hueAsPercentGrad % self::INTERVAL; - // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' - $remainder = $remainder_grad / self::INTERVAL; - return $this->saturation * ($reciprocal ? (1 - $remainder) : $remainder); - } - } \ No newline at end of file diff --git a/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php b/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php index 64fab92..30b473d 100644 --- a/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php +++ b/src/Transformer/Utilities/HueSaturationValueToRedGreenBlue.php @@ -4,24 +4,10 @@ namespace TorstenHettstedt\Colors\Transformer\Utilities; -use TorstenHettstedt\Colors\ColorModels\HueSaturationValue; use TorstenHettstedt\Colors\ColorModels\RedGreenBlue; -class HueSaturationValueToRedGreenBlue +class HueSaturationValueToRedGreenBlue extends AbstractHueSaturationValueToUtility { - /** @var int : Größe des Intervals in 1/100 Grad */ - protected const INTERVAL = 60.0 * 100.0; - - // Daten für HSV - /** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */ - protected float $hue; - /** @var float : Anteil am Vollkreis in 1/100 Grad */ - protected float $hueAsPercentGrad; - /** @var float : Definition der Sättigung der Farbe */ - protected float $saturation; - /** @var float : Definition der Helligkeit der Farbe */ - protected float $value; - // Daten für RGB /** @var float : Definition des Rotanteil */ protected float $red = 1.0; @@ -30,19 +16,6 @@ class HueSaturationValueToRedGreenBlue /** @var float : Definition des Blauanteil */ protected float $blue = 1.0; - /** - * HueSaturationValueToRedGreenBlue constructor. - * @param HueSaturationValue $from_color - * @noinspection PhpPureAttributeCanBeAddedInspection - */ - public function __construct(HueSaturationValue $from_color) - { - $this->hue = $from_color->getHue(); - $this->hueAsPercentGrad = intval($this->hue * self::INTERVAL * 6); - $this->saturation = $from_color->getSaturation(); - $this->value = $from_color->getValue(); - } - public function convert(): RedGreenBlue { $this->processConvert(); @@ -57,9 +30,7 @@ class HueSaturationValueToRedGreenBlue protected function processConvert(): void { $this->red = $this->green = $this->blue = $this->value; - if ($this->saturation > 0.0) { - $this->splitColor(); - } + parent::processConvert(); } protected function splitColor(): void @@ -99,12 +70,8 @@ class HueSaturationValueToRedGreenBlue protected function calcColorValue($reciprocal = false): float { - // Rest-Anteil am Vollkreis in 1/100 Grad - $remainder_grad = $this->hueAsPercentGrad % self::INTERVAL; - // Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]' - $remainder = $remainder_grad / self::INTERVAL; $color_value = $this->value; - $color_value *= 1 - ($this->saturation * ($reciprocal ? (1 - $remainder) : $remainder)); + $color_value *= 1 - parent::calcColorValue($reciprocal); return $color_value; }