Update config.master, color convert hsb/hsl is full float

All Convert\Color calls for hsb or hsl are full float compatible
This commit is contained in:
Clemens Schwaighofer
2022-03-23 10:38:23 +09:00
parent 04b0476b4d
commit 2a583e525c
4 changed files with 19 additions and 15 deletions

View File

@@ -132,7 +132,7 @@ final class CoreLibsConvertColorsTest extends TestCase
],
'valid color' => [
'rgb' => [10, 100, 200],
'hsb' => [212, 95, 78],
'hsb' => [212, 95, 78.0],
'hsb_rgb' => [10, 98, 199], // should be rgb, but rounding error
'hsl' => [211.6, 90.5, 41.2],
'valid' => true,
@@ -327,13 +327,13 @@ final class CoreLibsConvertColorsTest extends TestCase
* @dataProvider hsb2rgbColorProvider
* @testdox hsb2rgb $input_h,$input_s,$input_b will be $expected [$_dataName]
*
* @param integer $input_h
* @param integer $input_s
* @param integer $input_b
* @param float $input_h
* @param float $input_s
* @param float $input_b
* @param array|bool $expected
* @return void
*/
public function testHsb2rgb(int $input_h, int $input_s, int $input_b, $expected): void
public function testHsb2rgb(float $input_h, float $input_s, float $input_b, $expected): void
{
$this->assertEquals(
$expected,

View File

@@ -57,6 +57,7 @@ print "\$C::S/COLOR invalid rgb->hex (gray 125): -1, -1, -1: " . $color_class::r
$rgb = [10, 20, 30];
$hex = '#0a141e';
$hsb = [210, 67, 12];
$hsb_f = [210.5, 67.5, 12.5];
$hsl = [210, 50, 7.8];
print "S::COLOR rgb->hex: $rgb[0], $rgb[1], $rgb[2]: " . Colors::rgb2hex($rgb[0], $rgb[1], $rgb[2]) . "<br>";
print "S::COLOR hex->rgb: $hex: " . DgS::printAr(Colors::hex2rgb($hex)) . "<br>";
@@ -69,6 +70,8 @@ print "S::COLOR rgb->hsl: $rgb[0], $rgb[1], $rgb[2]: "
// D(from hsb/hsl) Note that param 2 + 3 is always 0-100 divided
print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: "
. DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2])) . "<br>";
print "S::COLOR hsb_f->rgb: $hsb_f[0], $hsb_f[1], $hsb_f[2]: "
. DgS::printAr(Colors::hsb2rgb($hsb_f[0], $hsb_f[1], $hsb_f[2])) . "<br>";
print "S::COLOR hsl->rgb: $hsl[0], $hsl[1], $hsl[2]: "
. DgS::printAr(Colors::hsl2rgb($hsl[0], $hsl[1], $hsl[2])) . "<br>";

View File

@@ -256,10 +256,11 @@ $GLOBALS['DB_CONFIG'] = DB_CONFIG;
// where global tables are that are used by all schemas (eg queue tables for online, etc)
// define('GLOBAL_DB_SCHEMA', PUBLIC_SCHEMA);
// debug settings, site lang, etc
define('TARGET', $SITE_CONFIG[HOST_NAME]['location']);
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag']);
define('SITE_LANG', $SITE_CONFIG[HOST_NAME]['site_lang']);
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled']);
define('TARGET', $SITE_CONFIG[HOST_NAME]['location'] ?? 'test');
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag'] ?? false);
define('SITE_LANG', $SITE_CONFIG[HOST_NAME]['site_lang'] ?? 'en_utf8');
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
// paths
// define('CSV_PATH', $PATHS[TARGET]['csv_path']);
// define('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']);

View File

@@ -135,13 +135,13 @@ class Colors
* hsb2rgb does not clean convert back to hsb in a round trip
* converts HSB/V to RGB values RGB is full INT
* if HSB/V value is invalid, sets this value to 0
* @param int $H hue 0-360 (int)
* @param int $S saturation 0-100 (int)
* @param int $V brightness/value 0-100 (int)
* @param float $H hue 0-360 (int)
* @param float $S saturation 0-100 (int)
* @param float $V brightness/value 0-100 (int)
* @return array<int>|bool 0 red/1 green/2 blue array as 0-255
* false for input value error
*/
public static function hsb2rgb(int $H, int $S, int $V)
public static function hsb2rgb(float $H, float $S, float $V)
{
// check that H is 0 to 359, 360 = 0
// and S and V are 0 to 1
@@ -270,12 +270,12 @@ class Colors
/**
* converts an HSL to RGB
* if HSL value is invalid, set this value to 0
* @param int|float $hue hue: 0-360 (degrees)
* @param float $hue hue: 0-360 (degrees)
* @param float $sat saturation: 0-100
* @param float $lum luminance: 0-100
* @return array<int,float|int>|bool red/blue/green 0-255 each
*/
public static function hsl2rgb($hue, float $sat, float $lum)
public static function hsl2rgb(float $hue, float $sat, float $lum)
{
if (!is_numeric($hue)) {
return false;