From 5e4f1f0bd84a4e78a0d5a95efd681b2c1756fbc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20L=C3=BCcke?= Date: Tue, 23 Mar 2021 13:05:45 +0100 Subject: [PATCH] =?UTF-8?q?Entfernung=20nicht=20ausgef=C3=BChrten=20Codes?= =?UTF-8?q?=20und=20Dokumentation=20der=20Wertebereiche=20zur=20besseren?= =?UTF-8?q?=20Darstellung=20der=20m=C3=B6glichen=20Risiken.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...anMagentaYellowKeyToHueSaturationValue.php | 24 ++++++++++------- .../RedGreenBlueToHueSaturationValue.php | 26 +++++++++---------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/Transformer/Utilities/CyanMagentaYellowKeyToHueSaturationValue.php b/src/Transformer/Utilities/CyanMagentaYellowKeyToHueSaturationValue.php index 4613f75..3a52c14 100644 --- a/src/Transformer/Utilities/CyanMagentaYellowKeyToHueSaturationValue.php +++ b/src/Transformer/Utilities/CyanMagentaYellowKeyToHueSaturationValue.php @@ -74,7 +74,9 @@ class CyanMagentaYellowKeyToHueSaturationValue protected function buildHueAmount(): float { - if ($this->maxCmyProperty === 0.0) { + // Wenn beide Werte gleich sind, ist die Endfarbe Grau. + // Damit wird auch in {@sse hueAmount()} eine Division durch Null verhindert. + if ($this->maxCmyProperty === $this->minCmyProperty) { return 0.0; } @@ -91,30 +93,32 @@ class CyanMagentaYellowKeyToHueSaturationValue */ private function hueAmount(string $property): float { - static $amount_share = 2.0; - + // Wertebereich: [0.0, 1.0] $divisor = $this->maxCmyProperty - $this->minCmyProperty; + // Wertebereich: [1.0, 5.0] + $amount = 0.0; + // Wertebereich: [-1.0, +1.0] + $dividend = 0.0; switch ($property) { case self::PROPERTY_YELLOW: - $amount = 0; // 0.167 + $amount = 1.0; // 0.167 $dividend = $this->cyan - $this->magenta; break; case self::PROPERTY_CYAN: - $amount = 1; // 0.500 + $amount = 3.0; // 0.500 $dividend = $this->magenta -$this->yellow; break; case self::PROPERTY_MAGENTA: - $amount = 2; // 0.833 + $amount = 5.0; // 0.833 $dividend = $this->yellow - $this->cyan; break; - default: - return 0; } - $start_amount = ($amount * $amount_share) + 1.0; + // Wertebereich: [-1.0, +1.0] $expansion_amount = $dividend / $divisor; - return ($start_amount + $expansion_amount) / 6.0; + // Wertebereich: [+0.0, +6.0] + return ($amount + $expansion_amount) / 6.0; } } \ No newline at end of file diff --git a/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php b/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php index 4b06a31..f74d781 100644 --- a/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php +++ b/src/Transformer/Utilities/RedGreenBlueToHueSaturationValue.php @@ -58,10 +58,6 @@ class RedGreenBlueToHueSaturationValue while($this->hue < 0.0) { $this->hue += 1.0; } - - while($this->hue > 1.0) { - $this->hue -= 1.0; - } } public function convert(): HueSaturationValue @@ -76,6 +72,8 @@ class RedGreenBlueToHueSaturationValue protected function buildHueAmount(): float { + // Wenn beide Werte gleich sind, ist die Endfarbe Grau. + // Damit wird auch in {@sse hueAmount()} eine Division durch Null verhindert. if ($this->maxRgbProperty === $this->minRgbProperty) { return 0.0; } @@ -105,30 +103,32 @@ class RedGreenBlueToHueSaturationValue */ private function hueAmount(string $property): float { - static $amount_share = 2.0; - + // Wertebereich: [0.0, 1.0] $divisor = $this->maxRgbProperty - $this->minRgbProperty; + // Wertebereich: [1.0, 5.0] + $amount = 0.0; + // Wertebereich: [-1.0, +1.0] + $dividend = 0.0; switch ($property) { case self::PROPERTY_RED: - $amount = 0; // 0.0 + $amount = 0.0; // 0.0 $dividend = $this->green - $this->blu; break; case self::PROPERTY_GREEN: - $amount = 1; // 0.333 + $amount = 2.0; // 0.333 $dividend = $this->blu -$this->red; break; case self::PROPERTY_BLUE: - $amount = 2; // 0.999 + $amount = 4.0; // 0.999 $dividend = $this->red - $this->green; break; - default: - return 0; } - $start_amount = $amount * $amount_share; + // Wertebereich: [-1.0, +1.0] $expansion_amount = $dividend / $divisor; - return ($start_amount + $expansion_amount) / 6.0; + // Wertebereich: [-1.0, +5.0] + return ($amount + $expansion_amount) / 6.0; } } \ No newline at end of file -- 2.54.0