feature: natürliche Modellklassen können in andere Farbsysteme transformiert werden
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user