14 Commits
Author SHA1 Message Date
TorstenHettstedt 8785508a67 Merge pull request 'refactor/texte-verbessern' (#11) from refactor/texte-verbessern into master
Reviewed-on: #11
2022-03-04 19:35:41 +01:00
Torstem_JetBrain c9540dc126 refactor: Texte überarbeiten 2022-03-04 19:33:25 +01:00
Torstem_JetBrain bd9eac43b2 feature: Erneuerung der benutzten PHP-Pakete 2022-03-04 19:24:58 +01:00
TorstenHettstedt 7a9c5dcf91 Merge pull request 'feature/natuerliche-tranformation' (#9) from feature/natuerliche-tranformation into master
Reviewed-on: #9
2022-03-04 18:07:42 +01:00
Torstem_JetBrain def8066374 refactor: kleinere Fehler Beseitigen 2022-03-03 16:05:51 +01:00
Torstem_JetBrain 49ef3b83f6 feature: natürliche Modellklassen können in andere Farbsysteme transformiert werden 2022-03-03 15:09:09 +01:00
Torstem_JetBrain 5941c17a8a tests: Tests für die Ausgabe der puren Modell-Klasse hinzufügen 2022-03-03 15:08:01 +01:00
Torstem_JetBrain 92cbb1eb46 tests: Tests für natürlichen Transformations-Klassen hinzufügen 2022-03-03 13:22:02 +01:00
Torstem_JetBrain 03d2680305 documentation: Die natürlichen Transformations-Klassen sind in ihrer Abhängigkeit und Darstellung definiert worden 2022-03-02 19:02:29 +01:00
TorstenHettstedt cc2e35e20f Merge pull request 'Feature: natuerliche Werte' (#8) from feature/natuerliche-werte into master
Reviewed-on: #8
2022-03-02 12:15:13 +01:00
Torstem_JetBrain 9505be376a refactor: Helfer-Klassen ersetzten eine abstrakte Klasse 2022-03-01 21:17:52 +01:00
Torstem_JetBrain 039d780d85 feature: natürlichen Werte-Klassen hinzufügen 2022-03-01 20:55:52 +01:00
Torstem_JetBrain ef824f64eb tests: Tests für natürlichen Werte-Klassen hinzufügen 2022-03-01 16:02:27 +01:00
Torstem_JetBrain 524fdbb268 documentation: Die neuen Modelle sind in ihrer Abhängigkeit und Darstellung definiert worden 2022-03-01 14:53:07 +01:00
34 changed files with 1605 additions and 39 deletions
+21 -1
View File
@@ -11,8 +11,28 @@ 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
[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.
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.
+2 -2
View File
@@ -28,7 +28,7 @@
"require-dev": {
"codeception/codeception": "^4.1.18",
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.0.0",
"phpstan/phpstan" : "^0.12.82"
"codeception/module-asserts": "^1.3.1",
"phpstan/phpstan" : "^1.4.7"
}
}
+77
View File
@@ -0,0 +1,77 @@
@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 NaturallyTransformer {
interface ColorModelTransformInterface {
+ toRedGreenBlue(): NaturallyColorModels.RedGreenBlue
+ toCyanMagentaYellowKey(): NaturallyColorModels.CyanMagentaYellowKey
+ toHueSaturationValue(): NaturallyColorModels.HueSaturationValue
}
class CyanMagentaYellowKeyTransformer
class HueSaturationValueTransformer
class 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
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
+3 -3
View File
@@ -9,11 +9,11 @@ namespace TorstenHettstedt\Colors\ColorModels;
*/
class CyanMagentaYellowKey extends AbstractColorModel
{
/** @var float : Definition des Cyan-Anteil */
/** @var float : Definition des Cyan-Anteils */
protected float $cyan = 0.0;
/** @var float : Definition des Magenta-Anteil */
/** @var float : Definition des Magenta-Anteils */
protected float $magenta = 0.0;
/** @var float : Definition des Gelbanteil */
/** @var float : Definition des Gelbanteiles */
protected float $yellow = 0.0;
/** @var float : Definition des Schwarzanteil */
protected float $key = 0.0;
+1 -1
View File
@@ -9,7 +9,7 @@ namespace TorstenHettstedt\Colors\ColorModels;
*/
class HueSaturationValue extends AbstractColorModel
{
/** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */
/** @var float : Definition des Farbtones als Anteil eines Vollkreises '$Hue * π' */
protected float $hue = 0.0;
/** @var float : Definition der Sättigung der Farbe */
protected float $saturation = 0.0;
+3 -3
View File
@@ -8,11 +8,11 @@ namespace TorstenHettstedt\Colors\ColorModels;
*/
class RedGreenBlue extends AbstractColorModel
{
/** @var float : Definition des Rotanteil */
/** @var float : Definition des Rot-Anteils */
protected float $red = 1.0;
/** @var float : Definition des Grünanteil */
/** @var float : Definition des Grün-Anteils */
protected float $green = 1.0;
/** @var float : Definition des Grünanteil */
/** @var float : Definition des Blau-Anteils */
protected float $blue = 1.0;
/**
@@ -0,0 +1,109 @@
<?php
namespace TorstenHettstedt\Colors\NaturallyColorModels;
use JetBrains\PhpStorm\Pure;
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey as PureCyanMagentaYellowKey;
/**
* 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
{
/** @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();
}
/**
* @return PureCyanMagentaYellowKey
*/
public function getPureColor(): PureCyanMagentaYellowKey
{
return $this->pureColor;
}
/**
* @return int
*/
#[Pure] public function getCyan(): int
{
return $this->percentValuesHelper->asPercentValue($this->pureColor->getCyan());
}
/**
* @param int $cyan
* @return CyanMagentaYellowKey
*/
public function setCyan(int $cyan): CyanMagentaYellowKey
{
$this->percentValuesHelper->checkPercentValue($cyan);
$this->pureColor->setCyan($this->percentValuesHelper->fromPercentValue($cyan));
return $this;
}
/**
* @return int
*/
#[Pure] public function getMagenta(): int
{
return $this->percentValuesHelper->asPercentValue($this->pureColor->getMagenta());
}
/**
* @param int $magenta
* @return CyanMagentaYellowKey
*/
public function setMagenta(int $magenta): CyanMagentaYellowKey
{
$this->percentValuesHelper->checkPercentValue($magenta);
$this->pureColor->setMagenta($this->percentValuesHelper->fromPercentValue($magenta));
return $this;
}
/**
* @return int
*/
#[Pure] public function getYellow(): int
{
return $this->percentValuesHelper->asPercentValue($this->pureColor->getYellow());
}
/**
* @param int $yellow
* @return CyanMagentaYellowKey
*/
public function setYellow(int $yellow): CyanMagentaYellowKey
{
$this->percentValuesHelper->checkPercentValue($yellow);
$this->pureColor->setYellow($this->percentValuesHelper->fromPercentValue($yellow));
return $this;
}
/**
* @return int
*/
#[Pure] public function getKey(): int
{
return $this->percentValuesHelper->asPercentValue($this->pureColor->getKey());
}
/**
* @param int $key
* @return CyanMagentaYellowKey
*/
public function setKey(int $key): CyanMagentaYellowKey
{
$this->percentValuesHelper->checkPercentValue($key);
$this->pureColor->setKey($this->percentValuesHelper->fromPercentValue($key));
return $this;
}
}
@@ -0,0 +1,31 @@
<?php
namespace TorstenHettstedt\Colors\NaturallyColorModels\Helper;
use InvalidArgumentException;
class GradValues
{
public function asGradValue(float $value): int
{
return intval(round($value * 360, 0, PHP_ROUND_HALF_UP));
}
public function fromGradValue(int $value): float
{
return $value / 360.0;
}
public 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.');
}
}
}
@@ -0,0 +1,31 @@
<?php
namespace TorstenHettstedt\Colors\NaturallyColorModels\Helper;
use InvalidArgumentException;
class HexadecimalValues
{
public function asHexadecimalValue(float $value): int
{
return intval($value * 0xFF);
}
public function fromHexadecimalValue(int $value): float
{
return $value / 0xFF;
}
public 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.');
}
}
}
@@ -0,0 +1,31 @@
<?php
namespace TorstenHettstedt\Colors\NaturallyColorModels\Helper;
use InvalidArgumentException;
class PercentValues
{
public function asPercentValue(float $value): int
{
return intval(round($value * 100, 0, PHP_ROUND_HALF_UP));
}
public function fromPercentValue(int $value): float
{
return $value / 100.0;
}
public function checkPercentValue(int $value): void
{
if ($value > 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.');
}
}
}
@@ -0,0 +1,94 @@
<?php
namespace TorstenHettstedt\Colors\NaturallyColorModels;
use JetBrains\PhpStorm\Pure;
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue as PureHueSaturationValue;
/**
* 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
{
/** @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();
}
/**
* @return PureHueSaturationValue
*/
public function getPureColor(): PureHueSaturationValue
{
return $this->pureColor;
}
/**
* @return int
*/
#[Pure] public function getHue(): int
{
return $this->gradValuesHelper->asGradValue($this->pureColor->getHue());
}
/**
* @param int $hue
* @return HueSaturationValue
*/
public function setHue(int $hue): HueSaturationValue
{
$this->gradValuesHelper->checkGradValue($hue);
$this->pureColor->setHue($this->gradValuesHelper->fromGradValue($hue));
return $this;
}
/**
* @return int
*/
#[Pure] public function getSaturation(): int
{
return $this->percentValuesHelper->asPercentValue($this->pureColor->getSaturation());
}
/**
* @param int $saturation
* @return HueSaturationValue
*/
public function setSaturation(int $saturation): HueSaturationValue
{
$this->percentValuesHelper->checkPercentValue($saturation);
$this->pureColor->setSaturation($this->percentValuesHelper->fromPercentValue($saturation));
return $this;
}
/**
* @return int
*/
#[Pure] public function getValue(): int
{
return $this->percentValuesHelper->asPercentValue($this->pureColor->getValue());
}
/**
* @param int $value
* @return HueSaturationValue
*/
public function setValue(int $value): HueSaturationValue
{
$this->percentValuesHelper->checkPercentValue($value);
$this->pureColor->setValue($this->percentValuesHelper->fromPercentValue($value));
return $this;
}
}
+94
View File
@@ -0,0 +1,94 @@
<?php
namespace TorstenHettstedt\Colors\NaturallyColorModels;
use JetBrains\PhpStorm\Pure;
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
{
/** @var PureRedGreenBlue : Standard-Color-Modell */
protected PureRedGreenBlue $pureColor;
protected Helper\HexadecimalValues $hexadecimalValuesHelper;
#[Pure] public function __construct()
{
$this->pureColor = new PureRedGreenBlue();
$this->hexadecimalValuesHelper = new Helper\HexadecimalValues();
}
/**
* @return PureRedGreenBlue
*/
public function getPureColor(): PureRedGreenBlue
{
return $this->pureColor;
}
/**
* @return int
*/
#[Pure] public function getRed(): int
{
return $this->hexadecimalValuesHelper->asHexadecimalValue($this->pureColor->getRed());
}
/**
* @param int $red
* @return RedGreenBlue
*/
public function setRed(int $red): RedGreenBlue
{
$this->hexadecimalValuesHelper->checkHexadecimalValue($red);
$this->pureColor->setRed($this->hexadecimalValuesHelper->fromHexadecimalValue($red));
return $this;
}
/**
* @return int
*/
#[Pure] public function getGreen(): int
{
return $this->hexadecimalValuesHelper->asHexadecimalValue($this->pureColor->getGreen());
}
/**
* @param int $green
* @return RedGreenBlue
*/
public function setGreen(int $green): RedGreenBlue
{
$this->hexadecimalValuesHelper->checkHexadecimalValue($green);
$this->pureColor->setGreen($this->hexadecimalValuesHelper->fromHexadecimalValue($green));
return $this;
}
/**
* @return int
*/
#[Pure] public function getBlue(): int
{
return $this->hexadecimalValuesHelper->asHexadecimalValue($this->pureColor->getBlue());
}
/**
* @param int $blue
* @return RedGreenBlue
*/
public function setBlue(int $blue): RedGreenBlue
{
$this->hexadecimalValuesHelper->checkHexadecimalValue($blue);
$this->pureColor->setBlue($this->hexadecimalValuesHelper->fromHexadecimalValue($blue));
return $this;
}
#[Pure] public function asHtmlNotation(): string
{
return sprintf('#%X%X%X', $this->getRed(), $this->getGreen(), $this->getBlue());
}
}
@@ -0,0 +1,54 @@
<?php
namespace TorstenHettstedt\Colors\NaturallyTransformer;
use TorstenHettstedt\Colors\NaturallyColorModels\CyanMagentaYellowKey;
use TorstenHettstedt\Colors\NaturallyColorModels\Helper\GradValues;
use TorstenHettstedt\Colors\NaturallyColorModels\Helper\HexadecimalValues;
use TorstenHettstedt\Colors\NaturallyColorModels\Helper\PercentValues;
use TorstenHettstedt\Colors\NaturallyColorModels\HueSaturationValue;
use TorstenHettstedt\Colors\NaturallyColorModels\RedGreenBlue;
use TorstenHettstedt\Colors\Transformer\ColorModelTransformInterface as PureTransformer;
class AbstractNaturallyTransformer implements ColorModelTransformInterface
{
protected PureTransformer $transformer;
public function toRedGreenBlue(): RedGreenBlue
{
$hex_helper = new HexadecimalValues();
$convert_color = $this->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;
}
}
@@ -0,0 +1,18 @@
<?php
namespace TorstenHettstedt\Colors\NaturallyTransformer;
use TorstenHettstedt\Colors\NaturallyColorModels\CyanMagentaYellowKey;
use TorstenHettstedt\Colors\NaturallyColorModels\HueSaturationValue;
use TorstenHettstedt\Colors\NaturallyColorModels\RedGreenBlue;
interface ColorModelTransformInterface
{
public function toRedGreenBlue(): RedGreenBlue;
public function toCyanMagentaYellowKey(): CyanMagentaYellowKey;
public function toHueSaturationValue(): HueSaturationValue;
}
@@ -0,0 +1,21 @@
<?php
namespace TorstenHettstedt\Colors\NaturallyTransformer;
use JetBrains\PhpStorm\Pure;
use TorstenHettstedt\Colors\NaturallyColorModels\CyanMagentaYellowKey;
use TorstenHettstedt\Colors\Transformer\CyanMagentaYellowKeyTransformer as PureTransformer;
class CyanMagentaYellowKeyTransformer extends AbstractNaturallyTransformer
{
/**
* @param CyanMagentaYellowKey $color
*/
#[Pure] public function __construct(CyanMagentaYellowKey $color)
{
$this->transformer = new PureTransformer($color->getPureColor());
}
}
@@ -0,0 +1,21 @@
<?php
namespace TorstenHettstedt\Colors\NaturallyTransformer;
use JetBrains\PhpStorm\Pure;
use TorstenHettstedt\Colors\NaturallyColorModels\HueSaturationValue;
use TorstenHettstedt\Colors\Transformer\HueSaturationValueTransformer as PureTransformer;
class HueSaturationValueTransformer extends AbstractNaturallyTransformer
{
/**
* @param HueSaturationValue $color
*/
#[Pure] public function __construct(HueSaturationValue $color)
{
$this->transformer = new PureTransformer($color->getPureColor());
}
}
@@ -0,0 +1,21 @@
<?php
namespace TorstenHettstedt\Colors\NaturallyTransformer;
use JetBrains\PhpStorm\Pure;
use TorstenHettstedt\Colors\NaturallyColorModels\RedGreenBlue;
use TorstenHettstedt\Colors\Transformer\RedGreenBlueTransformer as PureTransformer;
class RedGreenBlueTransformer extends AbstractNaturallyTransformer
{
/**
* @param RedGreenBlue $color
*/
#[Pure] public function __construct(RedGreenBlue $color)
{
$this->transformer = new PureTransformer($color->getPureColor());
}
}
@@ -8,11 +8,11 @@ use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
abstract class AbstractHueSaturationValueToUtility
{
/** @var int : Größe des Intervals in 1/100 Grad */
/** @var float : 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 * π' */
/** @var float : Definition des Farbtones als Anteil eines Vollkreises '$Hue * π' */
protected float $hue;
/** @var float : Anteil am Vollkreis in 1/100 Grad */
protected float $hueAsPercentGrad;
@@ -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;
@@ -15,11 +15,11 @@ class CyanMagentaYellowKeyToHueSaturationValue
const PROPERTY_KEY = 'key';
// Daten für CMYK
/** @var float : Definition des Cyan-Anteil */
/** @var float : Definition des Cyan-Anteils */
protected float $cyan;
/** @var float : Definition des Magenta-Anteil */
/** @var float : Definition des Magenta-Anteils */
protected float $magenta;
/** @var float : Definition des Gelbanteil */
/** @var float : Definition des Gelbanteils */
protected float $yellow;
/** @var float : Definition des Schwarzanteil */
protected float $key;
@@ -30,7 +30,7 @@ class CyanMagentaYellowKeyToHueSaturationValue
protected float $minCmyProperty;
// Daten für HSV
/** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */
/** @var float : Definition des Farbtones als Anteil eines Vollkreises '$Hue * π' */
protected float $hue = 0.0;
/** @var float : Definition der Sättigung der Farbe */
protected float $saturation = 0.0;
@@ -77,7 +77,7 @@ class CyanMagentaYellowKeyToHueSaturationValue
protected function buildHueAmount(): float
{
// Wenn beide Werte gleich sind, ist die Endfarbe Grau.
// Damit wird auch in {@sse hueAmount()} eine Division durch Null verhindert.
// Damit wird auch in {@sse hueAmount()} eine Division durch '0' verhindert.
if ($this->maxCmyProperty === $this->minCmyProperty) {
return 0.0;
}
@@ -9,11 +9,11 @@ use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
class HueSaturationValueToCyanMagentaYellowKey extends AbstractHueSaturationValueToUtility
{
// Daten für CMYK
/** @var float : Definition des Cyan-Anteil */
/** @var float : Definition des Cyan-Anteils */
protected float $cyan = 0.0;
/** @var float : Definition des Magenta-Anteil */
/** @var float : Definition des Magenta-Anteils */
protected float $magenta = 0.0;
/** @var float : Definition des Gelbanteil */
/** @var float : Definition des Gelbanteils */
protected float $yellow = 0.0;
/** @var float : Definition des Schwarzanteil */
protected float $key = 0.0;
@@ -9,11 +9,11 @@ use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
class HueSaturationValueToRedGreenBlue extends AbstractHueSaturationValueToUtility
{
// Daten für RGB
/** @var float : Definition des Rotanteil */
/** @var float : Definition des Rotanteils */
protected float $red = 1.0;
/** @var float : Definition des Grünanteil */
/** @var float : Definition des Grünanteils */
protected float $green = 1.0;
/** @var float : Definition des Blauanteil */
/** @var float : Definition des Blauanteils */
protected float $blue = 1.0;
public function convert(): RedGreenBlue
@@ -37,7 +37,7 @@ class HueSaturationValueToRedGreenBlue extends AbstractHueSaturationValueToUtili
{
// ID des zu nutzenden Interval
$interval_id = $this->hueAsPercentGrad / self::INTERVAL;
// Ist der Wert der entgegen gesetzten Farbe.
// der Wert der entgegen gesetzten Farbe
$opposite_color_value = $this->value * ( 1 - $this->saturation);
switch ((int)$interval_id) {
@@ -13,11 +13,11 @@ class RedGreenBlueToHueSaturationValue
const PROPERTY_BLUE = 'blue';
// Daten für RGB
/** @var float : Definition des Rotanteil */
/** @var float : Definition des Rot-Anteils */
protected float $red;
/** @var float : Definition des Grünanteil */
/** @var float : Definition des Grün-Anteils */
protected float $green;
/** @var float : Definition des Blauanteil */
/** @var float : Definition des Blau-Anteils */
protected float $blu;
/** @var float : Der größte RGB-Farbwert */
@@ -26,7 +26,7 @@ class RedGreenBlueToHueSaturationValue
protected float $minRgbProperty;
// Daten für HSV
/** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */
/** @var float : Definition des Farbtones als Anteil eines Vollkreises '$Hue * π' */
protected float $hue = 0.0;
/** @var float : Definition der Sättigung der Farbe */
protected float $saturation = 0.0;
@@ -75,7 +75,7 @@ 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.
// Damit wird auch in {@sse hueAmount()} eine Division durch '0' verhindert.
if ($this->maxRgbProperty === $this->minRgbProperty) {
return 0.0;
}
@@ -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:
@@ -12,7 +12,7 @@ class ValidColorValuesProvider
const HSV = 'hsv';
/**
* @var array<string, array<string, float>[]>
* @var array<string, array<array<string, float>>>
*/
protected array $definitions = [
'weiß' => [
@@ -308,7 +308,7 @@ class ValidColorValuesProvider
/**
* @param array<string> $order
*
* @return array<string, array<string, float>[]>
* @return array<string, array<array<string, float>>>
*/
public function getValidColorValues(array $order): array
{
@@ -0,0 +1,128 @@
<?php
namespace TorstenHettstedt\Colors\Tests\Helper;
class ValidNaturallyColorValuesProvider
{
const CMYK = 'cmyk';
const RGB = 'rgb';
const HSV = 'hsv';
/**
* @var array<string, array<array<string, float>>>
*/
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<string, array<array<string, float>>>
*/
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;
}
}
@@ -0,0 +1,82 @@
<?php /** @noinspection PhpArrayShapeAttributeCanBeAddedInspection */
namespace TorstenHettstedt\Colors\Tests\Unit\NaturallyColorModels;
use Codeception\Test\Unit;
abstract class AbstractColorModelUnit extends Unit
{
abstract public function testConstruct(): void;
/**
* @return int[][]
*/
public function invalidPercentValueProvider(): array
{
return [
'zu klein' => [-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],
];
}
}
@@ -0,0 +1,143 @@
<?php
namespace TorstenHettstedt\Colors\Tests\Unit\NaturallyColorModels;
use InvalidArgumentException;
use TorstenHettstedt\Colors\NaturallyColorModels\CyanMagentaYellowKey;
class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
{
public function testConstruct(): void
{
$color = new CyanMagentaYellowKey();
$this->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);
}
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());
}
}
@@ -0,0 +1,113 @@
<?php
namespace TorstenHettstedt\Colors\Tests\Unit\NaturallyColorModels;
use InvalidArgumentException;
use TorstenHettstedt\Colors\NaturallyColorModels\HueSaturationValue;
class HueSaturationValueTest extends AbstractColorModelUnit
{
public function testConstruct(): void
{
$color = new HueSaturationValue();
$this->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);
}
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());
}
}
@@ -0,0 +1,122 @@
<?php
namespace TorstenHettstedt\Colors\Tests\Unit\NaturallyColorModels;
use InvalidArgumentException;
use TorstenHettstedt\Colors\NaturallyColorModels\RedGreenBlue;
class RedGreenBlueTest extends AbstractColorModelUnit
{
public function testConstruct(): void
{
$color = new RedGreenBlue();
$this->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);
}
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());
}
}
@@ -0,0 +1,121 @@
<?php
namespace TorstenHettstedt\Colors\Tests\Unit\NaturallyTransformer;
use Codeception\Test\Unit;
use Exception;
use TorstenHettstedt\Colors\NaturallyColorModels\CyanMagentaYellowKey;
use TorstenHettstedt\Colors\Tests\Helper\ValidNaturallyColorValuesProvider;
use TorstenHettstedt\Colors\NaturallyTransformer\CyanMagentaYellowKeyTransformer;
class CyanMagentaYellowKeyTransformerTest extends Unit
{
protected CyanMagentaYellowKey $color;
/**
* @return array<string, array<array<string, float>>>
*/
public function validRgbValuesProvider(): array
{
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
ValidNaturallyColorValuesProvider::CMYK,
ValidNaturallyColorValuesProvider::RGB
);
}
/**
* @return array<string, array<array<string, float>>>
*/
public function validHsvValuesProvider(): array
{
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
ValidNaturallyColorValuesProvider::CMYK,
ValidNaturallyColorValuesProvider::HSV
);
}
/**
* @return array<string, array<array<string, float>>>
*/
public function validCmykValuesProvider(): array
{
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
ValidNaturallyColorValuesProvider::CMYK,
ValidNaturallyColorValuesProvider::CMYK
);
}
/**
* @param array<string, float> $pure_color
* @param array<string, float> $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<string, float> $pure_color
* @param array<string, float> $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<string, float> $pure_color
* @param array<string, float> $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());
}
}
@@ -0,0 +1,118 @@
<?php
namespace TorstenHettstedt\Colors\Tests\Unit\NaturallyTransformer;
use Codeception\Test\Unit;
use Exception;
use TorstenHettstedt\Colors\NaturallyColorModels\HueSaturationValue;
use TorstenHettstedt\Colors\Tests\Helper\ValidNaturallyColorValuesProvider;
use TorstenHettstedt\Colors\NaturallyTransformer\HueSaturationValueTransformer;
class HueSaturationValueTransformerTest extends Unit
{
protected HueSaturationValue $color;
/**
* @return array<string, array<array<string, float>>>
*/
public function validCmykValuesProvider(): array
{
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
ValidNaturallyColorValuesProvider::HSV,
ValidNaturallyColorValuesProvider::CMYK,
);
}
/**
* @return array<string, array<array<string, float>>>
*/
public function validRgbValuesProvider(): array
{
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
ValidNaturallyColorValuesProvider::HSV,
ValidNaturallyColorValuesProvider::RGB,
);
}
/**
* @return array<string, array<array<string, float>>>
*/
public function validHsvValuesProvider(): array
{
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
ValidNaturallyColorValuesProvider::HSV,
ValidNaturallyColorValuesProvider::HSV,
);
}
/**
* @param array<string, float> $pure_color
* @param array<string, float> $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<string, float> $pure_color
* @param array<string, float> $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<string, float> $pure_color
* @param array<string, float> $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());
}
}
@@ -0,0 +1,118 @@
<?php
namespace TorstenHettstedt\Colors\Tests\Unit\NaturallyTransformer;
use Codeception\Test\Unit;
use Exception;
use TorstenHettstedt\Colors\NaturallyColorModels\RedGreenBlue;
use TorstenHettstedt\Colors\Tests\Helper\ValidNaturallyColorValuesProvider;
use TorstenHettstedt\Colors\NaturallyTransformer\RedGreenBlueTransformer;
class RedGreenBlueTransformerTest extends Unit
{
protected RedGreenBlue $color;
/**
* @return array<string, array<array<string, float>>>
*/
public function validCmykValuesProvider(): array
{
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
ValidNaturallyColorValuesProvider::RGB,
ValidNaturallyColorValuesProvider::CMYK,
);
}
/**
* @return array<string, array<array<string, float>>>
*/
public function validHsvValuesProvider(): array
{
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
ValidNaturallyColorValuesProvider::RGB,
ValidNaturallyColorValuesProvider::HSV,
);
}
/**
* @return array<string, array<array<string, float>>>
*/
public function validRgbValuesProvider(): array
{
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
ValidNaturallyColorValuesProvider::RGB,
ValidNaturallyColorValuesProvider::RGB,
);
}
/**
* @param array<string, float> $pure_color
* @param array<string, float> $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<string, float> $pure_color
* @param array<string, float> $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<string, float> $pure_color
* @param array<string, float> $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());
}
}
@@ -16,7 +16,7 @@ class CyanMagentaYellowKeyTransformerTest extends Unit
protected CyanMagentaYellowKey $color;
/**
* @return array<string, array<string, float>[]>
* @return array<string, array<array<string, float>>>
*/
public function validRgbValuesProvider(): array
{
@@ -27,7 +27,7 @@ class CyanMagentaYellowKeyTransformerTest extends Unit
}
/**
* @return array<string, array<string, float>[]>
* @return array<string, array<array<string, float>>>
*/
public function validHsvValuesProvider(): array
{
@@ -16,7 +16,7 @@ class HueSaturationValueTransformerTest extends Unit
protected HueSaturationValue $color;
/**
* @return array<string, array<string, float>[]>
* @return array<string, array<array<string, float>>>
*/
public function validCmykValuesProvider(): array
{
@@ -27,7 +27,7 @@ class HueSaturationValueTransformerTest extends Unit
}
/**
* @return array<string, array<string, float>[]>
* @return array<string, array<array<string, float>>>
*/
public function validRgbValuesProvider(): array
{
@@ -16,7 +16,7 @@ class RedGreenBlueTransformerTest extends Unit
protected RedGreenBlue $color;
/**
* @return array<string, array<string, float>[]>
* @return array<string, array<array<string, float>>>
*/
public function validCmykValuesProvider(): array
{
@@ -27,7 +27,7 @@ class RedGreenBlueTransformerTest extends Unit
}
/**
* @return array<string, array<string, float>[]>
* @return array<string, array<array<string, float>>>
*/
public function validHsvValuesProvider(): array
{