implemented Color
This commit is contained in:
parent
bcb839fb49
commit
dda4ba31e0
2 changed files with 59 additions and 0 deletions
|
|
@ -69,6 +69,39 @@ class Color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function redAsHex(): int
|
||||||
|
{
|
||||||
|
$percentage = ($this->red < 0) ? 0 : (($this->red > 1) ? 1 : $this->red);
|
||||||
|
|
||||||
|
return (int)round(255 * $percentage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function greenAsHex(): int
|
||||||
|
{
|
||||||
|
$percentage = ($this->green < 0) ? 0 : (($this->green > 1) ? 1 : $this->green);
|
||||||
|
|
||||||
|
return (int)round(255 * $percentage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function blueAsHex(): int
|
||||||
|
{
|
||||||
|
$percentage = ($this->blue < 0) ? 0 : (($this->blue > 1) ? 1 : $this->blue);
|
||||||
|
|
||||||
|
return (int)round(255 * $percentage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Color $color
|
* @param Color $color
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,32 @@ class ColorTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider parametersForHexValues
|
||||||
|
*
|
||||||
|
* @param int $red
|
||||||
|
* @param int $green
|
||||||
|
* @param int $blue
|
||||||
|
* @param Color $color
|
||||||
|
*/
|
||||||
|
public function testProvidesHexValues(int $red, int $green, int $blue, Color $color): void
|
||||||
|
{
|
||||||
|
$this->assertSame($red, $color->redAsHex());
|
||||||
|
$this->assertSame($green, $color->greenAsHex());
|
||||||
|
$this->assertSame($blue, $color->blueAsHex());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function parametersForHexValues()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[255, 0, 0, new Color(1.5, 0.0, 0.0)],
|
||||||
|
[0, 128, 0, new Color(0.0, 0.5, 0.0)],
|
||||||
|
[0, 0, 255, new Color(-0.5, 0.0, 1.0)],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testProvidedColorValues(): void
|
public function testProvidedColorValues(): void
|
||||||
{
|
{
|
||||||
$color = new Color($this->red, $this->green, $this->blue);
|
$color = new Color($this->red, $this->green, $this->blue);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue