Compare commits
6
Commits
cc2e35e20f
...
7a9c5dcf91
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a9c5dcf91 | ||
|
|
def8066374 | ||
|
|
49ef3b83f6 | ||
|
|
5941c17a8a | ||
|
|
92cbb1eb46 | ||
|
|
03d2680305 |
@@ -31,4 +31,8 @@ Die Werte werden als Hexadecimal Zahlen und in der Webschreibweise zur Verfügun
|
||||
|
||||
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.
|
||||
@@ -20,19 +20,38 @@ NaturallyColorModels.CyanMagentaYellowKey o-- ColorModels.CyanMagentaYellowKey
|
||||
NaturallyColorModels.HueSaturationValue o-- ColorModels.HueSaturationValue
|
||||
NaturallyColorModels.RedGreenBlue o-- ColorModels.RedGreenBlue
|
||||
|
||||
|
||||
namespace Transformer {
|
||||
namespace NaturallyTransformer {
|
||||
interface ColorModelTransformInterface {
|
||||
+ toRedGreenBlue(): RedGreenBlue;
|
||||
+ toCyanMagentaYellowKey(): CyanMagentaYellowKey;
|
||||
+ toHueSaturationValue(): HueSaturationValue;
|
||||
+ toRedGreenBlue(): NaturallyColorModels.RedGreenBlue
|
||||
+ toCyanMagentaYellowKey(): NaturallyColorModels.CyanMagentaYellowKey
|
||||
+ toHueSaturationValue(): NaturallyColorModels.HueSaturationValue
|
||||
}
|
||||
class CyanMagentaYellowKeyTransformer
|
||||
class HueSaturationValueTransformer
|
||||
class RedGreenBlueTransformer
|
||||
ColorModelTransformInterface <|-- CyanMagentaYellowKeyTransformer
|
||||
ColorModelTransformInterface <|-- HueSaturationValueTransformer
|
||||
ColorModelTransformInterface <|-- 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
|
||||
|
||||
@@ -22,6 +22,14 @@ class CyanMagentaYellowKey
|
||||
$this->percentValuesHelper = new Helper\PercentValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PureCyanMagentaYellowKey
|
||||
*/
|
||||
public function getPureColor(): PureCyanMagentaYellowKey
|
||||
{
|
||||
return $this->pureColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
|
||||
@@ -10,7 +10,7 @@ class GradValues
|
||||
|
||||
public function asGradValue(float $value): int
|
||||
{
|
||||
return intval($value * 360);
|
||||
return intval(round($value * 360, 0, PHP_ROUND_HALF_UP));
|
||||
}
|
||||
|
||||
public function fromGradValue(int $value): float
|
||||
|
||||
@@ -10,7 +10,7 @@ class PercentValues
|
||||
|
||||
public function asPercentValue(float $value): int
|
||||
{
|
||||
return intval($value * 100);
|
||||
return intval(round($value * 100, 0, PHP_ROUND_HALF_UP));
|
||||
}
|
||||
|
||||
public function fromPercentValue(int $value): float
|
||||
|
||||
@@ -25,6 +25,14 @@ class HueSaturationValue
|
||||
$this->gradValuesHelper = new Helper\GradValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PureHueSaturationValue
|
||||
*/
|
||||
public function getPureColor(): PureHueSaturationValue
|
||||
{
|
||||
return $this->pureColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,14 @@ class RedGreenBlue
|
||||
$this->hexadecimalValuesHelper = new Helper\HexadecimalValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PureRedGreenBlue
|
||||
*/
|
||||
public function getPureColor(): PureRedGreenBlue
|
||||
{
|
||||
return $this->pureColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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<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<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;
|
||||
}
|
||||
}
|
||||
@@ -125,4 +125,19 @@ class CyanMagentaYellowKeyTest extends AbstractColorModelUnit
|
||||
$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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,4 +97,17 @@ class HueSaturationValueTest extends AbstractColorModelUnit
|
||||
$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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,4 +106,17 @@ class RedGreenBlueTest extends AbstractColorModelUnit
|
||||
$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<string, float>[]>
|
||||
*/
|
||||
public function validRgbValuesProvider(): array
|
||||
{
|
||||
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
|
||||
ValidNaturallyColorValuesProvider::CMYK,
|
||||
ValidNaturallyColorValuesProvider::RGB
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, float>[]>
|
||||
*/
|
||||
public function validHsvValuesProvider(): array
|
||||
{
|
||||
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
|
||||
ValidNaturallyColorValuesProvider::CMYK,
|
||||
ValidNaturallyColorValuesProvider::HSV
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, 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<string, float>[]>
|
||||
*/
|
||||
public function validCmykValuesProvider(): array
|
||||
{
|
||||
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
|
||||
ValidNaturallyColorValuesProvider::HSV,
|
||||
ValidNaturallyColorValuesProvider::CMYK,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, float>[]>
|
||||
*/
|
||||
public function validRgbValuesProvider(): array
|
||||
{
|
||||
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
|
||||
ValidNaturallyColorValuesProvider::HSV,
|
||||
ValidNaturallyColorValuesProvider::RGB,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, 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<string, float>[]>
|
||||
*/
|
||||
public function validCmykValuesProvider(): array
|
||||
{
|
||||
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
|
||||
ValidNaturallyColorValuesProvider::RGB,
|
||||
ValidNaturallyColorValuesProvider::CMYK,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string, float>[]>
|
||||
*/
|
||||
public function validHsvValuesProvider(): array
|
||||
{
|
||||
return (new ValidNaturallyColorValuesProvider())->getValidColorValues(
|
||||
ValidNaturallyColorValuesProvider::RGB,
|
||||
ValidNaturallyColorValuesProvider::HSV,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, 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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user