Compare commits

...

5 Commits

Author SHA1 Message Date
Clemens Schwaighofer
60613bf311 Comment fixes in Convert\Color 2022-03-23 11:38:05 +09:00
Clemens Schwaighofer
2a583e525c Update config.master, color convert hsb/hsl is full float
All Convert\Color calls for hsb or hsl are full float compatible
2022-03-23 10:38:23 +09:00
Clemens Schwaighofer
04b0476b4d Info TODO text 2022-03-22 20:23:44 +09:00
Clemens Schwaighofer
13fb22385b Fix DB\IO return for unset pk name to be always string
Add Test for SELECT typ query and num rows type with dbReturn
2022-03-22 20:17:30 +09:00
Clemens Schwaighofer
b7f594e683 Fix, config master base style/js, fix DB\IO num rows
DB\IO dbReturn also sets internal num_rows, num_fields, field_names so
the normal dbGet* calls can be used after dbReturn call

JAVASCRIPT/STYLESHEET in config.master is now override able from .env
file. Others will follow
2022-03-22 20:11:13 +09:00
9 changed files with 64 additions and 24 deletions

View File

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

View File

@@ -3384,6 +3384,24 @@ final class CoreLibsDBIOTest extends TestCase
); );
} }
// if this is a select query, db dbReturn, dbReturnRow, dbReturnArray too
if (preg_match("/^(select|show|with) /i", $query)) {
// TODO also tst dbReturnRow and dbReturnArray
$res = $db->dbReturn($query);
$this->assertEquals(
$expected_rows,
$db->dbGetNumRows()
);
$this->assertEquals(
$expected_cols,
$db->dbGetNumFields()
);
$this->assertEquals(
$expected_col_names,
$db->dbGetFieldNames()
);
}
// reset all data // reset all data
$db->dbExec("TRUNCATE table_with_primary_key"); $db->dbExec("TRUNCATE table_with_primary_key");
$db->dbExec("TRUNCATE table_without_primary_key"); $db->dbExec("TRUNCATE table_without_primary_key");

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]; $rgb = [10, 20, 30];
$hex = '#0a141e'; $hex = '#0a141e';
$hsb = [210, 67, 12]; $hsb = [210, 67, 12];
$hsb_f = [210.5, 67.5, 12.5];
$hsl = [210, 50, 7.8]; $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 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>"; 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 // 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]: " print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: "
. DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2])) . "<br>"; . 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]: " print "S::COLOR hsl->rgb: $hsl[0], $hsl[1], $hsl[2]: "
. DgS::printAr(Colors::hsl2rgb($hsl[0], $hsl[1], $hsl[2])) . "<br>"; . DgS::printAr(Colors::hsl2rgb($hsl[0], $hsl[1], $hsl[2])) . "<br>";
@@ -76,6 +79,15 @@ $hsb = [0, 0, 5];
print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: " print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: "
. DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2])) . "<br>"; . DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2])) . "<br>";
// Random text
$h = rand(0, 359);
$s = rand(15, 70);
$b = 100;
$l = 50;
print "RANDOM IN: H: " . $h . ", S: " . $s . ", B/L: " . $b . "/" . $l . "<br>";
print "RANDOM hsb->rgb: <pre>" . DgS::printAr(Colors::hsb2rgb($h, $s, $b)) . "</pre><br>";
print "RANDOM hsl->rgb: <pre>" . DgS::printAr(Colors::hsl2rgb($h, $s, $l)) . "</pre><br>";
// TODO: run compare check input must match output // TODO: run compare check input must match output
// error message // error message

View File

@@ -69,6 +69,9 @@ $db->dbSetEncoding('SJIS');
print "ENCODING TEST: " . $db->dbVersionInfo('client_encoding') . "/" . $db->dbGetEncoding() . "<br>"; print "ENCODING TEST: " . $db->dbVersionInfo('client_encoding') . "/" . $db->dbGetEncoding() . "<br>";
$db->dbResetEncoding(); $db->dbResetEncoding();
$res = $db->dbReturn("SELECT * FROM max_test");
print "DB RETURN ROWS: " . $db->dbGetNumRows() . "<br>";
while (is_array($res = $db->dbReturn("SELECT * FROM max_test", DbIo::USE_CACHE, true))) { while (is_array($res = $db->dbReturn("SELECT * FROM max_test", DbIo::USE_CACHE, true))) {
print "UUD/TIME: " . $res['uid'] . "/" . $res['time'] . "<br>"; print "UUD/TIME: " . $res['uid'] . "/" . $res['time'] . "<br>";
} }
@@ -277,7 +280,7 @@ print "Wrote to DB tabel $table with data " . print_r($data, true) . " and got p
// return Array Test // return Array Test
$query = "SELECT type, sdate, integer FROM foobar"; $query = "SELECT type, sdate, integer FROM foobar";
$data = $db->dbReturnArray($query, true); $data = $db->dbReturnArray($query, true);
print "Full foobar list: <br><pre>" . print_r($data, true) . "</pre><br>"; print "Rows: " . $db->dbGetNumRows() . ", Full foobar list: <br><pre>" . print_r($data, true) . "</pre><br>";
// trigger a warning // trigger a warning
print "<b>WARNING NEXT</b><br>"; print "<b>WARNING NEXT</b><br>";

View File

@@ -1,6 +1,7 @@
{ {
"name": "gullevek/corelibs", "name": "gullevek/corelibs-dev",
"description": "CoreLibs", "version": "dev-master",
"description": "CoreLibs: Development package",
"type": "library", "type": "library",
"authors": [ "authors": [
{ {

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) // where global tables are that are used by all schemas (eg queue tables for online, etc)
// define('GLOBAL_DB_SCHEMA', PUBLIC_SCHEMA); // define('GLOBAL_DB_SCHEMA', PUBLIC_SCHEMA);
// debug settings, site lang, etc // debug settings, site lang, etc
define('TARGET', $SITE_CONFIG[HOST_NAME]['location']); define('TARGET', $SITE_CONFIG[HOST_NAME]['location'] ?? 'test');
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag']); define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag'] ?? false);
define('SITE_LANG', $SITE_CONFIG[HOST_NAME]['site_lang']); define('SITE_LANG', $SITE_CONFIG[HOST_NAME]['site_lang'] ?? 'en_utf8');
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled']); define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
// paths // paths
// define('CSV_PATH', $PATHS[TARGET]['csv_path']); // define('CSV_PATH', $PATHS[TARGET]['csv_path']);
// define('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']); // define('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']);
@@ -274,8 +275,8 @@ define('G_TITLE', $_ENV['G_TITLE'] ?? '');
/************ STYLE SHEETS / JS **********/ /************ STYLE SHEETS / JS **********/
define('ADMIN_STYLESHEET', 'edit.css'); define('ADMIN_STYLESHEET', 'edit.css');
define('ADMIN_JAVASCRIPT', 'edit.js'); define('ADMIN_JAVASCRIPT', 'edit.js');
define('STYLESHEET', 'frontend.css'); define('STYLESHEET', $_ENV['STYLESHEET'] ?? 'frontend.css');
define('JAVASCRIPT', 'frontend.js'); define('JAVASCRIPT', $_ENV['JAVASCRIPT'] ?? 'frontend.js');
// anything optional // anything optional
/************* INTERNAL ******************/ /************* INTERNAL ******************/

View File

@@ -4,7 +4,6 @@
* AUTHOR: Clemens Schwaighofer * AUTHOR: Clemens Schwaighofer
* CREATED: 2008/08/01 * CREATED: 2008/08/01
* SHORT DESCRIPTION: * SHORT DESCRIPTION:
* URL redirect header
* HISTORY: * HISTORY:
*********************************************************************/ *********************************************************************/

View File

@@ -66,7 +66,8 @@ class Colors
} }
$rgbArray = []; $rgbArray = [];
if (strlen($hexStr) == 6) { if (strlen($hexStr) == 6) {
// If a proper hex code, convert using bitwise operation. No overhead... faster // If a proper hex code, convert using bitwise operation.
// No overhead... faster
$colorVal = hexdec($hexStr); $colorVal = hexdec($hexStr);
$rgbArray['r'] = 0xFF & ($colorVal >> 0x10); $rgbArray['r'] = 0xFF & ($colorVal >> 0x10);
$rgbArray['g'] = 0xFF & ($colorVal >> 0x8); $rgbArray['g'] = 0xFF & ($colorVal >> 0x8);
@@ -135,13 +136,13 @@ class Colors
* hsb2rgb does not clean convert back to hsb in a round trip * hsb2rgb does not clean convert back to hsb in a round trip
* converts HSB/V to RGB values RGB is full INT * converts HSB/V to RGB values RGB is full INT
* if HSB/V value is invalid, sets this value to 0 * if HSB/V value is invalid, sets this value to 0
* @param int $H hue 0-360 (int) * @param float $H hue 0-360 (int)
* @param int $S saturation 0-100 (int) * @param float $S saturation 0-100 (int)
* @param int $V brightness/value 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 * @return array<int>|bool 0 red/1 green/2 blue array as 0-255
* false for input value error * 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 // check that H is 0 to 359, 360 = 0
// and S and V are 0 to 1 // and S and V are 0 to 1
@@ -270,12 +271,12 @@ class Colors
/** /**
* converts an HSL to RGB * converts an HSL to RGB
* if HSL value is invalid, set this value to 0 * 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 $sat saturation: 0-100
* @param float $lum luminance: 0-100 * @param float $lum luminance: 0-100
* @return array<int,float|int>|bool red/blue/green 0-255 each * @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)) { if (!is_numeric($hue)) {
return false; return false;
@@ -289,7 +290,8 @@ class Colors
if ($lum < 0 || $lum > 100) { if ($lum < 0 || $lum > 100) {
return false; return false;
} }
$hue = (1 / 360) * $hue; // calc to internal convert value for hue // calc to internal convert value for hue
$hue = (1 / 360) * $hue;
// convert to internal 0-1 format // convert to internal 0-1 format
$sat /= 100; $sat /= 100;
$lum /= 100; $lum /= 100;

View File

@@ -1786,9 +1786,12 @@ class IO
// count the rows returned (if select) // count the rows returned (if select)
$this->cursor_ext[$query_hash]['num_rows'] = $this->cursor_ext[$query_hash]['num_rows'] =
$this->db_functions->__dbNumRows($this->cursor_ext[$query_hash]['cursor']); $this->db_functions->__dbNumRows($this->cursor_ext[$query_hash]['cursor']);
// also set last return
$this->num_rows = $this->cursor_ext[$query_hash]['num_rows'];
// count the fields // count the fields
$this->cursor_ext[$query_hash]['num_fields'] = $this->cursor_ext[$query_hash]['num_fields'] =
$this->db_functions->__dbNumFields($this->cursor_ext[$query_hash]['cursor']); $this->db_functions->__dbNumFields($this->cursor_ext[$query_hash]['cursor']);
$this->num_fields = $this->cursor_ext[$query_hash]['num_fields'];
// set field names // set field names
$this->cursor_ext[$query_hash]['field_names'] = []; $this->cursor_ext[$query_hash]['field_names'] = [];
for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) { for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) {
@@ -1798,6 +1801,7 @@ class IO
$i $i
); );
} }
$this->field_names = $this->cursor_ext[$query_hash]['field_names'];
// reset first call vars // reset first call vars
$this->cursor_ext[$query_hash]['firstcall'] = 0; $this->cursor_ext[$query_hash]['firstcall'] = 0;
// reset the internal pos counter // reset the internal pos counter
@@ -2870,7 +2874,7 @@ class IO
*/ */
public function dbGetInsertPKName(): string public function dbGetInsertPKName(): string
{ {
return $this->insert_id_pk_name; return (string)$this->insert_id_pk_name;
} }
/** /**