Basic colors test add started
Also fixes for various things that come up during test writing Test phpunit not yet finished (exceptions, etc) Note: a lot of checks for extreme values are (int) so we do not fail for small float values
This commit is contained in:
@@ -354,15 +354,21 @@ class Color
|
||||
{
|
||||
$saturation = $hsl->S / 100;
|
||||
$lightness = $hsl->L / 100;
|
||||
$value = $lightness + $saturation * min($lightness, 1 - $lightness);
|
||||
// if lightness is 0, then we cannot return convert to hsb
|
||||
$value = $lightness + $saturation * min($lightness, 1 - $lightness);
|
||||
// print "Orig: " . print_r($hsl, true) . "\n";
|
||||
// print "SAT: " . $saturation . ", Lightness: " . $lightness . ", Value: " . $value . "\n";
|
||||
// var_dump($value);
|
||||
|
||||
// check for black and white
|
||||
$saturation = ($value === 0) ?
|
||||
$saturation = $value == 0 ?
|
||||
0 :
|
||||
200 * (1 - $lightness / $value);
|
||||
$value *= 100;
|
||||
return HSB::__constructFromArray([
|
||||
$hsl->H,
|
||||
$saturation,
|
||||
$value * 100,
|
||||
$value,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -377,11 +383,11 @@ class Color
|
||||
// hsv/toHsl
|
||||
$hue = $hsb->H;
|
||||
$saturation = $hsb->S / 100;
|
||||
$value = $hsb->V / 100;
|
||||
$value = $hsb->B / 100;
|
||||
|
||||
$lightness = $value * (1 - $saturation / 2);
|
||||
// check for B/W
|
||||
$saturation = in_array($lightness, [0, 1], true) ?
|
||||
$saturation = in_array($lightness, [0, 1]) ?
|
||||
0 :
|
||||
100 * ($value - $lightness) / min($lightness, 1 - $lightness)
|
||||
;
|
||||
@@ -456,6 +462,7 @@ class Color
|
||||
$blackness = $hwb->B / 100;
|
||||
|
||||
$sum = $whiteness + $blackness;
|
||||
// print "S: B/W: " . $sum . " /W: " . $whiteness . " /B: " . $blackness . "\n";
|
||||
// for black and white
|
||||
if ($sum >= 1) {
|
||||
$saturation = 0;
|
||||
@@ -475,8 +482,6 @@ class Color
|
||||
|
||||
// MARK: LAB <-> LCH
|
||||
|
||||
// toLch
|
||||
|
||||
/**
|
||||
* CIE Lab to LCH
|
||||
*
|
||||
|
||||
@@ -62,10 +62,10 @@ class HSB
|
||||
}
|
||||
switch ($name) {
|
||||
case 'H':
|
||||
if ($value == 360) {
|
||||
if ((int)$value == 360) {
|
||||
$value = 0;
|
||||
}
|
||||
if ($value < 0 || $value > 359) {
|
||||
if ((int)$value < 0 || (int)$value > 359) {
|
||||
throw new \LengthException(
|
||||
'Argument value ' . $value . ' for hue is not in the range of 0 to 359',
|
||||
1
|
||||
@@ -73,7 +73,7 @@ class HSB
|
||||
}
|
||||
break;
|
||||
case 'S':
|
||||
if ($value < 0 || $value > 100) {
|
||||
if ((int)$value < 0 || (int)$value > 100) {
|
||||
throw new \LengthException(
|
||||
'Argument value ' . $value . ' for saturation is not in the range of 0 to 100',
|
||||
2
|
||||
@@ -81,7 +81,7 @@ class HSB
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
if ($value < 0 || $value > 100) {
|
||||
if ((int)$value < 0 || (int)$value > 100) {
|
||||
throw new \LengthException(
|
||||
'Argument value ' . $value . ' for brightness is not in the range of 0 to 100',
|
||||
3
|
||||
|
||||
@@ -63,10 +63,10 @@ class HSL
|
||||
}
|
||||
switch ($name) {
|
||||
case 'H':
|
||||
if ($value == 360) {
|
||||
if ((int)$value == 360) {
|
||||
$value = 0;
|
||||
}
|
||||
if ($value < 0 || $value > 359) {
|
||||
if ((int)$value < 0 || (int)$value > 359) {
|
||||
throw new \LengthException(
|
||||
'Argument value ' . $value . ' for hue is not in the range of 0 to 359',
|
||||
1
|
||||
@@ -74,7 +74,7 @@ class HSL
|
||||
}
|
||||
break;
|
||||
case 'S':
|
||||
if ($value < 0 || $value > 100) {
|
||||
if ((int)$value < 0 || (int)$value > 100) {
|
||||
throw new \LengthException(
|
||||
'Argument value ' . $value . ' for saturation is not in the range of 0 to 100',
|
||||
2
|
||||
@@ -82,7 +82,7 @@ class HSL
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
if ($value < 0 || $value > 100) {
|
||||
if ((int)$value < 0 || (int)$value > 100) {
|
||||
throw new \LengthException(
|
||||
'Argument value ' . $value . ' for luminance is not in the range of 0 to 100',
|
||||
3
|
||||
|
||||
@@ -63,10 +63,10 @@ class HWB
|
||||
}
|
||||
switch ($name) {
|
||||
case 'H':
|
||||
if ($value == 360) {
|
||||
if ((int)$value == 360) {
|
||||
$value = 0;
|
||||
}
|
||||
if ($value < 0 || $value > 360) {
|
||||
if ((int)$value < 0 || (int)$value > 360) {
|
||||
throw new \LengthException(
|
||||
'Argument value ' . $value . ' for hue is not in the range of 0 to 360',
|
||||
1
|
||||
@@ -74,7 +74,7 @@ class HWB
|
||||
}
|
||||
break;
|
||||
case 'W':
|
||||
if ($value < 0 || $value > 100) {
|
||||
if ((int)$value < 0 || (int)$value > 100) {
|
||||
throw new \LengthException(
|
||||
'Argument value ' . $value . ' for saturation is not in the range of 0 to 100',
|
||||
2
|
||||
@@ -82,7 +82,7 @@ class HWB
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
if ($value < 0 || $value > 100) {
|
||||
if ((int)$value < 0 || (int)$value > 100) {
|
||||
throw new \LengthException(
|
||||
'Argument value ' . $value . ' for luminance is not in the range of 0 to 100',
|
||||
3
|
||||
|
||||
@@ -85,11 +85,10 @@ class RGB
|
||||
throw new \ErrorException('Creation of dynamic property is not allowed', 0);
|
||||
}
|
||||
// if not linear
|
||||
if (!$this->linear && ($value < 0 || $value > 255)) {
|
||||
if (!$this->linear && ((int)$value < 0 || (int)$value > 255)) {
|
||||
throw new \LengthException('Argument value ' . $value . ' for color ' . $name
|
||||
. ' is not in the range of 0 to 255', 1);
|
||||
} elseif ($this->linear && ($value < -10E10 || $value > 1)) {
|
||||
// not allow very very small negative numbers
|
||||
} elseif ($this->linear && ((int)$value < 0 || (int)$value > 1)) {
|
||||
throw new \LengthException('Argument value ' . $value . ' for color ' . $name
|
||||
. ' is not in the range of 0 to 1 for linear rgb', 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user