From 32c192a362b336f5bea6bc980e71fd68d905f4db Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Wed, 13 Nov 2024 19:19:35 +0900 Subject: [PATCH] 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 --- .../Convert/CoreLibsConvertColorTest.php | 345 ++++++++++++++++++ www/admin/class_test.convert.colors.php | 101 +++-- www/lib/CoreLibs/Convert/Color/Color.php | 19 +- .../Convert/Color/Coordinates/HSB.php | 8 +- .../Convert/Color/Coordinates/HSL.php | 8 +- .../Convert/Color/Coordinates/HWB.php | 8 +- .../Convert/Color/Coordinates/RGB.php | 5 +- 7 files changed, 432 insertions(+), 62 deletions(-) create mode 100644 4dev/tests/Convert/CoreLibsConvertColorTest.php diff --git a/4dev/tests/Convert/CoreLibsConvertColorTest.php b/4dev/tests/Convert/CoreLibsConvertColorTest.php new file mode 100644 index 00000000..3b5d950f --- /dev/null +++ b/4dev/tests/Convert/CoreLibsConvertColorTest.php @@ -0,0 +1,345 @@ + round($v), + $values + ); + } + + public function testSingle() + { + $this->assertTrue(true, 'Single test'); + // $rgb = Color\Coordinates\RGB::__constructFromArray([0, 0, 60]); + // print "IN: " . print_r($rgb, true) . "\n"; + // $hsl = Color\Color::rgbToHsl($rgb); + // print "to HSL: " . print_r($hsl, true) . "\n"; + // $hsb = Color\Color::hslToHsb($hsl); + // print "to HSB: " . print_r($hsb, true) . "\n"; + // $hwb = Color\Color::hsbToHwb($hsb); + // print "to HWB: " . print_r($hwb, true) . "\n"; + // // and reverse + // $hsb_r = Color\Color::hwbToHsb($hwb); + // print "R to HSB: " . print_r($hsb_r, true) . "\n"; + // $hsl_r = Color\Color::hsbToHsl($hsb_r); + // print "R to HSB: " . print_r($hsl_r, true) . "\n"; + // $rgb_r = Color\Color::hslToRgb($hsl_r); + // print "R to RGB: " . print_r($rgb_r, true) . "\n"; + + // $hsl = Color\Coordinates\HSL::__constructFromArray([0, 0, 0]); + // print "IN HSL: " . print_r($hsl, true) . "\n"; + // $hsb = Color\Color::hslToHsb($hsl); + // print "to HSB: " . print_r($hsb, true) . "\n"; + // $hwb = Color\Color::hsbToHwb($hsb); + // print "to HWB: " . print_r($hwb, true) . "\n"; + // // and reverse + // $hsb_r = Color\Color::hwbToHsb($hwb); + // print "R to HSB: " . print_r($hsb_r, true) . "\n"; + // $hsl_r = Color\Color::hsbToHsl($hsb_r); + // print "R to HSL: " . print_r($hsl_r, true) . "\n"; + // print "--------\n"; + // $hsb = Color\Coordinates\HSB::__constructFromArray([0, 20, 0]); + // print "IN HSB: " . print_r($hsb, true) . "\n"; + // $hsl = Color\Color::hsbToHsl($hsb); + // print "to HSL: " . print_r($hsl, true) . "\n"; + // $hwb = Color\Color::hslToHwb($hsl); + // print "to HWB: " . print_r($hwb, true) . "\n"; + // // and reverse + // $hsl_r = Color\Color::hwbToHsl($hwb); + // print "R to HSB: " . print_r($hsb_r, true) . "\n"; + // $hsb_r = Color\Color::hslToHsb($hsl_r); + // print "R to HSL: " . print_r($hsb_r, true) . "\n"; + // print "--------\n"; + // $hwb = Color\Coordinates\HWB::__constructFromArray([0, 20, 100]); + // print "IN: " . print_r($hwb, true) . "\n"; + // $hsl = Color\Color::hwbToHsl($hwb); + // print "to HSL: " . print_r($hsl, true) . "\n"; + // $hwb_r = Color\Color::hslToHwb($hsl); + // print "HSL to HWB: " . print_r($hwb_r, true) . "\n"; + // $hsb = Color\Color::hwbToHsb($hwb); + // print "to HSB: " . print_r($hsb, true) . "\n"; + // $hwb_r = Color\Color::hsbToHwb($hsb); + // print "HSL to HWB: " . print_r($hwb_r, true) . "\n"; + } + + /** + * From/To RGB <-> ... conversion tests + * + * @covers ::rgbToHsb + * @covers ::rgbToHsl + * @covers ::rgbToHwb + * @covers ::hsbToRgb + * @covers ::hslToRgb + * @covers ::hwebToRgb + * @testdox Convert from and to RGB via HSL, HWB, HSB/V + * + * @return void + */ + public function testRgbColorCoordinateConvertToAndBack(): void + { + for ($r = 0; $r <= 300; $r += 60) { + for ($g = 0; $g <= 300; $g += 60) { + for ($b = 0; $b <= 300; $b += 60) { + // for this test we stay in the correct lane + if ($r > 255) { + $r = 255; + } + if ($g > 255) { + $g = 255; + } + if ($b > 255) { + $b = 255; + } + // base is always the same + $color = Color\Coordinates\RGB::__constructFromArray([$r, $g, $b]); + $base = 'rgb'; + foreach (['hsb', 'hsl', 'hwb'] as $coord) { + // print "COORD: " . $coord . ", RGB: " . print_r($color->returnAsArray(), true) . "\n"; + // rgb to X and back must be same + $target = $base . 'To' . ucfirst($coord); + $source = $coord . 'To' . ucfirst($base); + $converted_color = Color\Color::$target($color); + $color_b = Color\Color::$source($converted_color); + // $converted_color = Color\Color::rgbToHsb($color); + // $rgb_b = Color\Color::hsbToRgb($converted_color); + $this->assertEqualsWithDelta( + $color->returnAsArray(), + $color_b->returnAsArray(), + self::DELTA, + 'Convert ' . $base . ' to ' . $coord . ': ' . print_r($color->returnAsArray(), true) . '/' + . print_r($color_b->returnAsArray(), true) + ); + } + } + } + } + } + + // HSL / HSB / HWB conversion are not reversable if + // HSL: lightness 0 or 100 + // HSB: saturation or brightness 0 + // HWB: blackness >= 80 and whitness >= 20 or B>=20 & W>=20 or B>=50 & W>=50 + + /** + * Undocumented function + * + * @covers ::hslToHsb + * @covers ::hsbToHsl + * @covers ::hslToHwb + * @covers ::hwbToHsl + * @testdox Convert from and to HSL via RGB, HWB, HSB/V + * + * @return void + */ + public function testHslColorCoordinateConvertToAndBack(): void + { + for ($H = 0; $H <= 360; $H += 60) { + for ($S = 0; $S <= 100; $S += 20) { + for ($L = 0; $L <= 100; $L += 20) { + // if lightness 0 or 100 then we cannot reverse (B/W) + if (($L == 0 or $L == 100)) { + continue; + } + $color = Color\Coordinates\HSL::__constructFromArray([$H, $S, $L]); + $base = 'hsl'; + foreach (['hsb', 'hwb', 'rgb'] as $coord) { + // for rgb hue on S = 0 is irrelevant (B/W) + if ($H > 0 && $coord == 'rgb') { + continue; + } + $target = $base . 'To' . ucfirst($coord); + $source = $coord . 'To' . ucfirst($base); + $converted_color = Color\Color::$target($color); + $color_b = Color\Color::$source($converted_color); + // print "COORD: " . $coord . ", HSL: " . print_r($color->returnAsArray(), true) . "\n"; + $this->assertEqualsWithDelta( + $color->returnAsArray(), + $color_b->returnAsArray(), + self::DELTA, + 'Convert HSL to ' . $coord . ': ' . print_r($color->returnAsArray(), true) . '/' + . print_r($color_b->returnAsArray(), true) + ); + } + } + } + } + } + + /** + * Undocumented function + * + * @covers ::hsbToHsl + * @covers ::hslToHsb + * @covers ::hsbToHwb + * @covers ::hwbToHsb + * @testdox Convert from and to HSB via RGB, HWB, HSL + * + * @return void + */ + public function testHsbColorCoordinateConvertToAndBack(): void + { + for ($H = 0; $H <= 360; $H += 60) { + for ($S = 0; $S <= 100; $S += 20) { + for ($B = 0; $B <= 100; $B += 20) { + // if sat or brightness is 0 then we cannot reverse correctly (B/W) + if ($S == 0 or $B == 0) { + continue; + } + $color = Color\Coordinates\HSB::__constructFromArray([$H, $S, $B]); + $base = 'hsb'; + foreach (['hwb', 'hsl', 'rgb'] as $coord) { + $target = $base . 'To' . ucfirst($coord); + $source = $coord . 'To' . ucfirst($base); + $converted_color = Color\Color::$target($color); + $color_b = Color\Color::$source($converted_color); + // print "COORD: " . $coord . ", HSL: " . print_r($color->returnAsArray(), true) . "\n"; + $this->assertEqualsWithDelta( + $color->returnAsArray(), + $color_b->returnAsArray(), + self::DELTA, + 'Convert ' . $base . ' to ' . $coord . ': ' . print_r($color->returnAsArray(), true) . '/' + . print_r($color_b->returnAsArray(), true) + ); + } + } + } + } + } + + + /** + * Undocumented function + * + * @covers ::hwbToHsl + * @covers ::hslToHwb + * @covers ::hwbToHsb + * @covers ::hsbToHwb + * @testdox Convert from and to HWB via RGB, HSL, HSB/V + * + * @return void + */ + public function testHwbColorCoordinateConvertToAndBack(): void + { + for ($H = 0; $H <= 360; $H += 60) { + for ($W = 0; $W <= 100; $W += 20) { + for ($B = 0; $B <= 100; $B += 20) { + // if W>=20 and B>=80 or B>=20 and W>=20 or both >=50 + // we cannot reverse correctl (B/W) + if ( + ($W >= 20 && $B >= 80) || + ($W >= 80 && $B >= 20) || + ($W >= 50 && $B >= 50) + ) { + continue; + } + $base = 'hwb'; + $color = Color\Coordinates\HWB::__constructFromArray([$H, $W, $B]); + foreach (['hsl', 'hsb', 'rgb'] as $coord) { + // for rgb hue on S = 0 is irrelevant (B/W) + if ($H > 0 && $coord == 'rgb') { + continue; + } + $target = $base . 'To' . ucfirst($coord); + $source = $coord . 'To' . ucfirst($base); + $converted_color = Color\Color::$target($color); + $color_b = Color\Color::$source($converted_color); + // print "COORD: " . $coord . ", HSL: " . print_r($color->returnAsArray(), true) . "\n"; + $this->assertEqualsWithDelta( + $color->returnAsArray(), + $color_b->returnAsArray(), + self::DELTA, + 'Convert ' . $base . ' to ' . $coord . ': ' . print_r($color->returnAsArray(), true) . '/' + . print_r($color_b->returnAsArray(), true) + ); + } + } + } + } + } + + /** + * Undocumented function + * + * covers ::returnAsHex() + * covers ::__constructFromHexString() + * @testdox Convert from RGB to hex and back + * + * @return void + */ + public function testRgbToFromHex(): void + { + for ($r = 0; $r <= 300; $r += 60) { + for ($g = 0; $g <= 300; $g += 60) { + for ($b = 0; $b <= 300; $b += 60) { + // for this test we stay in the correct lane + if ($r > 255) { + $r = 255; + } + if ($g > 255) { + $g = 255; + } + if ($b > 255) { + $b = 255; + } + // with or without prefix + foreach ([true, false] as $hex_prefix) { + $hex_color = Color\Coordinates\RGB::__constructFromArray([$r, $g, $b]) + ->returnAsHex($hex_prefix); + // parse into hex to rgb and see if we get the same r/g/b + $color = Color\Coordinates\RGB::__constructFromHexString($hex_color)->returnAsArray(); + // + $this->assertEquals( + [$r, $g, $b], + $color, + 'Convert rgb to hex and back: ' . print_r([$r, $g, $b], true) . '/' + . print_r($color, true) + ); + } + } + } + } + } + + // oklab + + // cie lab + + // create exceptions for all color spaces + + public function testExceptionHSB(): void + { + // for H/S/B exception the same + $this->expectException(\LengthException::class); + Color\Coordinates\HSB::__constructFromArray([900, 10, 10]); + + // invalid access to class + // $this->expectException(\ErrorException::class); + } +} + +// __END__ diff --git a/www/admin/class_test.convert.colors.php b/www/admin/class_test.convert.colors.php index 84d70ce5..131bc642 100644 --- a/www/admin/class_test.convert.colors.php +++ b/www/admin/class_test.convert.colors.php @@ -68,8 +68,63 @@ print ""; print '
Class Test Master
'; print '

' . $PAGE_NAME . '

'; +// out of bounds test + // define a list of from to color sets for conversion test +$hwb = Color::hsbToHwb(Coordinates\HSB::__constructFromArray([ + 160, + 0, + 50, +])); +print "HWB: " . DgS::printAr($hwb) . "
"; +$hsb = Color::hwbToHsb($hwb); +print "HSB: " . DgS::printAr($hsb) . "
"; + +$oklch = Color::rgbToOkLch(Coordinates\RGB::__constructFromArray([ + 250, + 0, + 0 +])); +print "OkLch: " . DgS::printAr($oklch) . "
"; +$rgb = Color::okLchToRgb($oklch); +print "OkLch -> RGB: " . DgS::printAr($rgb) . "
"; + +$oklab = Color::rgbToOkLab(Coordinates\RGB::__constructFromArray([ + 250, + 0, + 0 +])); +print "OkLab: " . DgS::printAr($oklab) . "
"; +print display($oklab->toCssString(), $oklab->toCssString(), 'Oklab'); +$rgb = Color::okLabToRgb($oklab); +print "OkLab -> RGB: " . DgS::printAr($rgb) . "
"; +print display($rgb->toCssString(), $rgb->toCssString(), 'OkLab to RGB'); + +$rgb = Coordinates\RGB::__constructFromArray([250, 100, 10])->toLinear(); +print "RGBlinear: " . DgS::printAr($rgb) . "
"; +$rgb = Coordinates\RGB::__constructFromArray([0, 0, 0])->toLinear(); +print "RGBlinear: " . DgS::printAr($rgb) . "
"; + +$cie_lab = Color::okLabToLab($oklab); +print "CieLab: " . DgS::printAr($cie_lab) . "
"; +print display($cie_lab->toCssString(), $cie_lab->toCssString(), 'OkLab to Cie Lab'); + +$rgb = Coordinates\RGB::__constructFromArray([0, 0, 60]); +$hsb = Color::rgbToHsb($rgb); +$rgb_b = Color::hsbToRgb($hsb); +print "RGB: " . DgS::printAr($rgb) . "
"; +print "RGB->HSB: " . DgS::printAr($hsb) . "
"; +print "HSB->RGB: " . DgS::printAr($rgb_b) . "
"; + +$hsl = Coordinates\HSL::__constructFromArray([0, 20, 0]); +$hsb = Coordinates\HSB::__constructFromArray([0, 20, 0]); +$hsl_from_hsb = Color::hsbToHsl($hsb); +print "HSL from HSB: " . DgS::printAr($hsl_from_hsb) . "
"; + +print "
"; +print "

LEGACY

"; + // A(out of bounds) try { print "C::S/COLOR invalid rgb->hex (gray 125): -1, -1, -1: " @@ -83,6 +138,7 @@ try { } catch (\LengthException $e) { print "**Exception: " . $e->getMessage() . "
" . print_r($e, true) . "

"; } +print "
"; // B(valid) $rgb = [50, 20, 30]; $hex = '#0a141e'; @@ -125,6 +181,8 @@ print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: " Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2]) )) . "
"; +print "
"; + // Random text $h = rand(0, 359); $s = rand(15, 70); @@ -134,49 +192,12 @@ print "RANDOM IN: H: " . $h . ", S: " . $s . ", B/L: " . $b . "/" . $l . "
"; print "RANDOM hsb->rgb:
" . DgS::printAr(SetVarType::setArray(Colors::hsb2rgb($h, $s, $b))) . "

"; print "RANDOM hsl->rgb:
" . DgS::printAr(SetVarType::setArray(Colors::hsl2rgb($h, $s, $l))) . "

"; +print "
"; + $rgb = [0, 0, 0]; print "rgb 0,0,0: " . Dgs::printAr($rgb) . " => " . Dgs::printAr(Colors::rgb2hsb($rgb[0], $rgb[1], $rgb[2])) . "
"; -// TODO: run compare check input must match output - -$hwb = Color::hsbToHwb(Coordinates\HSB::__constructFromArray([ - 160, - 0, - 50, -])); -print "HWB: " . DgS::printAr($hwb) . "
"; -$hsb = Color::hwbToHsb($hwb); -print "HSB: " . DgS::printAr($hsb) . "
"; - -$oklch = Color::rgbToOkLch(Coordinates\RGB::__constructFromArray([ - 250, - 0, - 0 -])); -print "OkLch: " . DgS::printAr($oklch) . "
"; -$rgb = Color::okLchToRgb($oklch); -print "OkLch -> RGB: " . DgS::printAr($rgb) . "
"; - -$oklab = Color::rgbToOkLab(Coordinates\RGB::__constructFromArray([ - 250, - 0, - 0 -])); -print "OkLab: " . DgS::printAr($oklab) . "
"; -print display($oklab->toCssString(), $oklab->toCssString(), 'Oklab'); -$rgb = Color::okLabToRgb($oklab); -print "OkLab -> RGB: " . DgS::printAr($rgb) . "
"; -print display($rgb->toCssString(), $rgb->toCssString(), 'OkLab to RGB'); - -$rgb = Coordinates\RGB::__constructFromArray([250, 100, 10])->toLinear(); -print "RGBlinear: " . DgS::printAr($rgb) . "
"; -$rgb = Coordinates\RGB::__constructFromArray([0, 0, 0])->toLinear(); -print "RGBlinear: " . DgS::printAr($rgb) . "
"; - -$cie_lab = Color::okLabToLab($oklab); -print "CieLab: " . DgS::printAr($cie_lab) . "
"; -print display($cie_lab->toCssString(), $cie_lab->toCssString(), 'OkLab to Cie Lab'); - +print "
"; print ""; diff --git a/www/lib/CoreLibs/Convert/Color/Color.php b/www/lib/CoreLibs/Convert/Color/Color.php index 3b490e9b..49e6bd96 100644 --- a/www/lib/CoreLibs/Convert/Color/Color.php +++ b/www/lib/CoreLibs/Convert/Color/Color.php @@ -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 * diff --git a/www/lib/CoreLibs/Convert/Color/Coordinates/HSB.php b/www/lib/CoreLibs/Convert/Color/Coordinates/HSB.php index 7ebb2dc6..40a74dab 100644 --- a/www/lib/CoreLibs/Convert/Color/Coordinates/HSB.php +++ b/www/lib/CoreLibs/Convert/Color/Coordinates/HSB.php @@ -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 diff --git a/www/lib/CoreLibs/Convert/Color/Coordinates/HSL.php b/www/lib/CoreLibs/Convert/Color/Coordinates/HSL.php index 15005471..1b5b4ecc 100644 --- a/www/lib/CoreLibs/Convert/Color/Coordinates/HSL.php +++ b/www/lib/CoreLibs/Convert/Color/Coordinates/HSL.php @@ -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 diff --git a/www/lib/CoreLibs/Convert/Color/Coordinates/HWB.php b/www/lib/CoreLibs/Convert/Color/Coordinates/HWB.php index 1dd6eb23..39999f41 100644 --- a/www/lib/CoreLibs/Convert/Color/Coordinates/HWB.php +++ b/www/lib/CoreLibs/Convert/Color/Coordinates/HWB.php @@ -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 diff --git a/www/lib/CoreLibs/Convert/Color/Coordinates/RGB.php b/www/lib/CoreLibs/Convert/Color/Coordinates/RGB.php index 7fc3eda0..17dbeb6c 100644 --- a/www/lib/CoreLibs/Convert/Color/Coordinates/RGB.php +++ b/www/lib/CoreLibs/Convert/Color/Coordinates/RGB.php @@ -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); }