From 2a583e525cb1ae2683619b5444356514e3090a3b Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Wed, 23 Mar 2022 10:38:23 +0900 Subject: [PATCH] Update config.master, color convert hsb/hsl is full float All Convert\Color calls for hsb or hsl are full float compatible --- 4dev/tests/CoreLibsConvertColorsTest.php | 10 +++++----- www/admin/class_test.colors.php | 3 +++ www/configs/config.master.php | 9 +++++---- www/lib/CoreLibs/Convert/Colors.php | 12 ++++++------ 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/4dev/tests/CoreLibsConvertColorsTest.php b/4dev/tests/CoreLibsConvertColorsTest.php index a890ab0a..d58ce903 100644 --- a/4dev/tests/CoreLibsConvertColorsTest.php +++ b/4dev/tests/CoreLibsConvertColorsTest.php @@ -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, diff --git a/www/admin/class_test.colors.php b/www/admin/class_test.colors.php index 63fbee94..b0a32410 100644 --- a/www/admin/class_test.colors.php +++ b/www/admin/class_test.colors.php @@ -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]) . "
"; print "S::COLOR hex->rgb: $hex: " . DgS::printAr(Colors::hex2rgb($hex)) . "
"; @@ -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])) . "
"; + 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])) . "
"; print "S::COLOR hsl->rgb: $hsl[0], $hsl[1], $hsl[2]: " . DgS::printAr(Colors::hsl2rgb($hsl[0], $hsl[1], $hsl[2])) . "
"; diff --git a/www/configs/config.master.php b/www/configs/config.master.php index 0cca6b1c..d25471ed 100644 --- a/www/configs/config.master.php +++ b/www/configs/config.master.php @@ -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']); diff --git a/www/lib/CoreLibs/Convert/Colors.php b/www/lib/CoreLibs/Convert/Colors.php index 7e519357..f5f2d776 100644 --- a/www/lib/CoreLibs/Convert/Colors.php +++ b/www/lib/CoreLibs/Convert/Colors.php @@ -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|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|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;