Eine Klasse für das HSV-Farbmodel hinzugefügt.

This commit is contained in:
2021-03-02 11:37:50 +01:00
parent fe01eded37
commit 540929e893
2 changed files with 174 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
<?php
namespace TorstenHettstedt\Colors\ColorModels;
/**
* 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 extends AbstractColorModel
{
/** @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;
/**
* @return float
*/
public function getHue(): float
{
return $this->hue;
}
/**
* @param float $hue
* @return HueSaturationValue
*/
public function setHue(float $hue): HueSaturationValue
{
$this->checkValue($hue);
$this->hue = $hue;
return $this;
}
/**
* @return float
*/
public function getSaturation(): float
{
return $this->saturation;
}
/**
* @param float $saturation
* @return HueSaturationValue
*/
public function setSaturation(float $saturation): HueSaturationValue
{
$this->checkValue($saturation);
$this->saturation = $saturation;
return $this;
}
/**
* @return float
*/
public function getValue(): float
{
return $this->value;
}
/**
* @param float $value
* @return HueSaturationValue
*/
public function setValue(float $value): HueSaturationValue
{
$this->checkValue($value);
$this->value = $value;
return $this;
}
}
@@ -0,0 +1,97 @@
<?php
namespace TorstenHettstedtUnitTests\Colors\ColorModels;
use InvalidArgumentException;
use TorstenHettstedt\Colors\ColorModels\HueSaturationValue;
class HueSaturationValueTest extends AbstractColorModelUnit
{
public function testConstruct()
{
$color = new HueSaturationValue();
$this->assertEquals(0.0, $color->getHue());
$this->assertEquals(0.0, $color->getSaturation());
$this->assertEquals(1.0, $color->getValue());
}
/**
* @param float $value
*
* @dataProvider validValueProvider
*/
public function testSetHueWithValidValue(float $value)
{
$color = new HueSaturationValue();
$color->setHue($value);
$this->assertEquals($value, $color->getHue());
}
/**
* @param float $value
*
* @dataProvider invalidValueProvider
*/
public function testSetHueWithInvalidValue(float $value)
{
$color = new HueSaturationValue();
$this->expectException(InvalidArgumentException::class);
$color->setHue($value);
}
/**
* @param float $value
*
* @dataProvider validValueProvider
*/
public function testSetSaturationWithValidValue(float $value)
{
$color = new HueSaturationValue();
$color->setSaturation($value);
$this->assertEquals($value, $color->getSaturation());
}
/**
* @param float $value
*
* @dataProvider invalidValueProvider
*/
public function testSetSaturationWithInvalidValue(float $value)
{
$color = new HueSaturationValue();
$this->expectException(InvalidArgumentException::class);
$color->setSaturation($value);
}
/**
* @param float $value
*
* @dataProvider validValueProvider
*/
public function testSetValueWithValidValue(float $value)
{
$color = new HueSaturationValue();
$color->setValue($value);
$this->assertEquals($value, $color->getValue());
}
/**
* @param float $value
*
* @dataProvider invalidValueProvider
*/
public function testSetValueWithInvalidValue(float $value)
{
$color = new HueSaturationValue();
$this->expectException(InvalidArgumentException::class);
$color->setValue($value);
}
}