Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc2e35e20f | ||
|
|
9505be376a | ||
|
|
039d780d85 | ||
|
|
ef824f64eb | ||
|
|
524fdbb268 | ||
|
|
802eb706f9 | ||
|
|
0642ffe48a | ||
|
|
0e033b1fbe | ||
|
|
6a26eb4608 | ||
|
|
15b425aa22 | ||
|
|
b363c26984 | ||
|
|
f7899d9f1e | ||
|
|
f890a9df67 | ||
|
|
c3aa392997 | ||
|
|
5288425e8d | ||
|
|
0e426b96e3 | ||
|
|
5ce7cf2552 | ||
|
|
753cac49c8 | ||
|
|
5e4f1f0bd8 | ||
|
|
44314b264e | ||
|
|
60c10f1d70 | ||
|
|
b6b366477d | ||
|
|
9c65840172 | ||
|
|
a20355ccee | ||
|
|
6f17e57424 | ||
|
|
6ca23ee2eb | ||
|
|
99c4e0dcc1 | ||
|
|
83eab10dd7 | ||
|
|
ad2a7ddd16 | ||
|
|
c949643d26 | ||
|
|
615cb0f655 | ||
|
|
6c4f5231c0 | ||
|
|
9bc53ed768 | ||
|
|
f8868ddd37 | ||
|
|
435dff067f | ||
|
|
692b8fa1c8 | ||
|
|
c832f0344c |
@@ -1,16 +0,0 @@
|
||||
# Farbmodelle und Farbsystemumwandler
|
||||
|
||||
## Zielstellung
|
||||
|
||||
Es existieren schon einige Projekte, die sich der Umwandlung von Farben kümmern. Doch aktuell gibt es kein Projekt, das für *PHP 8* geschrieben wurde.
|
||||
Deshalb soll das Projekt alle aktuell genutzten Farbmodelle Darstellen und ineinander umwandeln können.
|
||||
|
||||
## Hinweise zu den Modell-Klassen
|
||||
|
||||
Die Modelle müssen mit den Informationen gefüllt werden. Ein nicht geändertes Modell hat immer die Farbe Weiß.
|
||||
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.
|
||||
|
||||
## 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) auf.
|
||||
@@ -0,0 +1,34 @@
|
||||
# Farbmodelle und Farbsystemumwandler
|
||||
|
||||
## Zielstellung
|
||||
|
||||
Es existieren schon einige Projekte, die sich der Umwandlung von Farben kümmern. Doch aktuell gibt es kein Projekt, das für *PHP 8* geschrieben wurde.
|
||||
Deshalb soll das Projekt alle aktuell genutzten Farbmodelle Darstellen und ineinander umwandeln können.
|
||||
|
||||
## Hinweise zu den Modell-Klassen
|
||||
|
||||
Die Modelle müssen mit den Informationen gefüllt werden. Ein nicht geändertes Modell hat immer die Farbe Weiß.
|
||||
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.
|
||||
@@ -0,0 +1,14 @@
|
||||
paths:
|
||||
tests: tests
|
||||
output: tests/_output
|
||||
data: tests/_data
|
||||
support: tests/_support
|
||||
envs: tests/_envs
|
||||
actor_suffix: Tester
|
||||
extensions:
|
||||
enabled:
|
||||
- Codeception\Extension\RunFailed
|
||||
coverage:
|
||||
enabled: true
|
||||
include:
|
||||
- src/*
|
||||
+8
-4
@@ -16,15 +16,19 @@
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"TorstenHettstedtUnitTests\\Colors\\" : "tests/unit"
|
||||
"TorstenHettstedt\\Colors\\Tests\\Unit\\" : "tests/unit",
|
||||
"TorstenHettstedt\\Colors\\Tests\\Helper\\" : "tests/_support/Helper"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": "^8.0"
|
||||
"php": "^8.0",
|
||||
"phpunit/php-code-coverage": "^9.2",
|
||||
"jetbrains/phpstorm-attributes": "^1.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"codeception/codeception": "^4.1.18",
|
||||
"codeception/module-phpbrowser": "^1.0.0",
|
||||
"codeception/module-asserts": "^1.0.0"
|
||||
"codeception/module-asserts": "^1.0.0",
|
||||
"phpstan/phpstan" : "^0.12.82"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
parameters:
|
||||
level: 6
|
||||
paths:
|
||||
- src
|
||||
- tests/unit
|
||||
- tests/_support/Helper
|
||||
@@ -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
|
||||
@@ -8,7 +8,7 @@ use InvalidArgumentException;
|
||||
abstract class AbstractColorModel
|
||||
{
|
||||
|
||||
protected function checkValue(float $value)
|
||||
protected function checkValue(float $value): void
|
||||
{
|
||||
if ($value > 1.0) {
|
||||
throw new InvalidArgumentException('Ein Wert größer als 1 ist nicht definierbar.');
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<?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 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($value * 360);
|
||||
}
|
||||
|
||||
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($value * 100);
|
||||
}
|
||||
|
||||
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,86 @@
|
||||
<?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 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?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 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
public function asHtmlNotation(): string
|
||||
{
|
||||
return sprintf('#%X%X%X', $this->getRed(), $this->getGreen(), $this->getBlue());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace TorstenHettstedt\Colors\Transformer;
|
||||
|
||||
|
||||
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
|
||||
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
|
||||
use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
|
||||
|
||||
class HueSaturationValueTransformer implements ColorModelTransformInterface
|
||||
{
|
||||
|
||||
protected HueSaturationValue $color;
|
||||
|
||||
/**
|
||||
* @param HueSaturationValue $color
|
||||
*/
|
||||
public function __construct(HueSaturationValue $color)
|
||||
{
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
|
||||
public function toRedGreenBlue(): RedGreenBlue
|
||||
{
|
||||
$utility = new Utilities\HueSaturationValueToRedGreenBlue($this->color);
|
||||
return $utility->convert();
|
||||
}
|
||||
|
||||
public function toCyanMagentaYellowKey(): CyanMagentaYellowKey
|
||||
{
|
||||
$utility = new Utilities\HueSaturationValueToCyanMagentaYellowKey($this->color);
|
||||
return $utility->convert();
|
||||
}
|
||||
|
||||
public function toHueSaturationValue(): HueSaturationValue
|
||||
{
|
||||
return clone $this->color;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace TorstenHettstedt\Colors\Transformer;
|
||||
|
||||
|
||||
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
|
||||
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
|
||||
use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
|
||||
|
||||
class RedGreenBlueTransformer implements ColorModelTransformInterface
|
||||
{
|
||||
|
||||
protected RedGreenBlue $color;
|
||||
|
||||
/**
|
||||
* @param RedGreenBlue $color
|
||||
*/
|
||||
public function __construct(RedGreenBlue $color)
|
||||
{
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
|
||||
public function toRedGreenBlue(): RedGreenBlue
|
||||
{
|
||||
return clone $this->color;
|
||||
}
|
||||
|
||||
public function toCyanMagentaYellowKey(): CyanMagentaYellowKey
|
||||
{
|
||||
$hsv_color = (new Utilities\RedGreenBlueToHueSaturationValue($this->color))->convert();
|
||||
$utility = new Utilities\HueSaturationValueToCyanMagentaYellowKey($hsv_color);
|
||||
return $utility->convert();
|
||||
}
|
||||
|
||||
public function toHueSaturationValue(): HueSaturationValue
|
||||
{
|
||||
$utility = new Utilities\RedGreenBlueToHueSaturationValue($this->color);
|
||||
return $utility->convert();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace TorstenHettstedt\Colors\Transformer\Utilities;
|
||||
|
||||
|
||||
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
|
||||
|
||||
abstract class 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;
|
||||
|
||||
/**
|
||||
* 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.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;
|
||||
|
||||
/**
|
||||
* @param bool $reciprocal
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace TorstenHettstedt\Colors\Transformer\Utilities;
|
||||
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
|
||||
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
|
||||
|
||||
@@ -55,6 +56,9 @@ class CyanMagentaYellowKeyToHueSaturationValue
|
||||
$this->minCmyProperty = min($this->cyan, $this->magenta, $this->yellow);
|
||||
|
||||
$this->hue = $this->buildHueAmount();
|
||||
if ($this->hue === 1.0) {
|
||||
$this->hue = 0.0;
|
||||
}
|
||||
$this->saturation = $this->maxCmyProperty;
|
||||
$this->value = 1 - $this->key;
|
||||
}
|
||||
@@ -69,9 +73,12 @@ class CyanMagentaYellowKeyToHueSaturationValue
|
||||
->setValue($this->value);
|
||||
}
|
||||
|
||||
#[Pure]
|
||||
protected function buildHueAmount(): float
|
||||
{
|
||||
if ($this->maxCmyProperty === 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;
|
||||
}
|
||||
|
||||
@@ -88,34 +95,32 @@ class CyanMagentaYellowKeyToHueSaturationValue
|
||||
*/
|
||||
private function hueAmount(string $property): float
|
||||
{
|
||||
if ($this->maxCmyProperty === 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace TorstenHettstedt\Colors\Transformer\Utilities;
|
||||
|
||||
|
||||
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
|
||||
|
||||
class HueSaturationValueToCyanMagentaYellowKey extends AbstractHueSaturationValueToUtility
|
||||
{
|
||||
// Daten für CMYK
|
||||
/** @var float : Definition des Cyan-Anteil */
|
||||
protected float $cyan = 0.0;
|
||||
/** @var float : Definition des Magenta-Anteil */
|
||||
protected float $magenta = 0.0;
|
||||
/** @var float : Definition des Gelbanteil */
|
||||
protected float $yellow = 0.0;
|
||||
/** @var float : Definition des Schwarzanteil */
|
||||
protected float $key = 0.0;
|
||||
|
||||
public function convert(): CyanMagentaYellowKey
|
||||
{
|
||||
$this->processConvert();
|
||||
|
||||
return (new CyanMagentaYellowKey())
|
||||
->setCyan($this->cyan)
|
||||
->setMagenta($this->magenta)
|
||||
->setYellow($this->yellow)
|
||||
->setKey($this->key);
|
||||
}
|
||||
|
||||
|
||||
protected function processConvert(): void
|
||||
{
|
||||
$this->key = 1 - $this->value;
|
||||
parent::processConvert();
|
||||
}
|
||||
|
||||
protected function splitColor(): void
|
||||
{
|
||||
// ID des zu nutzenden Interval
|
||||
$interval_id = $this->hueAsPercentGrad / self::INTERVAL;
|
||||
|
||||
switch ((int)$interval_id) {
|
||||
case 1: // Yellow
|
||||
$this->cyan = $this->calcColorValue();
|
||||
$this->yellow = $this->saturation;
|
||||
break;
|
||||
case 2:
|
||||
$this->cyan = $this->saturation;
|
||||
$this->yellow = $this->calcColorValue(true);
|
||||
break;
|
||||
case 3: // Cyan
|
||||
$this->cyan = $this->saturation;
|
||||
$this->magenta = $this->calcColorValue();
|
||||
break;
|
||||
case 4:
|
||||
$this->cyan = $this->calcColorValue(true);
|
||||
$this->magenta = $this->saturation;
|
||||
break;
|
||||
case 5: // Magenta
|
||||
$this->magenta = $this->saturation;
|
||||
$this->yellow = $this->calcColorValue();
|
||||
break;
|
||||
default:
|
||||
$this->magenta = $this->calcColorValue(true);
|
||||
$this->yellow = $this->saturation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,41 +4,17 @@
|
||||
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 * 100;
|
||||
|
||||
// Daten für HSV
|
||||
/** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */
|
||||
protected float $hue;
|
||||
/** @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;
|
||||
/** @var float : Definition des Grünanteil */
|
||||
protected float $green = 1.0;
|
||||
/** @var float : Definition des Blauanteil */
|
||||
protected float $blu = 1.0;
|
||||
|
||||
/**
|
||||
* HueSaturationValueToRedGreenBlue constructor.
|
||||
* @param HueSaturationValue $from_color
|
||||
* @noinspection PhpPureAttributeCanBeAddedInspection
|
||||
*/
|
||||
public function __construct(HueSaturationValue $from_color)
|
||||
{
|
||||
$this->hue = $from_color->getHue();
|
||||
$this->saturation = $from_color->getSaturation();
|
||||
$this->value = $from_color->getValue();
|
||||
}
|
||||
protected float $blue = 1.0;
|
||||
|
||||
public function convert(): RedGreenBlue
|
||||
{
|
||||
@@ -47,65 +23,56 @@ class HueSaturationValueToRedGreenBlue
|
||||
return (new RedGreenBlue())
|
||||
->setRed($this->red)
|
||||
->setGreen($this->green)
|
||||
->setBlue($this->blu);
|
||||
->setBlue($this->blue);
|
||||
}
|
||||
|
||||
|
||||
protected function processConvert(): void
|
||||
{
|
||||
if ($this->saturation === 0.0) {
|
||||
$this->red = $this->green = $this->blu = $this->value;
|
||||
} else {
|
||||
$this->splitColor();
|
||||
}
|
||||
$this->red = $this->green = $this->blue = $this->value;
|
||||
parent::processConvert();
|
||||
}
|
||||
|
||||
protected function splitColor(): void
|
||||
{
|
||||
// Anteil am Vollkreis in 1/100 Grad
|
||||
$percent_grad = intval($this->hue * 360 * 100);
|
||||
// ID des zu nutzenden Interval
|
||||
$interval_id = intdiv($percent_grad , self::INTERVAL);
|
||||
// Rest-Anteil am Vollkreis des aktuellen Intervals als Wert '[0,1]'
|
||||
$remainder = (($percent_grad % self::INTERVAL) / self::INTERVAL);
|
||||
$help_values = [
|
||||
$this->value,
|
||||
$this->value * ( 1 - $this->saturation),
|
||||
$this->value * ( 1 - $this->saturation * $remainder),
|
||||
$this->value * ( 1 - $this->saturation * (1 - $remainder)),
|
||||
];
|
||||
switch ($interval_id) {
|
||||
$interval_id = $this->hueAsPercentGrad / self::INTERVAL;
|
||||
// Ist der Wert der entgegen gesetzten Farbe.
|
||||
$opposite_color_value = $this->value * ( 1 - $this->saturation);
|
||||
|
||||
switch ((int)$interval_id) {
|
||||
case 1:
|
||||
$this->red = $help_values[2];
|
||||
$this->green = $help_values[0];
|
||||
$this->blu = $help_values[1];
|
||||
$this->red = $this->calcColorValue();
|
||||
$this->blue = $opposite_color_value;
|
||||
break;
|
||||
case 2:
|
||||
$this->red = $help_values[1];
|
||||
$this->green = $help_values[0];
|
||||
$this->blu = $help_values[3];
|
||||
case 2: // Green
|
||||
$this->red = $opposite_color_value;
|
||||
$this->blue = $this->calcColorValue(true);
|
||||
break;
|
||||
case 3:
|
||||
$this->red = $help_values[1];
|
||||
$this->green = $help_values[2];
|
||||
$this->blu = $help_values[0];
|
||||
$this->red = $opposite_color_value;
|
||||
$this->green = $this->calcColorValue();
|
||||
break;
|
||||
case 4:
|
||||
$this->red = $help_values[3];
|
||||
$this->green = $help_values[1];
|
||||
$this->blu = $help_values[0];
|
||||
case 4: // Blue
|
||||
$this->red = $this->calcColorValue(true);
|
||||
$this->green = $opposite_color_value;
|
||||
break;
|
||||
case 5:
|
||||
$this->red = $help_values[0];
|
||||
$this->green = $help_values[1];
|
||||
$this->blu = $help_values[2];
|
||||
$this->green = $opposite_color_value;
|
||||
$this->blue = $this->calcColorValue();
|
||||
break;
|
||||
default:
|
||||
$this->red = $help_values[0];
|
||||
$this->green = $help_values[3];
|
||||
$this->blu = $help_values[1];
|
||||
default: // Red
|
||||
$this->green = $this->calcColorValue(true);
|
||||
$this->blue = $opposite_color_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function calcColorValue($reciprocal = false): float
|
||||
{
|
||||
$color_value = $this->value;
|
||||
$color_value *= 1 - parent::calcColorValue($reciprocal);
|
||||
return $color_value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedt\Colors\Transformer\Utilities;
|
||||
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
|
||||
use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
|
||||
|
||||
class RedGreenBlueToHueSaturationValue
|
||||
{
|
||||
const PROPERTY_RED = 'red';
|
||||
const PROPERTY_GREEN = 'green';
|
||||
const PROPERTY_BLUE = 'blue';
|
||||
|
||||
// Daten für RGB
|
||||
/** @var float : Definition des Rotanteil */
|
||||
protected float $red;
|
||||
/** @var float : Definition des Grünanteil */
|
||||
protected float $green;
|
||||
/** @var float : Definition des Blauanteil */
|
||||
protected float $blu;
|
||||
|
||||
/** @var float : Der größte RGB-Farbwert */
|
||||
protected float $maxRgbProperty;
|
||||
/** @var float : Der kleinste RGB-Farbwert */
|
||||
protected float $minRgbProperty;
|
||||
|
||||
// Daten für HSV
|
||||
/** @var float : Definition des Farbton als Anteil eines Vollkreises '$Hue * π' */
|
||||
protected float $hue = 0.0;
|
||||
/** @var float : Definition der Sättigung der Farbe */
|
||||
protected float $saturation = 0.0;
|
||||
/** @var float : Definition der Helligkeit der Farbe */
|
||||
protected float $value = 1.0;
|
||||
|
||||
/**
|
||||
* CyanMagentaYellowKeyToHueSaturationValue constructor.
|
||||
*
|
||||
* @param RedGreenBlue $from_color
|
||||
*
|
||||
* @noinspection PhpPureAttributeCanBeAddedInspection
|
||||
*/
|
||||
public function __construct(RedGreenBlue $from_color)
|
||||
{
|
||||
$this->red = $from_color->getRed();
|
||||
$this->green = $from_color->getGreen();
|
||||
$this->blu = $from_color->getBlue();
|
||||
}
|
||||
|
||||
protected function processConvert(): void
|
||||
{
|
||||
$this->maxRgbProperty = max($this->red, $this->green, $this->blu);
|
||||
$this->minRgbProperty = min($this->red, $this->green, $this->blu);
|
||||
|
||||
$this->hue = $this->buildHueAmount();
|
||||
$this->saturation = $this->buildSaturation();
|
||||
$this->value = $this->maxRgbProperty;
|
||||
|
||||
while($this->hue < 0.0) {
|
||||
$this->hue += 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
public function convert(): HueSaturationValue
|
||||
{
|
||||
$this->processConvert();
|
||||
|
||||
return (new HueSaturationValue())
|
||||
->setHue($this->hue)
|
||||
->setSaturation($this->saturation)
|
||||
->setValue($this->value);
|
||||
}
|
||||
|
||||
#[Pure]
|
||||
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;
|
||||
}
|
||||
|
||||
return match ($this->maxRgbProperty) {
|
||||
$this->red => $this->hueAmount(self::PROPERTY_RED),
|
||||
$this->green => $this->hueAmount(self::PROPERTY_GREEN),
|
||||
default => $this->hueAmount(self::PROPERTY_BLUE),
|
||||
};
|
||||
}
|
||||
|
||||
protected function buildSaturation(): float
|
||||
{
|
||||
if ($this->maxRgbProperty === 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$dividend = $this->maxRgbProperty - $this->minRgbProperty;
|
||||
|
||||
return $dividend / $this->maxRgbProperty;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $property : Name der CMYK-Eigenschaft
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
private function hueAmount(string $property): float
|
||||
{
|
||||
// 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.0
|
||||
$dividend = $this->green - $this->blu;
|
||||
break;
|
||||
case self::PROPERTY_GREEN:
|
||||
$amount = 2.0; // 0.333
|
||||
$dividend = $this->blu -$this->red;
|
||||
break;
|
||||
case self::PROPERTY_BLUE:
|
||||
$amount = 4.0; // 0.999
|
||||
$dividend = $this->red - $this->green;
|
||||
break;
|
||||
}
|
||||
|
||||
// Wertebereich: [-1.0, +1.0]
|
||||
$expansion_amount = $dividend / $divisor;
|
||||
// Wertebereich: [-1.0, +5.0]
|
||||
return ($amount + $expansion_amount) / 6.0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace TorstenHettstedt\Colors\Tests\Helper;
|
||||
|
||||
|
||||
class ValidColorValuesProvider
|
||||
{
|
||||
|
||||
const CMYK = 'cmyk';
|
||||
const RGB = 'rgb';
|
||||
const HSV = 'hsv';
|
||||
|
||||
/**
|
||||
* @var array<string, array<string, float>[]>
|
||||
*/
|
||||
protected array $definitions = [
|
||||
'weiß' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 1.0,
|
||||
'green' => 1.0,
|
||||
'blue' => 1.0,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 0.0,
|
||||
'saturation' => 0.0,
|
||||
'value' => 1.0,
|
||||
],
|
||||
],
|
||||
'hellgrau' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 2.0 / 3.0,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 1.0 / 3.0,
|
||||
'green' => 1.0 / 3.0,
|
||||
'blue' => 1.0 / 3.0,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 0.0,
|
||||
'saturation' => 0.0,
|
||||
'value' => 1.0 / 3.0,
|
||||
],
|
||||
],
|
||||
'dunkelgrau' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 1.0 / 3.0,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 2.0 / 3.0,
|
||||
'green' => 2.0 / 3.0,
|
||||
'blue' => 2.0 / 3.0,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 0.0,
|
||||
'saturation' => 0.0,
|
||||
'value' => 2.0 / 3.0,
|
||||
],
|
||||
],
|
||||
'schwarz' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 1.0,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 0.0,
|
||||
'green' => 0.0,
|
||||
'blue' => 0.0,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 0.0,
|
||||
'saturation' => 0.0,
|
||||
'value' => 0.0,
|
||||
],
|
||||
],
|
||||
'gelb' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 1.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 1.0,
|
||||
'green' => 1.0,
|
||||
'blue' => 0.0,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 1.0 / 6.0,
|
||||
'saturation' => 1.0,
|
||||
'value' => 1.0,
|
||||
],
|
||||
],
|
||||
'grün' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 1.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 1.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 0.0,
|
||||
'green' => 1.0,
|
||||
'blue' => 0.0,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 2.0 / 6.0,
|
||||
'saturation' => 1.0,
|
||||
'value' => 1.0,
|
||||
],
|
||||
],
|
||||
'cyan' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 1.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 0.0,
|
||||
'green' => 1.0,
|
||||
'blue' => 1.0,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 3.0 / 6.0,
|
||||
'saturation' => 1.0,
|
||||
'value' => 1.0,
|
||||
],
|
||||
],
|
||||
'blau' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 1.0,
|
||||
'magenta' => 1.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 0.0,
|
||||
'green' => 0.0,
|
||||
'blue' => 1.0,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 4.0 / 6.0,
|
||||
'saturation' => 1.0,
|
||||
'value' => 1.0,
|
||||
],
|
||||
],
|
||||
'magenta' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 1.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 1.0,
|
||||
'green' => 0.0,
|
||||
'blue' => 1.0,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 5.0 / 6.0,
|
||||
'saturation' => 1.0,
|
||||
'value' => 1.0,
|
||||
],
|
||||
],
|
||||
'rot' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 1.0,
|
||||
'yellow' => 1.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 1.0,
|
||||
'green' => 0.0,
|
||||
'blue' => 0.0,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 0.0,
|
||||
'saturation' => 1.0,
|
||||
'value' => 1.0,
|
||||
],
|
||||
],
|
||||
'dunkellachs' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.54,
|
||||
'yellow' => 0.72,
|
||||
'key' => 0.30,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 0.7,
|
||||
'green' => 0.3216,
|
||||
'blue' => 0.1961,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 0.0417,
|
||||
'saturation' => 0.72,
|
||||
'value' => 0.70,
|
||||
],
|
||||
],
|
||||
'gold' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.13,
|
||||
'yellow' => 0.76,
|
||||
'key' => 0.13,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 0.87,
|
||||
'green' => 0.757,
|
||||
'blue' => 0.209,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 0.138,
|
||||
'saturation' => 0.76,
|
||||
'value' => 0.87,
|
||||
],
|
||||
],
|
||||
'grasgrün' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.495,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 1.0,
|
||||
'key' => 0.51,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 0.247,
|
||||
'green' => 0.490,
|
||||
'blue' => 0.0,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 0.2492,
|
||||
'saturation' => 1.00,
|
||||
'value' => 0.49,
|
||||
],
|
||||
],
|
||||
'aquamarin' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.501,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 0.168,
|
||||
'key' => 0.00,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 0.49804,
|
||||
'green' => 1.0,
|
||||
'blue' => 0.83285,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 0.4445,
|
||||
'saturation' => 0.50196,
|
||||
'value' => 1.0,
|
||||
],
|
||||
],
|
||||
'violet' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.191,
|
||||
'magenta' => 0.321,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.29,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 0.575,
|
||||
'green' => 0.482,
|
||||
'blue' => 0.71,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 0.734,
|
||||
'saturation' => 0.321,
|
||||
'value' => 0.71,
|
||||
],
|
||||
],
|
||||
'pflaume' => [
|
||||
self::CMYK => [
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.2755,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.1335,
|
||||
],
|
||||
self::RGB => [
|
||||
'red' => 0.8667,
|
||||
'green' => 0.6274,
|
||||
'blue' => 0.8667,
|
||||
],
|
||||
self::HSV => [
|
||||
'hue' => 0.83333,
|
||||
'saturation' => 0.27601,
|
||||
'value' => 0.86666,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* @param array<string> $order
|
||||
*
|
||||
* @return array<string, array<string, float>[]>
|
||||
*/
|
||||
public function getValidColorValues(array $order): array
|
||||
{
|
||||
$values = [];
|
||||
foreach ($this->definitions as $color => $definition) {
|
||||
$definitions = [];
|
||||
foreach ($order as $key) {
|
||||
$definitions[] = $definition[$key];
|
||||
}
|
||||
$values[$color] = $definitions;
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
<?php /** @noinspection PhpArrayShapeAttributeCanBeAddedInspection */
|
||||
|
||||
|
||||
namespace TorstenHettstedtUnitTests\Colors\ColorModels;
|
||||
namespace TorstenHettstedt\Colors\Tests\Unit\ColorModels;
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
|
||||
abstract class AbstractColorModelUnit extends Unit
|
||||
{
|
||||
|
||||
abstract public function testConstruct();
|
||||
abstract public function testConstruct(): void;
|
||||
|
||||
/**
|
||||
* @return float[][]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedtUnitTests\Colors\ColorModels;
|
||||
namespace TorstenHettstedt\Colors\Tests\Unit\ColorModels;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
|
||||
@@ -8,7 +8,7 @@ use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
|
||||
class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
|
||||
{
|
||||
|
||||
public function testConstruct()
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
@@ -23,7 +23,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetCyanWithValidValue(float $value)
|
||||
public function testSetCyanWithValidValue(float $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
@@ -36,7 +36,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetMagentaWithValidValue(float $value)
|
||||
public function testSetMagentaWithValidValue(float $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
@@ -49,7 +49,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetYellowWithValidValue(float $value)
|
||||
public function testSetYellowWithValidValue(float $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
@@ -62,7 +62,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetKeyWithValidValue(float $value)
|
||||
public function testSetKeyWithValidValue(float $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
@@ -75,7 +75,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetCyanWithInvalidValue(float $value)
|
||||
public function testSetCyanWithInvalidValue(float $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
@@ -88,7 +88,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetMagentaWithInvalidValue(float $value)
|
||||
public function testSetMagentaWithInvalidValue(float $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
@@ -101,7 +101,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetYellowWithInvalidValue(float $value)
|
||||
public function testSetYellowWithInvalidValue(float $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
@@ -114,7 +114,7 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetKeyWithInvalidValue(float $value)
|
||||
public function testSetKeyWithInvalidValue(float $value): void
|
||||
{
|
||||
$color = new CyanMagentaYellowKey();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedtUnitTests\Colors\ColorModels;
|
||||
namespace TorstenHettstedt\Colors\Tests\Unit\ColorModels;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
|
||||
@@ -8,7 +8,7 @@ use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
|
||||
class HueSaturationValueTest extends AbstractColorModelUnit
|
||||
{
|
||||
|
||||
public function testConstruct()
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
@@ -22,7 +22,7 @@ class HueSaturationValueTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetHueWithValidValue(float $value)
|
||||
public function testSetHueWithValidValue(float $value): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
@@ -35,7 +35,7 @@ class HueSaturationValueTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetHueWithInvalidValue(float $value)
|
||||
public function testSetHueWithInvalidValue(float $value): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
@@ -48,7 +48,7 @@ class HueSaturationValueTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetSaturationWithValidValue(float $value)
|
||||
public function testSetSaturationWithValidValue(float $value): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
@@ -61,7 +61,7 @@ class HueSaturationValueTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetSaturationWithInvalidValue(float $value)
|
||||
public function testSetSaturationWithInvalidValue(float $value): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
@@ -74,7 +74,7 @@ class HueSaturationValueTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetValueWithValidValue(float $value)
|
||||
public function testSetValueWithValidValue(float $value): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
@@ -87,7 +87,7 @@ class HueSaturationValueTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetValueWithInvalidValue(float $value)
|
||||
public function testSetValueWithInvalidValue(float $value): void
|
||||
{
|
||||
$color = new HueSaturationValue();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php /** @noinspection PhpArrayShapeAttributeCanBeAddedInspection */
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedtUnitTests\Colors\ColorModels;
|
||||
namespace TorstenHettstedt\Colors\Tests\Unit\ColorModels;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
|
||||
@@ -8,7 +8,7 @@ use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
|
||||
class RedGreenBlueTest extends AbstractColorModelUnit
|
||||
{
|
||||
|
||||
public function testConstruct()
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
@@ -22,7 +22,7 @@ class RedGreenBlueTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetRedWithValidValue(float $value)
|
||||
public function testSetRedWithValidValue(float $value): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
@@ -35,7 +35,7 @@ class RedGreenBlueTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetRedWithInvalidValue(float $value)
|
||||
public function testSetRedWithInvalidValue(float $value): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
@@ -47,7 +47,7 @@ class RedGreenBlueTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetGreenWithValidValue(float $value)
|
||||
public function testSetGreenWithValidValue(float $value): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
@@ -60,7 +60,7 @@ class RedGreenBlueTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetGreenWithInvalidValue(float $value)
|
||||
public function testSetGreenWithInvalidValue(float $value): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
@@ -73,7 +73,7 @@ class RedGreenBlueTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider validValueProvider
|
||||
*/
|
||||
public function testSetBlueWithValidValue(float $value)
|
||||
public function testSetBlueWithValidValue(float $value): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
@@ -86,7 +86,7 @@ class RedGreenBlueTest extends AbstractColorModelUnit
|
||||
*
|
||||
* @dataProvider invalidValueProvider
|
||||
*/
|
||||
public function testSetBlueWithInvalidValue(float $value)
|
||||
public function testSetBlueWithInvalidValue(float $value): void
|
||||
{
|
||||
$color = new RedGreenBlue();
|
||||
|
||||
|
||||
@@ -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,128 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
<?php /** @noinspection PhpArrayShapeAttributeCanBeAddedInspection */
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedtUnitTests\Colors\Transformer;
|
||||
namespace TorstenHettstedt\Colors\Tests\Unit\Transformer;
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
use Exception;
|
||||
use TorstenHettstedt\Colors\ColorModels\CyanMagentaYellowKey;
|
||||
use TorstenHettstedt\Colors\Tests\Helper\ValidColorValuesProvider;
|
||||
use TorstenHettstedt\Colors\Transformer\CyanMagentaYellowKeyTransformer;
|
||||
|
||||
class CyanMagentaYellowKeyTransformerTest extends Unit
|
||||
@@ -15,214 +16,36 @@ class CyanMagentaYellowKeyTransformerTest extends Unit
|
||||
protected CyanMagentaYellowKey $color;
|
||||
|
||||
/**
|
||||
* @return float[][][]
|
||||
* @return array<string, array<string, float>[]>
|
||||
*/
|
||||
public function validRgbValuesProvider(): array
|
||||
{
|
||||
return [
|
||||
'weiß' => [
|
||||
[
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
[
|
||||
'red' => 1.0,
|
||||
'green' => 1.0,
|
||||
'blue' => 1.0,
|
||||
]
|
||||
],
|
||||
'schwarz' => [
|
||||
[
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 1.0,
|
||||
],
|
||||
[
|
||||
'red' => 0.0,
|
||||
'green' => 0.0,
|
||||
'blue' => 0.0,
|
||||
]
|
||||
],
|
||||
'cyan' => [
|
||||
[
|
||||
'cyan' => 1.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
[
|
||||
'red' => 0.0,
|
||||
'green' => 1.0,
|
||||
'blue' => 1.0,
|
||||
]
|
||||
],
|
||||
'magenta' => [
|
||||
[
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 1.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
[
|
||||
'red' => 1.0,
|
||||
'green' => 0.0,
|
||||
'blue' => 1.0,
|
||||
]
|
||||
],
|
||||
'gelb' => [
|
||||
[
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 1.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
[
|
||||
'red' => 1.0,
|
||||
'green' => 1.0,
|
||||
'blue' => 0.0,
|
||||
]
|
||||
],
|
||||
'gold' => [
|
||||
[
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.13,
|
||||
'yellow' => 0.76,
|
||||
'key' => 0.13,
|
||||
],
|
||||
[
|
||||
'red' => 0.87,
|
||||
'green' => 0.757,
|
||||
'blue' => 0.209,
|
||||
]
|
||||
],
|
||||
'violet' => [
|
||||
[
|
||||
'cyan' => 0.19,
|
||||
'magenta' => 0.32,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.29,
|
||||
],
|
||||
[
|
||||
'red' => 0.575,
|
||||
'green' => 0.482,
|
||||
'blue' => 0.71,
|
||||
]
|
||||
],
|
||||
];
|
||||
return (new ValidColorValuesProvider())->getValidColorValues([
|
||||
ValidColorValuesProvider::CMYK,
|
||||
ValidColorValuesProvider::RGB
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float[][][]
|
||||
* @return array<string, array<string, float>[]>
|
||||
*/
|
||||
public function validHsvValuesProvider(): array
|
||||
{
|
||||
return [
|
||||
'weiß' => [
|
||||
[
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
[
|
||||
'hue' => 0.0,
|
||||
'saturation' => 0.0,
|
||||
'value' => 1.0,
|
||||
]
|
||||
],
|
||||
'schwarz' => [
|
||||
[
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 1.0,
|
||||
],
|
||||
[
|
||||
'hue' => 0.0,
|
||||
'saturation' => 0.0,
|
||||
'value' => 0.0,
|
||||
]
|
||||
],
|
||||
'cyan' => [
|
||||
[
|
||||
'cyan' => 1.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
[
|
||||
'hue' => 0.5,
|
||||
'saturation' => 1.0,
|
||||
'value' => 1.0,
|
||||
]
|
||||
],
|
||||
'magenta' => [
|
||||
[
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 1.0,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
[
|
||||
'hue' => 0.833,
|
||||
'saturation' => 1.0,
|
||||
'value' => 1.0,
|
||||
]
|
||||
],
|
||||
'gelb' => [
|
||||
[
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.0,
|
||||
'yellow' => 1.0,
|
||||
'key' => 0.0,
|
||||
],
|
||||
[
|
||||
'hue' => 0.167,
|
||||
'saturation' => 1.0,
|
||||
'value' => 1.0,
|
||||
]
|
||||
],
|
||||
'gold' => [
|
||||
[
|
||||
'cyan' => 0.0,
|
||||
'magenta' => 0.13,
|
||||
'yellow' => 0.76,
|
||||
'key' => 0.13,
|
||||
],
|
||||
[
|
||||
'hue' => 0.138,
|
||||
'saturation' => 0.76,
|
||||
'value' => 0.87,
|
||||
]
|
||||
],
|
||||
'violet' => [
|
||||
[
|
||||
'cyan' => 0.19,
|
||||
'magenta' => 0.32,
|
||||
'yellow' => 0.0,
|
||||
'key' => 0.29,
|
||||
],
|
||||
[
|
||||
'hue' => 0.734,
|
||||
'saturation' => 0.32,
|
||||
'value' => 0.71,
|
||||
]
|
||||
],
|
||||
];
|
||||
return (new ValidColorValuesProvider())->getValidColorValues([
|
||||
ValidColorValuesProvider::CMYK,
|
||||
ValidColorValuesProvider::HSV
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cmyk
|
||||
* @param array $rgb
|
||||
* @param array<string, float> $cmyk
|
||||
* @param array<string, float> $rgb
|
||||
*
|
||||
* @dataProvider validRgbValuesProvider
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testToRedGreenBlue(array $cmyk, array $rgb)
|
||||
public function testToRedGreenBlue(array $cmyk, array $rgb): void
|
||||
{
|
||||
$this->color = $this->make(CyanMagentaYellowKey::class, $cmyk);
|
||||
|
||||
@@ -237,13 +60,13 @@ class CyanMagentaYellowKeyTransformerTest extends Unit
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cmyk
|
||||
* @param array<string, float> $cmyk
|
||||
*
|
||||
* @dataProvider validRgbValuesProvider
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testToCyanMagentaYellowKey(array $cmyk)
|
||||
public function testToCyanMagentaYellowKey(array $cmyk): void
|
||||
{
|
||||
|
||||
$this->color = $this->make(CyanMagentaYellowKey::class, $cmyk);
|
||||
@@ -259,15 +82,15 @@ class CyanMagentaYellowKeyTransformerTest extends Unit
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cmyk
|
||||
* @param array $hsv
|
||||
* @param array<string, float> $cmyk
|
||||
* @param array<string, float> $hsv
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @dataProvider validHsvValuesProvider
|
||||
*
|
||||
*/
|
||||
public function testToHueSaturationValue(array $cmyk, array $hsv)
|
||||
public function testToHueSaturationValue(array $cmyk, array $hsv): void
|
||||
{
|
||||
$this->color = $this->make(CyanMagentaYellowKey::class, $cmyk);
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedt\Colors\Tests\Unit\Transformer;
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
use Exception;
|
||||
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
|
||||
use TorstenHettstedt\Colors\Tests\Helper\ValidColorValuesProvider;
|
||||
use TorstenHettstedt\Colors\Transformer\HueSaturationValueTransformer;
|
||||
|
||||
class HueSaturationValueTransformerTest extends Unit
|
||||
{
|
||||
|
||||
const FLOAT_DELTA = 0.001;
|
||||
|
||||
protected HueSaturationValue $color;
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, float>[]>
|
||||
*/
|
||||
public function validCmykValuesProvider(): array
|
||||
{
|
||||
return (new ValidColorValuesProvider())->getValidColorValues([
|
||||
ValidColorValuesProvider::HSV,
|
||||
ValidColorValuesProvider::CMYK,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, float>[]>
|
||||
*/
|
||||
public function validRgbValuesProvider(): array
|
||||
{
|
||||
return (new ValidColorValuesProvider())->getValidColorValues([
|
||||
ValidColorValuesProvider::HSV,
|
||||
ValidColorValuesProvider::RGB,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, float> $hsv
|
||||
* @param array<string, float> $rgb
|
||||
*
|
||||
* @dataProvider validRgbValuesProvider
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testToRedGreenBlue(array $hsv, array $rgb): void
|
||||
{
|
||||
$this->color = $this->make(HueSaturationValue::class, $hsv);
|
||||
|
||||
$transformer = new HueSaturationValueTransformer($this->color);
|
||||
|
||||
$color = $transformer->toRedGreenBlue();
|
||||
|
||||
$this->assertEqualsWithDelta($rgb['red'], $color->getRed(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($rgb['green'], $color->getGreen(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($rgb['blue'], $color->getBlue(), self::FLOAT_DELTA);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, float> $hsv
|
||||
* @param array<string, float> $cmyk
|
||||
*
|
||||
* @throws Exception
|
||||
* @dataProvider validCmykValuesProvider
|
||||
*
|
||||
*/
|
||||
public function testToCyanMagentaYellowKey(array $hsv, array $cmyk): void
|
||||
{
|
||||
|
||||
$this->color = $this->make(HueSaturationValue::class, $hsv);
|
||||
|
||||
$transformer = new HueSaturationValueTransformer($this->color);
|
||||
|
||||
$color = $transformer->toCyanMagentaYellowKey();
|
||||
|
||||
$this->assertEqualsWithDelta($cmyk['cyan'], $color->getCyan(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($cmyk['magenta'], $color->getMagenta(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($cmyk['yellow'], $color->getYellow(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($cmyk['key'], $color->getKey(), self::FLOAT_DELTA);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, float> $hsv
|
||||
*
|
||||
* @throws Exception
|
||||
* @dataProvider validCmykValuesProvider
|
||||
*/
|
||||
public function testToHueSaturationValue(array $hsv): void
|
||||
{
|
||||
$this->color = $this->make(HueSaturationValue::class, $hsv);
|
||||
|
||||
$transformer = new HueSaturationValueTransformer($this->color);
|
||||
|
||||
$color = $transformer->toHueSaturationValue();
|
||||
|
||||
$this->assertEqualsWithDelta($hsv['hue'], $color->getHue(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($hsv['saturation'], $color->getSaturation(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($hsv['value'], $color->getValue(), self::FLOAT_DELTA);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace TorstenHettstedt\Colors\Tests\Unit\Transformer;
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
use Exception;
|
||||
use TorstenHettstedt\Colors\ColorModels\RedGreenBlue;
|
||||
use TorstenHettstedt\Colors\Tests\Helper\ValidColorValuesProvider;
|
||||
use TorstenHettstedt\Colors\Transformer\RedGreenBlueTransformer;
|
||||
|
||||
class RedGreenBlueTransformerTest extends Unit
|
||||
{
|
||||
|
||||
const FLOAT_DELTA = 0.001;
|
||||
|
||||
protected RedGreenBlue $color;
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, float>[]>
|
||||
*/
|
||||
public function validCmykValuesProvider(): array
|
||||
{
|
||||
return (new ValidColorValuesProvider())->getValidColorValues([
|
||||
ValidColorValuesProvider::RGB,
|
||||
ValidColorValuesProvider::CMYK,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, float>[]>
|
||||
*/
|
||||
public function validHsvValuesProvider(): array
|
||||
{
|
||||
return (new ValidColorValuesProvider())->getValidColorValues([
|
||||
ValidColorValuesProvider::RGB,
|
||||
ValidColorValuesProvider::HSV,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, float> $rgb
|
||||
*
|
||||
* @dataProvider validCmykValuesProvider
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testToRedGreenBlue(array $rgb): void
|
||||
{
|
||||
$this->color = $this->make(RedGreenBlue::class, $rgb);
|
||||
|
||||
$transformer = new RedGreenBlueTransformer($this->color);
|
||||
|
||||
$color = $transformer->toRedGreenBlue();
|
||||
|
||||
$this->assertEqualsWithDelta($rgb['red'], $color->getRed(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($rgb['green'], $color->getGreen(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($rgb['blue'], $color->getBlue(), self::FLOAT_DELTA);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, float> $rgb
|
||||
* @param array<string, float> $cmyk
|
||||
*
|
||||
* @throws Exception
|
||||
* @dataProvider validCmykValuesProvider
|
||||
*
|
||||
*/
|
||||
public function testToCyanMagentaYellowKey(array $rgb, array $cmyk): void
|
||||
{
|
||||
|
||||
$this->color = $this->make(RedGreenBlue::class, $rgb);
|
||||
|
||||
$transformer = new RedGreenBlueTransformer($this->color);
|
||||
|
||||
$color = $transformer->toCyanMagentaYellowKey();
|
||||
|
||||
$this->assertEqualsWithDelta($cmyk['cyan'], $color->getCyan(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($cmyk['magenta'], $color->getMagenta(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($cmyk['yellow'], $color->getYellow(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($cmyk['key'], $color->getKey(), self::FLOAT_DELTA);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, float> $rgb
|
||||
* @param array<string, float> $hsv
|
||||
*
|
||||
* @throws Exception
|
||||
* @dataProvider validHsvValuesProvider
|
||||
*/
|
||||
public function testToHueSaturationValue(array $rgb, array $hsv): void
|
||||
{
|
||||
$this->color = $this->make(RedGreenBlue::class, $rgb);
|
||||
|
||||
$transformer = new RedGreenBlueTransformer($this->color);
|
||||
|
||||
$color = $transformer->toHueSaturationValue();
|
||||
|
||||
$this->assertEqualsWithDelta($hsv['hue'], $color->getHue(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($hsv['saturation'], $color->getSaturation(), self::FLOAT_DELTA);
|
||||
$this->assertEqualsWithDelta($hsv['value'], $color->getValue(), self::FLOAT_DELTA);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user