diff --git a/4dev/tests/Convert/CoreLibsConvertMathTest.php b/4dev/tests/Convert/CoreLibsConvertMathTest.php
index 95002850..6441ca79 100644
--- a/4dev/tests/Convert/CoreLibsConvertMathTest.php
+++ b/4dev/tests/Convert/CoreLibsConvertMathTest.php
@@ -156,12 +156,32 @@ final class CoreLibsConvertMathTest extends TestCase
public function providerMultiplyMatrices(): array
{
return [
- 'single' => [
+ '[3] x [3] => [3x1]' => [
[1, 2, 3],
[1, 2, 3],
[14]
],
- 'double first' => [
+ '[3] x [3x1]' => [
+ [1, 2, 3],
+ [[1], [2], [3]],
+ [14]
+ ],
+ '[3] x [3x1]' => [
+ [1, 2, 3],
+ [[1], [2], [3]],
+ [14]
+ ],
+ '[1x3L] x [3x1]' => [
+ [[1, 2, 3]],
+ [[1], [2], [3]],
+ [14]
+ ],
+ '[1x3] x [3x1]' => [
+ [[1], [2], [3]],
+ [[1], [2], [3]],
+ [1, 2, 3]
+ ],
+ '[2x3] x [3] => [3x1]' => [
[
[1, 2, 3],
[1, 2, 3]
@@ -172,7 +192,18 @@ final class CoreLibsConvertMathTest extends TestCase
14
]
],
- 'double both' => [
+ '[2x3] x [3x1]' => [
+ [
+ [1, 2, 3],
+ [1, 2, 3]
+ ],
+ [[1], [2], [3]],
+ [
+ 14,
+ 14
+ ]
+ ],
+ '[2x3] x [2x3] => [3x3]' => [
[
[1, 2, 3],
[1, 2, 3],
@@ -186,7 +217,37 @@ final class CoreLibsConvertMathTest extends TestCase
[3, 6, 9]
]
],
- 'tripple first, single second' => [
+ '[2x3] x [3x3]' => [
+ [
+ [1, 2, 3],
+ [1, 2, 3],
+ ],
+ [
+ [1, 2, 3],
+ [1, 2, 3],
+ [0, 0, 0],
+ ],
+ [
+ [3, 6, 9],
+ [3, 6, 9]
+ ]
+ ],
+ '[2x3] x [3x2]' => [
+ 'a' => [
+ [1, 2, 3],
+ [1, 2, 3],
+ ],
+ 'b' => [
+ [1, 1],
+ [2, 2],
+ [3, 3],
+ ],
+ 'prod' => [
+ [14, 14],
+ [14, 14],
+ ]
+ ],
+ '[3x3] x [3] => [1x3]' => [
[
[1, 2, 3],
[1, 2, 3],
@@ -199,7 +260,7 @@ final class CoreLibsConvertMathTest extends TestCase
14
]
],
- 'tripple first, double second' => [
+ '[3x3] x [2x3] => [3x3]' => [
[
[1, 2, 3],
[1, 2, 3],
@@ -215,7 +276,24 @@ final class CoreLibsConvertMathTest extends TestCase
[3, 6, 9],
]
],
- 'single first, tripple second' => [
+ '[3x3] x [3x3]' => [
+ [
+ [1, 2, 3],
+ [1, 2, 3],
+ [1, 2, 3],
+ ],
+ [
+ [1, 2, 3],
+ [1, 2, 3],
+ // [0, 0, 0],
+ ],
+ [
+ [3, 6, 9],
+ [3, 6, 9],
+ [3, 6, 9],
+ ]
+ ],
+ '[3] x [3x3]' => [
[1, 2, 3],
[
[1, 2, 3],
@@ -226,7 +304,7 @@ final class CoreLibsConvertMathTest extends TestCase
[6, 12, 18],
]
],
- 'double first, tripple second' => [
+ '[2x3] x [3x3]' => [
[
[1, 2, 3],
[1, 2, 3],
diff --git a/composer.json b/composer.json
index 3f2c5950..2a90156b 100644
--- a/composer.json
+++ b/composer.json
@@ -10,7 +10,6 @@
"phpstan/phpstan": "^1.12",
"phan/phan": "^5.4",
"phpstan/extension-installer": "^1.4",
- "phpstan/phpstan-strict-rules": "^1.6",
"phpunit/phpunit": "^9",
"phpstan/phpstan-deprecation-rules": "^1.2",
"yamadashy/phpstan-friendly-formatter": "^1.1"
diff --git a/www/admin/class_test.convert.colors.php b/www/admin/class_test.convert.colors.php
index 0254ce67..6754aa51 100644
--- a/www/admin/class_test.convert.colors.php
+++ b/www/admin/class_test.convert.colors.php
@@ -54,7 +54,7 @@ function display(string $color, string $text, string $text_add): string
["{COLOR}", "{TEXT}", "{CSS}"],
[
$color,
- $text . ($text_add ? '
' . $text_add : ''),
+ $text . (!empty($text_add) ? '
' . $text_add : ''),
$css
],
$template
@@ -123,22 +123,16 @@ $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: "
- . CoreLibs\Convert\Colors::rgb2hex(-1, -1, -1) . "
";
+ . (new Coordinates\RGB([-1, -1, -1]))->returnAsHex() . "
";
} catch (\LengthException $e) {
- print "*Exception: " . $e->getMessage() . "
" . $e . "
";
-}
-try {
- print "\$C::S/COLOR invalid rgb->hex (gray 125): -1, -1, -1: "
- . $color_class::rgb2hex(-1, -1, -1) . "
";
-} catch (\LengthException $e) {
- print "**Exception: " . $e->getMessage() . "
" . print_r($e, true) . "
";
+ print "*Exception: " . $e->getMessage() . "
" . print_r($e, true) . "
";
}
print "
";
+print "LEGACY
";
// B(valid)
$rgb = [50, 20, 30];
$hex = '#0a141e';
@@ -189,13 +183,16 @@ $s = rand(15, 70);
$b = 100;
$l = 50;
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 "RANDOM hsb->rgb: "
+ . DgS::printAr(SetVarType::setArray(Color::hsbToRgb(new Coordinates\HSB([$h, $s, $b])))) . "
";
+print "RANDOM hsl->rgb: "
+ . DgS::printAr(SetVarType::setArray(Color::hslToRgb(new Coordinates\HSL([$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])) . "
";
+print "rgb 0,0,0: " . Dgs::printAr($rgb) . " => "
+ . Dgs::printAr(Color::rgbToHsb(new Coordinates\RGB([$rgb[0], $rgb[1], $rgb[2]]))) . "
";
print "
";
diff --git a/www/admin/class_test.math.php b/www/admin/class_test.math.php
index 287dc78f..d3af1f39 100644
--- a/www/admin/class_test.math.php
+++ b/www/admin/class_test.math.php
@@ -23,7 +23,6 @@ $log = new CoreLibs\Logging\Logging([
'log_file_id' => $LOG_FILE_ID,
'log_per_date' => true,
]);
-$_math = new CoreLibs\Convert\Math();
$math_class = 'CoreLibs\Convert\Math';
// define a list of from to color sets for conversion test
@@ -35,13 +34,9 @@ print "";
print '';
print '' . $PAGE_NAME . '
';
-print "FCEIL: " . $_math->fceil(5.1234567890, 5) . "
";
-print "FLOORP: " . $_math->floorp(5123456, -3) . "
";
-print "FLOORP: " . $_math->floorp(5123456, -10) . "
";
-print "INITNUMERIC: " . $_math->initNumeric('123') . "
";
-
print "S-FCEIL: " . $math_class::fceil(5.1234567890, 5) . "
";
print "S-FLOORP: " . $math_class::floorp(5123456, -3) . "
";
+print "S-FLOORP: " . $math_class::floorp(5123456, -10) . "
";
print "S-INITNUMERIC: " . $math_class::initNumeric(123) . "
";
print "S-INITNUMERIC: " . $math_class::initNumeric(123.456) . "
";
print "S-INITNUMERIC: " . $math_class::initNumeric('123') . "
";
diff --git a/www/lib/CoreLibs/Basic.php b/www/lib/CoreLibs/Basic.php
index 065ec63e..db57672a 100644
--- a/www/lib/CoreLibs/Basic.php
+++ b/www/lib/CoreLibs/Basic.php
@@ -1139,118 +1139,6 @@ class Basic
// *** BETTER PASSWORD OPTIONS END ***
- // *** COLORS ***
- // [!!! DEPRECATED !!!]
- // moved to \CoreLibs\Convert\Colors
-
- /**
- * converts a hex RGB color to the int numbers
- * @param string $hexStr RGB hexstring
- * @param bool $returnAsString flag to return as string
- * @param string $seperator string seperator: default: ","
- * @return string|array|bool false on error or array with RGB or
- * a string with the seperator
- * @deprecated use \CoreLibs\Convert\Colors::hex2rgb() instead
- */
- public static function hex2rgb(string $hexStr, bool $returnAsString = false, string $seperator = ',')
- {
- trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::hex2rgb()', E_USER_DEPRECATED);
- return \CoreLibs\Convert\Colors::hex2rgb($hexStr, $returnAsString, $seperator);
- }
-
- /**
- * converts the rgb values from int data to the valid rgb html hex string
- * optional can turn of leading #
- * @param int $red red 0-255
- * @param int $green green 0-255
- * @param int $blue blue 0-255
- * @param bool $hex_prefix default true, prefix with "#"
- * @return string|bool rgb in hex values with leading # if set
- * @deprecated use \CoreLibs\Convert\Colors::rgb2hex() instead
- */
- public static function rgb2hex(int $red, int $green, int $blue, bool $hex_prefix = true)
- {
- trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::rgb2hex()', E_USER_DEPRECATED);
- return \CoreLibs\Convert\Colors::rgb2hex($red, $green, $blue, $hex_prefix);
- }
-
- /**
- * converts and int RGB to the HTML color string in hex format
- * @param int $red red 0-255
- * @param int $green green 0-255
- * @param int $blue blue 0-255
- * @return string|bool hex rgb string
- * @deprecated use rgb2hex instead
- */
- public static function rgb2html(int $red, int $green, int $blue)
- {
- trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::rgb2hex()', E_USER_DEPRECATED);
- // check that each color is between 0 and 255
- return \CoreLibs\Convert\Colors::rgb2hex($red, $green, $blue, true);
- }
-
- /**
- * converts RGB to HSB/V values
- * returns:
- * array with hue (0-360), sat (0-100%), brightness/value (0-100%)
- * @param int $red red 0-255
- * @param int $green green 0-255
- * @param int $blue blue 0-255
- * @return array|bool Hue, Sat, Brightness/Value
- * @deprecated use \CoreLibs\Convert\Colors::rgb2hsb() instead
- */
- public static function rgb2hsb(int $red, int $green, int $blue)
- {
- trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::rgb2hsb()', E_USER_DEPRECATED);
- return \CoreLibs\Convert\Colors::rgb2hsb($red, $green, $blue);
- }
-
- /**
- * converts HSB/V to RGB values RGB is full INT
- * @param int $H hue 0-360
- * @param float $S saturation 0-1 (float)
- * @param float $V brightness/value 0-1 (float)
- * @return array|bool 0 red/1 green/2 blue array
- * @deprecated use \CoreLibs\Convert\Colors::hsb2rgb() instead
- */
- public static function hsb2rgb(int $H, float $S, float $V)
- {
- trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::hsb2rgb()', E_USER_DEPRECATED);
- return \CoreLibs\Convert\Colors::hsb2rgb($H, (int)round($S * 100), (int)round($V * 100));
- }
-
- /**
- * converts a RGB (0-255) to HSL
- * return:
- * array with hue (0-360), saturation (0-100%) and luminance (0-100%)
- * @param int $r red 0-255
- * @param int $g green 0-255
- * @param int $b blue 0-255
- * @return array|bool hue/sat/luminance
- * @deprecated use \CoreLibs\Convert\Colors::rgb2hsl() instead
- */
- public static function rgb2hsl(int $r, int $g, int $b)
- {
- trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::rgb2hsl()', E_USER_DEPRECATED);
- return \CoreLibs\Convert\Colors::rgb2hsb($r, $g, $b);
- }
-
- /**
- * converts an HSL to RGB
- * @param int $h hue: 0-360 (degrees)
- * @param float $s saturation: 0-1
- * @param float $l luminance: 0-1
- * @return array|bool red/blue/green 0-255 each
- * @deprecated use \CoreLibs\Convert\Colors::hsl2rgb() instead
- */
- public static function hsl2rgb(int $h, float $s, float $l)
- {
- trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::hsl2rgb()', E_USER_DEPRECATED);
- return \CoreLibs\Convert\Colors::hsl2rgb($h, $s * 100, $l * 100);
- }
-
- // *** COLORS END ***
-
// *** EMAIL FUNCTIONS ***
// [!!! DEPRECATED !!!]
// Moved to \CoreLibs\Check\Email
diff --git a/www/lib/CoreLibs/Convert/Color/CieXyz.php b/www/lib/CoreLibs/Convert/Color/CieXyz.php
index d8fd927c..2784f3e8 100644
--- a/www/lib/CoreLibs/Convert/Color/CieXyz.php
+++ b/www/lib/CoreLibs/Convert/Color/CieXyz.php
@@ -264,7 +264,7 @@ class CieXyz
private static function linRgbToXyzD65(RGB $rgb): XYZ
{
// if not linear, convert to linear
- if (!$rgb->get('linear')) {
+ if (!(bool)$rgb->get('linear')) {
$rgb = (new RGB($rgb->returnAsArray()))->toLinear();
}
return new XYZ(self::convertArray(Math::multiplyMatrices(
diff --git a/www/lib/CoreLibs/Convert/Colors.php b/www/lib/CoreLibs/Convert/Colors.php
index 52f3f9d8..b24747be 100644
--- a/www/lib/CoreLibs/Convert/Colors.php
+++ b/www/lib/CoreLibs/Convert/Colors.php
@@ -33,6 +33,7 @@ class Colors
* @param bool $hex_prefix default true, prefix with "#"
* @return string rgb in hex values with leading # if set,
* @throws \LengthException If any argument is not in the range of 0~255
+ * @deprecated v9.20.0 use: new Coordinates\RGB([$red, $green, $blue]))->returnAsHex(true/false for #)
*/
public static function rgb2hex(
int $red,
@@ -53,6 +54,7 @@ class Colors
* or a string with the seperator
* @throws \InvalidArgumentException if hex string is empty
* @throws \UnexpectedValueException if the hex string value is not valid
+ * @deprecated v9.20.0 use: new Coordinates\RGB($hex_string) (build string/array from return data)
*/
public static function hex2rgb(
string $hex_string,
@@ -91,6 +93,7 @@ class Colors
* @param int $blue blue 0-255
* @return array Hue, Sat, Brightness/Value
* @throws \LengthException If any argument is not in the range of 0~255
+ * @deprecated v9.20.0 use: Color::rgbToHsb(...)->returnAsArray() will return float unrounded
*/
public static function rgb2hsb(int $red, int $green, int $blue): array
{
@@ -112,6 +115,7 @@ class Colors
* @param float $V brightness/value 0-100 (int)
* @return array 0 red/1 green/2 blue array as 0-255
* @throws \LengthException If any argument is not in the valid range
+ * @deprecated v9.20.0 use: Color::hsbToRgb(...)->returnAsArray() will return float unrounded
*/
public static function hsb2rgb(float $H, float $S, float $V): array
{
@@ -133,6 +137,7 @@ class Colors
* @param int $blue blue 0-255
* @return array hue/sat/luminance
* @throws \LengthException If any argument is not in the range of 0~255
+ * @deprecated v9.20.0 use: Color::rgbToHsl(...)->returnAsArray() will return float unrounded
*/
public static function rgb2hsl(int $red, int $green, int $blue): array
{
@@ -153,6 +158,7 @@ class Colors
* @param float $lum luminance: 0-100
* @return array red/blue/green 0-255 each
* @throws \LengthException If any argument is not in the valid range
+ * @deprecated v9.20.0 use: Color::hslToRgb(...)->returnAsArray() will return float unrounded
*/
public static function hsl2rgb(float $hue, float $sat, float $lum): array
{
diff --git a/www/lib/CoreLibs/Convert/Math.php b/www/lib/CoreLibs/Convert/Math.php
index a20085f7..41eb7463 100644
--- a/www/lib/CoreLibs/Convert/Math.php
+++ b/www/lib/CoreLibs/Convert/Math.php
@@ -136,6 +136,28 @@ class Math
*
* It returns an array which is the product of the two number matrices passed as parameters.
*
+ * NOTE:
+ * if the right side (B matrix) has a missing row, this row will be fillwed with 0 instead of
+ * throwing an error:
+ * A:
+ * [
+ * [1, 2, 3],
+ * [4, 5, 6],
+ * ]
+ * B:
+ * [
+ * [7, 8, 9],
+ * [10, 11, 12],
+ * ]
+ * The B will get a third row with [0, 0, 0] added to make the multiplication work as it will be
+ * rewritten as
+ * B-rewrite:
+ * [
+ * [7, 10, 0],
+ * [8, 11, 12],
+ * [0, 0, 0] <- automatically added
+ * ]
+ *
* @param array> $a m x n matrice
* @param array> $b n x p matrice
*
@@ -161,8 +183,9 @@ class Math
$p = count($b[0]);
// transpose $b:
+ // so that we can multiply row by row
$bCols = array_map(
- callback: fn ($k) => \array_map(
+ callback: fn ($k) => array_map(
(fn ($i) => is_array($i) ? $i[$k] : 0),
$b,
),
@@ -175,7 +198,8 @@ class Math
array_reduce(
array: $row,
callback: fn ($a, $v, $i = null) => $a + $v * (
- $col[$i ?? array_search($v, $row) ?: 0]
+ // if last entry missing for full copy add a 0 to it
+ $col[$i ?? array_search($v, $row, true)] ?? 0 /** @phpstan-ignore-line */
),
initial: 0,
) :
@@ -191,7 +215,7 @@ class Math
if ($m === 1) {
// Avoid [[a, b, c, ...]]:
- $product = $product[0];
+ return $product[0];
}
if ($p === 1) {