diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index 946a21c..ff7db18 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -1516,3 +1516,892 @@ declare var printf: typeof lib_plankton.string.printf; declare var eml_log: any; declare var track_exports: any; declare var make_logger: (prefix: any, current_loglevel: any) => (obj: any, lvl: any) => void; +declare namespace lib_plankton.complex { + /** + * @author fenris + */ + type type_complex = { + rea: float; + ima: float; + }; + /** + * erstellt eine komplexe Zahl anhand ihrer kartesianischen Koordinaten + * + * @author fenris + */ + function make_cartesian(rea_: float, ima_: float): type_complex; + /** + * erstellt eine komplexe Zahl anhand ihrer Polar-Koordinaten + * + * @author fenris + */ + function make_polar(abs: float, arg: float): type_complex; + /** + * alias zu "make_cartesian" + * + * @author fenris + */ + function make(rea_: float, ima_: float): type_complex; + /** + * erstellt die komplexe Null + * + * @author fenris + */ + function nul(): type_complex; + /** + * erstellt die komplexe Eins + * + * @author fenris + */ + function one(): type_complex; + /** + * gibt den Real-Teil einer komplexen Zahl zurück + * + * @author fenris + */ + function rea(x: type_complex): float; + /** + * gibt den Imaginär-Teil einer komplexen Zahl zurück + * + * @author fenris + */ + function ima(x: type_complex): float; + /** + * gibt die konjugierte komplexe Zahl zurück + * + * @author fenris + */ + function con(x: type_complex): type_complex; + /** + * gibt den Betrag einer komplexen Zahl zurück + * + * @author fenris + */ + function abs(x: type_complex): float; + /** + * gibt das Argument einer komplexen Zahl zurück (auf dem Hauptzweig des komplexen Logarithmus) + * + * @author fenris + */ + function arg(x: type_complex): float; + /** + * gibt eine skalierte komplexe Zahl zurück (das Produkt mit einer reellen Zahl) + * + * @author fenris + */ + function scl(x: type_complex, s: float): type_complex; + /** + * errechnet die Summe zweier komplexer Zahl + * + * @author fenris + */ + function add(x: type_complex, y: type_complex): type_complex; + /** + * gibt die additiv inverse, also negierte komplexe Zahl zurück + * + * @author fenris + */ + function neg(x: type_complex): type_complex; + /** + * ermittelt die Differenz zweier komplexer Zahlen + * + * @author fenris + */ + function sub(x: type_complex, y: type_complex): type_complex; + /** + * ermittelt das Produkt zweier komplexer Zahlen + * + * @author fenris + */ + function mul(x: type_complex, y: type_complex): type_complex; + /** + * ermittelt die multiplikativ inverse komplexe Zahl, also den Kehrwert + * + * @author fenris + */ + function inv(x: type_complex): type_complex; + /** + * ermittelt den Quotienten zweier komplexer Zahlen + * + * @author fenris + */ + function div(x: type_complex, y: type_complex): type_complex; + /** + * ermittelt die natürliche Potenz einer komplexen Zahl + * + * @author fenris + */ + function npow(x: type_complex, n: int): type_complex; + /** + * ermittelt die natürliche Potenz einer komplexen Zahl + * + * @author fenris + * @deprecated use "npow" instead + * @todo remove + */ + function exp(x: type_complex, n: int): type_complex; + /** + * ermittelt die Potenz zweier komplexer Zahlen + * + * @author fenris + * @todo Probleme der komplexen Exponentiation berücksichtigen + */ + function pow(x: type_complex, y: type_complex): type_complex; + /** + * gibt die n-ten komplexen Einheits-Wurzeln zurück ({x ∈ C | x^n = 1}) + * + * @author fenris + */ + function unitroots(n: int): Array; + /** + * {x ∈ C | x^n = y} + * + * @author fenris + */ + function normroots(n: int, y: type_complex): Array; + /** + * ermittelt ob zwei komplexe Zahlen gleich sind + * + * @author fenris + */ + function equ(x: type_complex, y: type_complex, threshold?: float): boolean; + /** + * gibt eine textuelle Repräsentation einer komplexen Zahl zurück + * + * @author fenris + */ + function str(x: type_complex): string; +} +declare namespace lib_plankton.complex { + /** + * @author fenris + */ + class class_complex { + /** + * @author fenris + */ + private subject; + /** + * @author fenris + */ + private constructor(); + /** + * @author fenris + */ + private static _cram; + /** + * @author fenris + */ + private static _tear; + /** + * @author fenris + */ + static make_cartesian(rea: float, ima: float): class_complex; + /** + * @author fenris + */ + static make_polar(abs: float, arg: float): class_complex; + /** + * @author fenris + */ + static make(rea: float, ima: float): class_complex; + /** + * @author fenris + */ + static nul(): class_complex; + /** + * @author fenris + */ + static one(): class_complex; + /** + * @author fenris + */ + con(): class_complex; + /** + * @author fenris + */ + abs(): float; + /** + * @author fenris + */ + arg(): float; + /** + * @author fenris + */ + scl(s: float): class_complex; + /** + * @author fenris + */ + add(other: class_complex): class_complex; + /** + * @author fenris + */ + neg(): class_complex; + /** + * @author fenris + */ + sub(other: class_complex): class_complex; + /** + * @author fenris + */ + mul(other: class_complex): class_complex; + /** + * @author fenris + */ + inv(): class_complex; + /** + * @author fenris + */ + div(other: class_complex): class_complex; + /** + * @author fenris + */ + exp(n: int): class_complex; + /** + * @author fenris + */ + pow(other: class_complex): class_complex; + /** + * @author fenris + */ + equ(other: class_complex): boolean; + /** + * @author fenris + */ + str(): string; + /** + * @author fenris + */ + toString(): string; + } +} +declare namespace lib_plankton.math { + /** + * @desc golden ratio (e.g. for generating colors) + * @author fenris + */ + const phi: float; + /** + * @author fenris + */ + const e: float; + /** + * @author fenris + */ + const pi: float; + /** + * @author fenris + */ + const tau: float; +} +declare namespace lib_plankton.math { + /** + * @author fenris + */ + function clamp(x: number, a?: number, b?: number): number; + /** + * @desc the mathematical sign-function + * @return {int} an element of {-1,0,+1} + * @author fenris + */ + function sgn(x: number): int; + /** + * @desc integer division + * @author fenris + */ + function div(x: float, y: float): float; + /** + * @desc real modulo operator + * @author fenris + */ + function mod(x: float, y: float): float; + /** + * @desc computes "x^y mod z" via square-and-multiply + * @param {int} base ("x") + * @param {int} exponent ("y") + * @param {int} modulus ("z") + * @return {int} + * @author fenris + * @todo handle invalid cases (e.g. "z < 1") + * @todo implement iteratively + */ + function modpow(base: int, exponent: int, modulus: int): int; + /** + * @desc determines if two integers are coprime, i.e. that they don't have a common divisor greater than 1 + * @author fenris + * @todo write function "gcdx" and base on it + */ + function coprime(x: int, y: int): boolean; + /** + * @desc extended euclidean algorithm for computing multiplicative inverse elements + * @param {int} modulus + * @param {int} element + * @author fenris + * @todo write function "gcdx" and base on it + * @todo handle more invalid cases + */ + function inv(modulus: int, element: int, positive?: boolean): int; + /** + * @author fenris + */ + function interpolate_linear(x: number, y: number, t?: number): number; + /** + * @desc kind of the inverse of linear interpolation; i.e. to find the coefficient "t" for given values x, y and + * their presumed interpolation v + * @author fenris + */ + function appoint_linear(x: number, y: number, v: number): number; + /** + * continued fraction decomposition + */ + function cfd(x: float, n?: int): Array; +} +declare namespace lib_plankton.math { + /** + * @author fenris + */ + type type_relationparameters = { + symbol?: string; + name?: string; + predicate?: (value: type_value, reference: type_value) => boolean; + }; + /** + * @author fenris + */ + class class_relation implements interface_showable, interface_hashable, interface_collatable> { + /** + * @author fenris + */ + protected id: string; + /** + * @author fenris + */ + protected symbol: string; + /** + * @author fenris + */ + protected name: string; + /** + * @author fenris + */ + protected predicate: (value: type_value, reference: type_value) => boolean; + /** + * @author fenris + */ + check(value: type_value, reference: type_value): boolean; + /** + * @author fenris + */ + constructor(id: string, { "symbol": symbol, "name": name, "predicate": predicate, }: type_relationparameters); + /** + * @author fenris + */ + id_get(): string; + /** + * @author fenris + */ + symbol_get(): string; + /** + * @author fenris + */ + name_get(): string; + /** + * @desc [accessor] [implementation] + * @author fenris + */ + _show(): string; + /** + * @desc [accessor] [implementation] + * @author fenris + */ + _hash(): string; + /** + * @desc [accessor] [implementation] + * @author fenris + */ + _collate(relation: class_relation): boolean; + /** + * @author fenris + */ + toString(): string; + /** + * @author fenris + */ + protected static pool(): { + [id: string]: type_relationparameters; + }; + /** + * @author fenris + */ + static get(id: string): class_relation; + /** + * @author fenris + */ + static available(): Array; + } + /** + * @author fenris + */ + class class_filtrationitem implements interface_showable { + /** + * @author fenris + */ + protected extract: (dataset: Object) => type_value; + /** + * @author fenris + */ + protected relation: class_relation; + /** + * @author fenris + */ + protected reference: type_value; + /** + * @author fenris + */ + constructor({ "extract": extract, "relation": relation, "reference": reference, }: { + extract: (dataset: Object) => type_value; + relation: class_relation; + reference: type_value; + }); + /** + * @author fenris + */ + check(dataset: Object): boolean; + /** + * @desc [implementation] + * @author fenris + */ + _show(): string; + /** + * @author fenris + */ + toString(): string; + } + /** + * @desc disjunctive normal form + * @author fenris + */ + class class_filtration implements interface_showable { + /** + * @author fenris + */ + protected clauses: Array>>; + /** + * @author fenris + */ + constructor(clauses: Array>>); + /** + * @author fenris + */ + check(dataset: Object): boolean; + /** + * @author fenris + */ + use(datasets: Array): Array; + /** + * @desc [implementation] + * @author fenris + */ + _show(): string; + /** + * @author fenris + */ + toString(): string; + } + /** + * @author fenris + * @deprecated + */ + function comparator_to_relation(comparator: (x: type_value, y: type_value) => int): (x: type_value, y: type_value) => boolean; + /** + * @author fenris + * @deprecated + */ + function relation_to_comparator(relation: (x: type_value, y: type_value) => boolean): (x: type_value, y: type_value) => int; +} +declare module lib_calculus { + /** + * @class Calculus + * @desc Ensure precision of mathematical operations + */ + class Calculus { + /** @desc only for typescript + */ + private NORM; + /** + * @constructor + * @þaram {number} norm + */ + constructor(norm?: number); + /** + * normalize + * @param {number} value + * @return {number} + */ + normalize(value: number): number; + /** + * denormalize + * @param {number} value + * @return {number} + */ + denormalize(value: number): number; + } +} +declare namespace lib_plankton.math { + /** + * {x ∈ C | 0 = ax³ + bx² + cx + d} + * + * @author fenris + */ + function cubic_solve(a: lib_plankton.complex.type_complex, b: lib_plankton.complex.type_complex, c: lib_plankton.complex.type_complex, d: lib_plankton.complex.type_complex): Array; + /** + * {x ∈ C | 0 = ax³ + bx² + cx + d} + * + * @author fenris + */ + function cubic_solve_real(a: float, b: float, c: float, d: float): Array; +} +declare namespace lib_plankton.color { + /** + * @author fenris + */ + type type_model_hsv = { + hue: float; + saturation: float; + value: float; + }; + /** + * @author fenris + */ + type type_model_hsl = { + hue: float; + saturation: float; + lightness: float; + }; + /** + * @author fenris + */ + type type_model_rgb = { + red: float; + green: float; + blue: float; + }; + /** + * @author fenris + */ + type type_color = { + model: type_model_rgb; + }; + /** + * @author fenris + */ + function make_hsv({ "hue": hue, "saturation": saturation, "value": value }: { + hue?: float; + saturation?: float; + value?: float; + }): type_color; + /** + * @author fenris + */ + function make_hsl(model_hsl: type_model_hsl): type_color; + /** + * @author fenris + */ + function make_rgb(model_rgb: type_model_rgb): type_color; + /** + * @author fenris + */ + function to_hsv(color: type_color): type_model_hsv; + /** + * @author fenris + */ + function to_hsl(color: type_color): type_model_hsl; + /** + * @author fenris + */ + function to_rgb(color: type_color): type_model_rgb; + /** + * @author fenris + */ + function to_cmyk(color: type_color): type_model_rgb; + /** + * @author fenris + */ + function add(color1: type_color, color2: type_color): type_color; + /** + * @author fenris + */ + function multiply(color1: type_color, color2: type_color): type_color; + /** + * @author fenris + * @todo blend through other model? + */ + function blend(color1: type_color, color2: type_color, strength?: float): type_color; + /** + * @author fenris + */ + function mix(color1: type_color, color2: type_color, strength1?: float, strength2?: float): type_color; + /** + * @author fenris + */ + function output_rgb(color: type_color): string; + /** + * @author fenris + */ + function output_hex(color: type_color): string; + /** + * @author fenris + */ + function output_dot(color: type_color): string; + /** + * @author fenris + */ + function give_generic({ "n": n, "offset": offset, "saturation": saturation, "value": value, }: { + n: int; + offset?: float; + saturation?: float; + value?: float; + }): type_color; + /** + * @author fenris + */ + function give_gray(value?: float): type_color; + /** + * @author fenris + */ + function give_black(): type_color; + /** + * @author fenris + */ + function give_white(): type_color; + /** + * @author fenris + */ + function give_red({ "saturation": saturation, "value": value, }?: { + saturation?: float; + value?: float; + }): type_color; + /** + * @author fenris + */ + function give_green({ "saturation": saturation, "value": value, }?: { + saturation?: float; + value?: float; + }): type_color; + /** + * @author fenris + */ + function give_blue({ "saturation": saturation, "value": value, }?: { + saturation?: float; + value?: float; + }): type_color; + /** + * @author fenris + */ + function give_yellow({ "saturation": saturation, "value": value, }?: { + saturation?: float; + value?: float; + }): type_color; + /** + * @author fenris + */ + function give_cyan({ "saturation": saturation, "value": value, }?: { + saturation?: float; + value?: float; + }): type_color; + /** + * @author fenris + */ + function give_magenta({ "saturation": saturation, "value": value, }?: { + saturation?: float; + value?: float; + }): type_color; +} +declare namespace lib_plankton.color { + /** + * @author fenris + */ + class class_color { + /** + * @author fenris + */ + private subject; + /** + * @author fenris + */ + protected constructor(subject: type_color); + /** + * @author fenris + */ + private static _cram; + /** + * @author fenris + */ + private static _tear; + /** + * @author fenris + */ + static make_hsv({ "hue": hue, "saturation": saturation, "value": value }: { + hue?: float; + saturation?: float; + value?: float; + }): class_color; + /** + * @author fenris + */ + blend(color: class_color, strength?: float): class_color; + /** + * @author fenris + */ + output_rgb(): string; + /** + * @author fenris + */ + output_hex(): string; + /** + * @author fenris + */ + output_dot(): string; + /** + * @author fenris + */ + static give_generic({ "n": n, "offset": offset, "saturation": saturation, "value": value, }: { + n: int; + offset?: float; + saturation?: float; + value?: float; + }): class_color; + static generic(x: any): class_color; + /** + * @author fenris + */ + static give_gray(value?: float): class_color; + /** + * @author fenris + */ + static give_black(): class_color; + /** + * @author fenris + */ + static give_white(): class_color; + /** + * @author fenris + */ + static give_red({ "saturation": saturation, "value": value, }?: { + saturation?: float; + value?: float; + }): class_color; + /** + * @author fenris + */ + static give_green({ "saturation": saturation, "value": value, }?: { + saturation?: float; + value?: float; + }): class_color; + /** + * @author fenris + */ + static give_blue({ "saturation": saturation, "value": value, }?: { + saturation?: float; + value?: float; + }): class_color; + /** + * @author fenris + */ + static give_yellow({ "saturation": saturation, "value": value, }?: { + saturation?: float; + value?: float; + }): class_color; + /** + * @author fenris + */ + static give_cyan({ "saturation": saturation, "value": value, }?: { + saturation?: float; + value?: float; + }): class_color; + /** + * @author fenris + */ + static give_magenta({ "saturation": saturation, "value": value, }?: { + saturation?: float; + value?: float; + }): class_color; + } +} +/** + * @author fenris + */ +declare namespace lib_plankton.xml { + /** + * @author fenris + */ + abstract class class_node { + /** + * @author fenris + */ + abstract compile(depth?: int): string; + } + /** + * @author fenris + */ + class class_node_text extends class_node { + /** + * @author fenris + */ + protected content: string; + /** + * @author fenris + */ + constructor(content: string); + /** + * @author fenris + */ + compile(depth?: int): string; + } + /** + * @author fenris + */ + class class_node_comment extends class_node { + /** + * @author fenris + */ + protected content: string; + /** + * @author fenris + */ + constructor(content: string); + /** + * @author fenris + */ + compile(depth?: int): string; + } + /** + * @author fenris + */ + class class_node_complex extends class_node { + /** + * @author fenris + */ + protected name: string; + /** + * @author fenris + */ + protected attributes: { + [key: string]: string; + }; + /** + * @author fenris + */ + protected children: Array; + /** + * @author fenris + */ + constructor(name: string, attributes?: { + [key: string]: string; + }, children?: any[]); + /** + * @author fenris + */ + compile(depth?: int): string; + } +} diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index b2ef82c..214a149 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -4734,3 +4734,1721 @@ var make_logger = (function () { } return make_logger; })(); +/* +This file is part of »bacterio-plankton:complex«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:complex« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:complex« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:complex«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var complex; + (function (complex) { + /** + * @author fenris + */ + function _sequence(n) { + return ((n <= 0) ? [] : _sequence(n - 1).concat([n - 1])); + } + /** + * @author fenris + */ + function _coin(template, arguments_) { + if (arguments_ === void 0) { arguments_ = {}; } + var result = template; + Object.keys(arguments_).forEach(function (key) { + var pattern = ("{{" + key + "}}"); + var replacement = String(arguments_[key]); + result = result.replace(new RegExp(pattern, "g"), replacement); + }); + return result; + } + /** + * erstellt eine komplexe Zahl anhand ihrer kartesianischen Koordinaten + * + * @author fenris + */ + function make_cartesian(rea_, ima_) { + return { + "rea": rea_, + "ima": ima_ + }; + } + complex.make_cartesian = make_cartesian; + /** + * erstellt eine komplexe Zahl anhand ihrer Polar-Koordinaten + * + * @author fenris + */ + function make_polar(abs, arg) { + return (make_cartesian((abs * Math.cos(arg)), (abs * Math.sin(arg)))); + } + complex.make_polar = make_polar; + /** + * alias zu "make_cartesian" + * + * @author fenris + */ + function make(rea_, ima_) { + return (make_cartesian(rea_, ima_)); + } + complex.make = make; + /** + * erstellt die komplexe Null + * + * @author fenris + */ + function nul() { + return (make(0, 0)); + } + complex.nul = nul; + /** + * erstellt die komplexe Eins + * + * @author fenris + */ + function one() { + return (make(1, 0)); + } + complex.one = one; + /** + * gibt den Real-Teil einer komplexen Zahl zurück + * + * @author fenris + */ + function rea(x) { + return (x.rea); + } + complex.rea = rea; + /** + * gibt den Imaginär-Teil einer komplexen Zahl zurück + * + * @author fenris + */ + function ima(x) { + return (x.ima); + } + complex.ima = ima; + /** + * gibt die konjugierte komplexe Zahl zurück + * + * @author fenris + */ + function con(x) { + return (make(+x.rea, -x.ima)); + } + complex.con = con; + /** + * gibt den quadrierten Betrag einer komplexen Zahl zurück + * + * @author fenris + */ + function sqrabs(x) { + return (((x.rea * x.rea) + (x.ima * x.ima))); + } + /** + * gibt den Betrag einer komplexen Zahl zurück + * + * @author fenris + */ + function abs(x) { + return (Math.sqrt(sqrabs(x))); + } + complex.abs = abs; + /** + * gibt das Argument einer komplexen Zahl zurück (auf dem Hauptzweig des komplexen Logarithmus) + * + * @author fenris + */ + function arg(x) { + return Math.atan2(x.ima, x.rea); + } + complex.arg = arg; + /** + * gibt eine skalierte komplexe Zahl zurück (das Produkt mit einer reellen Zahl) + * + * @author fenris + */ + function scl(x, s) { + return (make((x.rea * s), (x.ima * s))); + } + complex.scl = scl; + /** + * errechnet die Summe zweier komplexer Zahl + * + * @author fenris + */ + function add(x, y) { + return (make((x.rea + y.rea), (x.ima + y.ima))); + } + complex.add = add; + /** + * gibt die additiv inverse, also negierte komplexe Zahl zurück + * + * @author fenris + */ + function neg(x) { + return (make(-x.rea, -x.ima)); + } + complex.neg = neg; + /** + * ermittelt die Differenz zweier komplexer Zahlen + * + * @author fenris + */ + function sub(x, y) { + return (add(x, neg(y))); + } + complex.sub = sub; + /** + * ermittelt das Produkt zweier komplexer Zahlen + * + * @author fenris + */ + function mul(x, y) { + return (make(((x.rea * y.rea) - (x.ima * y.ima)), ((x.rea * y.ima) + (x.ima * y.rea)))); + } + complex.mul = mul; + /** + * ermittelt die multiplikativ inverse komplexe Zahl, also den Kehrwert + * + * @author fenris + */ + function inv(x) { + var a = sqrabs(x); + if (a <= 0) { + var message = "die komplexe Null ist nicht invertiebar"; + throw (new Error(message)); + } + else { + return (scl(con(x), (1 / a))); + } + } + complex.inv = inv; + /** + * ermittelt den Quotienten zweier komplexer Zahlen + * + * @author fenris + */ + function div(x, y) { + return (mul(x, inv(y))); + } + complex.div = div; + /** + * ermittelt die natürliche Potenz einer komplexen Zahl + * + * @author fenris + */ + function npow(x, n) { + if (n < 0) { + var message = "invalid exponent"; + throw (new Error(message)); + } + else { + var y_1 = one(); + _sequence(n).forEach(function () { y_1 = mul(y_1, x); }); + return y_1; + } + } + complex.npow = npow; + /** + * ermittelt die natürliche Potenz einer komplexen Zahl + * + * @author fenris + * @deprecated use "npow" instead + * @todo remove + */ + function exp(x, n) { + return npow(x, n); + } + complex.exp = exp; + /** + * ermittelt die Potenz zweier komplexer Zahlen + * + * @author fenris + * @todo Probleme der komplexen Exponentiation berücksichtigen + */ + function pow(x, y) { + var a = abs(x); + var b = arg(x); + var c = y.rea; + var d = y.ima; + if (a === 0) { + throw (new Error("not implemented")); + } + else { + var l = Math.log(a); + return (make_polar(Math.exp((l * c) - (b * d)), ((l * d) + (b * c)))); + } + } + complex.pow = pow; + /** + * gibt die n-ten komplexen Einheits-Wurzeln zurück ({x ∈ C | x^n = 1}) + * + * @author fenris + */ + function unitroots(n) { + return (_sequence(n) + .map(function (k) { return make_polar(1, (k / (n + 0.0)) * (2 * Math.PI)); })); + } + complex.unitroots = unitroots; + /** + * {x ∈ C | x^n = y} + * + * @author fenris + */ + function normroots(n, y) { + var z = make_polar(Math.pow(abs(y), (1.0 / n)), (arg(y) / n)); + return (unitroots(n) + .map(function (w) { return mul(w, z); })); + } + complex.normroots = normroots; + /** + * ermittelt ob zwei komplexe Zahlen gleich sind + * + * @author fenris + */ + function equ(x, y, threshold) { + if (threshold === void 0) { threshold = 0.005; } + // return (abs(sub(x, y)) <= threshold); + return ((Math.abs(x.rea - y.rea) <= threshold) + && + (Math.abs(x.ima - y.ima) <= threshold)); + } + complex.equ = equ; + /** + * gibt eine textuelle Repräsentation einer komplexen Zahl zurück + * + * @author fenris + */ + function str(x) { + return _coin( + // "(({{rea}}) + ({{ima}}·i))", + "<{{rea}},{{ima}}>", { + "rea": x.rea.toFixed(4), + "ima": x.ima.toFixed(4) + }); + } + complex.str = str; + })(complex = lib_plankton.complex || (lib_plankton.complex = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:complex«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:complex« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:complex« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:complex«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var complex; + (function (complex) { + /** + * @author fenris + */ + var class_complex = /** @class */ (function () { + /** + * @author fenris + */ + function class_complex(subject) { + this.subject = subject; + } + /** + * @author fenris + */ + class_complex._cram = function (subject) { + return (new class_complex(subject)); + }; + /** + * @author fenris + */ + class_complex._tear = function (instance) { + return instance.subject; + }; + /** + * @author fenris + */ + class_complex.make_cartesian = function (rea, ima) { + return (class_complex._cram(complex.make_cartesian(rea, ima))); + }; + /** + * @author fenris + */ + class_complex.make_polar = function (abs, arg) { + return (class_complex._cram(complex.make_polar(abs, arg))); + }; + /** + * @author fenris + */ + class_complex.make = function (rea, ima) { + return (class_complex._cram(complex.make(rea, ima))); + }; + /** + * @author fenris + */ + class_complex.nul = function () { + return (class_complex._cram(complex.nul())); + }; + /** + * @author fenris + */ + class_complex.one = function () { + return (class_complex._cram(complex.one())); + }; + /** + * @author fenris + */ + class_complex.prototype.con = function () { + return (class_complex._cram(complex.con(class_complex._tear(this)))); + }; + /** + * @author fenris + */ + class_complex.prototype.abs = function () { + return (complex.abs(class_complex._tear(this))); + }; + /** + * @author fenris + */ + class_complex.prototype.arg = function () { + return (complex.arg(class_complex._tear(this))); + }; + /** + * @author fenris + */ + class_complex.prototype.scl = function (s) { + return (class_complex._cram(complex.scl(class_complex._tear(this), s))); + }; + /** + * @author fenris + */ + class_complex.prototype.add = function (other) { + return (class_complex._cram(complex.add(class_complex._tear(this), class_complex._tear(other)))); + }; + /** + * @author fenris + */ + class_complex.prototype.neg = function () { + return (class_complex._cram(complex.neg(class_complex._tear(this)))); + }; + /** + * @author fenris + */ + class_complex.prototype.sub = function (other) { + return (class_complex._cram(complex.sub(class_complex._tear(this), class_complex._tear(other)))); + }; + /** + * @author fenris + */ + class_complex.prototype.mul = function (other) { + return (class_complex._cram(complex.mul(class_complex._tear(this), class_complex._tear(other)))); + }; + /** + * @author fenris + */ + class_complex.prototype.inv = function () { + return (class_complex._cram(complex.inv(class_complex._tear(this)))); + }; + /** + * @author fenris + */ + class_complex.prototype.div = function (other) { + return (class_complex._cram(complex.div(class_complex._tear(this), class_complex._tear(other)))); + }; + /** + * @author fenris + */ + class_complex.prototype.exp = function (n) { + return (class_complex._cram(complex.exp(class_complex._tear(this), n))); + }; + /** + * @author fenris + */ + class_complex.prototype.pow = function (other) { + return (class_complex._cram(complex.pow(class_complex._tear(this), class_complex._tear(other)))); + }; + /** + * @author fenris + */ + class_complex.prototype.equ = function (other) { + return (complex.equ(class_complex._tear(this), class_complex._tear(other))); + }; + /** + * @author fenris + */ + class_complex.prototype.str = function () { + return (complex.str(class_complex._tear(this))); + }; + /** + * @author fenris + */ + class_complex.prototype.toString = function () { + return this.str(); + }; + return class_complex; + }()); + complex.class_complex = class_complex; + })(complex = lib_plankton.complex || (lib_plankton.complex = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:math«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:math« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:math« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:math«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var math; + (function (math) { + /** + * @desc golden ratio (e.g. for generating colors) + * @author fenris + */ + math.phi = ((Math.sqrt(5) - 1) / 2); + /** + * @author fenris + */ + math.e = Math.E; + /** + * @author fenris + */ + math.pi = Math.PI; + /** + * @author fenris + */ + math.tau = (2 * Math.PI); + })(math = lib_plankton.math || (lib_plankton.math = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:math«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:math« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:math« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:math«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var math; + (function (math) { + /** + * @author fenris + */ + function clamp(x, a = 0.0, b = 1.0) { + return Math.min(Math.max(x, a), b); + } + math.clamp = clamp; + /** + * @desc the mathematical sign-function + * @return {int} an element of {-1,0,+1} + * @author fenris + */ + function sgn(x) { + if (x === 0) { + return 0; + } + else { + if (x < 0) { + return -1; + } + else /* (x > 0) */ { + return +1; + } + } + } + math.sgn = sgn; + /** + * @desc integer division + * @author fenris + */ + function div(x, y) { + return Math.floor(x / y); + } + math.div = div; + /** + * @desc real modulo operator + * @author fenris + */ + function mod(x, y) { + // return (x - (div(x, y) * y)); + if (y <= 0) { + throw (new Error("invalid divisor")); + } + else { + return ((x >= 0) + ? (x % y) + : ((y - ((-x) % y)) % y)); + } + } + math.mod = mod; + /** + * @desc computes "x^y mod z" via square-and-multiply + * @param {int} base ("x") + * @param {int} exponent ("y") + * @param {int} modulus ("z") + * @return {int} + * @author fenris + * @todo handle invalid cases (e.g. "z < 1") + * @todo implement iteratively + */ + function modpow(base, exponent, modulus) { + /* + The idea is the following: + + x^y + = x^((y div 2)·2 + (y mod 2)) + = x^((y div 2)·2) · x^(y mod 2) + = (x^(y div 2))^2 · x^(y mod 2) + + For computing (x^(y div 2)) the algorithm is used recursively. Building the square is done without any magic. + The second factor is either 1 or x, since (y mod 2) is either 0 or 1; in other words: multiplying x to the first + factor is only necessary if y is odd. + */ + if (exponent === 0) { + return 1; + } + else { + let a = modpow(base, exponent >> 1, modulus); + a = ((a * a) % modulus); + if ((exponent & 1) != 0) { + a = ((a * base) % modulus); + } + return a; + } + } + math.modpow = modpow; + /** + * @desc determines if two integers are coprime, i.e. that they don't have a common divisor greater than 1 + * @author fenris + * @todo write function "gcdx" and base on it + */ + function coprime(x, y) { + if (y === 0) { + return false; + } + else if (y === 1) { + return true; + } + else { + let z = mod(x, y); + return coprime(y, z); + } + } + math.coprime = coprime; + /** + * @desc extended euclidean algorithm for computing multiplicative inverse elements + * @param {int} modulus + * @param {int} element + * @author fenris + * @todo write function "gcdx" and base on it + * @todo handle more invalid cases + */ + function inv(modulus, element, positive = false) { + if (element === 0) { + throw (new Error("not invertable")); + } + else if (element === 1) { + return 1; + } + else { + let result = div(1 - (modulus * inv(element, mod(modulus, element), false)), element); + return (positive ? mod(result, modulus) : result); + } + } + math.inv = inv; + /** + * @author fenris + */ + function interpolate_linear(x, y, t = 0.5) { + return ((1 - t) * x + t * y); + } + math.interpolate_linear = interpolate_linear; + /** + * @desc kind of the inverse of linear interpolation; i.e. to find the coefficient "t" for given values x, y and + * their presumed interpolation v + * @author fenris + */ + function appoint_linear(x, y, v) { + return ((v - x) / (y - x)); + } + math.appoint_linear = appoint_linear; + /** + * continued fraction decomposition + */ + function cfd(x, n = (1 << 4)) { + let result = []; + let m = 0; + let y = x; + while (true) { + if (m >= n) { + break; + } + else { + const a = Math.floor(y); + result.push(a); + if (y === a) { + break; + } + else { + y = (1 / (y - a)); + m += 1; + } + } + } + return result; + } + math.cfd = cfd; + })(math = lib_plankton.math || (lib_plankton.math = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:math«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:math« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:math« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:math«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var math; + (function (math) { + /** + * @author fenris + */ + class class_relation { + /** + * @author fenris + */ + check(value, reference) { + return this.predicate(value, reference); + } + /** + * @author fenris + */ + /*protected*/ constructor(id, { "symbol": symbol = null, "name": name = null, "predicate": predicate, }) { + this.id = id; + this.symbol = symbol; + this.name = name; + this.predicate = predicate; + } + /** + * @author fenris + */ + id_get() { + return this.id; + } + /** + * @author fenris + */ + symbol_get() { + return this.symbol; + } + /** + * @author fenris + */ + name_get() { + return this.name; + } + /** + * @desc [accessor] [implementation] + * @author fenris + */ + _show() { + return `[${this.symbol}]`; + } + /** + * @desc [accessor] [implementation] + * @author fenris + */ + _hash() { + return this.id; + } + /** + * @desc [accessor] [implementation] + * @author fenris + */ + _collate(relation) { + return (this.id == relation.id); + } + /** + * @author fenris + */ + toString() { + return this._show(); + } + /** + * @author fenris + */ + static pool() { + return { + "eq": { + "symbol": "=", + "name": "gleich", + "predicate": (value, reference) => (value == reference), + }, + "ne": { + "symbol": "≠", + "name": "ungleich", + "predicate": (value, reference) => (value != reference), + }, + "gt": { + "symbol": ">", + "name": "größer", + "predicate": (value, reference) => (value > reference), + }, + "ge": { + "symbol": "≥", + "name": "größer oder gleich", + "predicate": (value, reference) => (value >= reference), + }, + "lt": { + "symbol": "<", + "name": "kleiner", + "predicate": (value, reference) => (value < reference), + }, + "le": { + "symbol": "≤", + "name": "kleiner oder gleich", + "predicate": (value, reference) => (value <= reference), + }, + }; + } + /** + * @author fenris + */ + static get(id) { + let pool = this.pool(); + if (id in pool) { + return (new class_relation(id, pool[id])); + } + else { + throw (new Error(`no such relation`)); + } + } + /** + * @author fenris + */ + static available() { + return Object.keys(this.pool()); + } + } + math.class_relation = class_relation; + /** + * @author fenris + */ + class class_filtrationitem { + /** + * @author fenris + */ + constructor({ "extract": extract, "relation": relation, "reference": reference, }) { + this.extract = extract; + this.relation = relation; + this.reference = reference; + } + /** + * @author fenris + */ + check(dataset) { + let value = this.extract(dataset); + let result = this.relation.check(value, this.reference); + return result; + } + /** + * @desc [implementation] + * @author fenris + */ + _show() { + return `(${this.relation.symbol_get()} ${instance_show(this.reference)})`; + } + /** + * @author fenris + */ + toString() { + return this._show(); + } + } + math.class_filtrationitem = class_filtrationitem; + /** + * @desc disjunctive normal form + * @author fenris + */ + class class_filtration { + /** + * @author fenris + */ + constructor(clauses) { + this.clauses = clauses; + } + /** + * @author fenris + */ + check(dataset) { + return (this.clauses.some(clause => clause.every(literal => literal.check(dataset)))); + } + /** + * @author fenris + */ + use(datasets) { + return datasets.filter(dataset => this.check(dataset)); + } + /** + * @desc [implementation] + * @author fenris + */ + _show() { + return ("{" + this.clauses.map(clause => ("[" + clause.map(instance_show).join(",") + "]")).join(",") + "}"); + } + /** + * @author fenris + */ + toString() { + return this._show(); + } + } + math.class_filtration = class_filtration; + /** + * @author fenris + * @deprecated + */ + function comparator_to_relation(comparator) { + console.warn("deprecated!"); + return ((x, y) => (comparator(x, y) <= 0)); + } + math.comparator_to_relation = comparator_to_relation; + /** + * @author fenris + * @deprecated + */ + function relation_to_comparator(relation) { + console.warn("deprecated!"); + return ((x, y) => (relation(x, y) ? (relation(y, x) ? 0 : -1) : 1)); + } + math.relation_to_comparator = relation_to_comparator; + })(math = lib_plankton.math || (lib_plankton.math = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:math«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:math« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:math« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:math«. If not, see . + */ +var lib_calculus; +(function (lib_calculus) { + /** + * @class Calculus + * @desc Ensure precision of mathematical operations + */ + class Calculus { + /** + * @constructor + * @þaram {number} norm + */ + constructor(norm = 100000) { + this.NORM = norm; + } + /** + * normalize + * @param {number} value + * @return {number} + */ + normalize(value) { + return (Math.floor(value * this.NORM)); + } + /** + * denormalize + * @param {number} value + * @return {number} + */ + denormalize(value) { + return (Math.floor(value) / this.NORM); + } + } + lib_calculus.Calculus = Calculus; +})(lib_calculus || (lib_calculus = {})); +/* +This file is part of »bacterio-plankton:math«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:math« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:math« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:math«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var math; + (function (math) { + /** + * {x ∈ C | 0 = x³ + px + q} + * + * @author fenris + */ + function cardano_reduced(p, q) { + // (p/3)^3 + (q/2)^2 + const determinant = (lib_plankton.complex.add(lib_plankton.complex.exp(lib_plankton.complex.scl(p, 1 / 3.0), 3), lib_plankton.complex.exp(lib_plankton.complex.scl(q, 1 / 2.0), 2))); + const [u, v] = (lib_plankton.complex.normroots(2, determinant) + .map(w => lib_plankton.complex.sub(w, lib_plankton.complex.scl(q, 1 / 2.0))) + .map(z => lib_plankton.complex.normroots(3, z))); + return [ + /* + lib_plankton.complex.add(u[0], v[0]), + lib_plankton.complex.add(u[1], v[2]), + lib_plankton.complex.add(u[2], v[1]), + */ + // (p = -3uv) → (v = p/(-3u)) → (v = (p/(-3))/u) + lib_plankton.complex.add(u[0], lib_plankton.complex.div(lib_plankton.complex.scl(p, -1 / 3.0), u[0])), + lib_plankton.complex.add(u[1], lib_plankton.complex.div(lib_plankton.complex.scl(p, -1 / 3.0), u[1])), + lib_plankton.complex.add(u[2], lib_plankton.complex.div(lib_plankton.complex.scl(p, -1 / 3.0), u[2])), + ]; + } + /** + * {x ∈ C | 0 = x³ + ex² + fx + g} + * + * @author fenris + */ + function cardano_normalized(e, f, g) { + // p := (-1/3)·e² + f + const p = (lib_plankton.complex.add(lib_plankton.complex.scl(lib_plankton.complex.exp(e, 2), -1 / 3.0), f)); + // q := (2/27)·e³ + (-1/3)·e·f + g + const q = (lib_plankton.complex.add(lib_plankton.complex.add(lib_plankton.complex.scl(lib_plankton.complex.exp(e, 3), +2 / 27.0), lib_plankton.complex.scl(lib_plankton.complex.mul(e, f), -1 / 3.0)), g)); + return (cardano_reduced(p, q) + .map(y => lib_plankton.complex.sub(y, lib_plankton.complex.scl(e, 1 / 3.0)))); + } + /** + * {x ∈ C | 0 = ax³ + bx² + cx + d} + * + * @author fenris + */ + function cubic_solve(a, b, c, d) { + if (lib_plankton.complex.equ(a, lib_plankton.complex.nul())) { + const message = "Leitkoeffizient ist Null; dadurch sollte sich das Problem eigentlich vereinfachen"; + throw (new Error(message)); + } + else { + // e = b/a + const e = lib_plankton.complex.div(b, a); + // f = c/a + const f = lib_plankton.complex.div(c, a); + // g = d/a + const g = lib_plankton.complex.div(d, a); + return cardano_normalized(e, f, g); + } + } + math.cubic_solve = cubic_solve; + /** + * {x ∈ C | 0 = ax³ + bx² + cx + d} + * + * @author fenris + */ + function cubic_solve_real(a, b, c, d) { + return cubic_solve(lib_plankton.complex.make(a, 0), lib_plankton.complex.make(b, 0), lib_plankton.complex.make(c, 0), lib_plankton.complex.make(d, 0)); + } + math.cubic_solve_real = cubic_solve_real; + /** + * gets the coefficients of a polynom by the roots + * + * @author fenris + */ + /*export*/ function cubic_construct(solutions) { + const [x, y, z] = solutions.map(lib_plankton.complex.neg); + const mix = function (values) { + return (values + .map(group => (group + .reduce(lib_plankton.complex.mul, lib_plankton.complex.one()))) + .reduce(lib_plankton.complex.add, lib_plankton.complex.nul())); + }; + return { + "a": mix([[]]), + "b": mix([[x], [y], [z]]), + "c": mix([[x, y], [x, z], [y, z]]), + "d": mix([[x, y, z]]), + }; + } + })(math = lib_plankton.math || (lib_plankton.math = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:color«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:color« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:color« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:color«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var color; + (function (color_1) { + /** + * @author fenris + */ + function make_hsv({ "hue": hue = 0.0, "saturation": saturation = 0.5, "value": value = 0.5 }) { + const h = lib_plankton.math.clamp(0, 1, hue); + const s = lib_plankton.math.clamp(0, 1, saturation); + const v = lib_plankton.math.clamp(0, 1, value); + const sector = (Math.floor(h * 6) % 6); + const phase = ((h * 6) - sector); + const p = (v * (1 - s)); + const q = (v * (1 - (s * phase))); + const t = (v * (1 - (s * (1 - phase)))); + return make_rgb([ + { "red": v, "green": t, "blue": p }, + { "red": q, "green": v, "blue": p }, + { "red": p, "green": v, "blue": t }, + { "red": p, "green": q, "blue": v }, + { "red": t, "green": p, "blue": v }, + { "red": v, "green": p, "blue": q }, + ][sector]); + } + color_1.make_hsv = make_hsv; + /** + * @author fenris + */ + function make_hsl(model_hsl) { + const { "hue": h, "saturation": s, "lightness": l } = model_hsl; + const h_ = h; + const v = (l + (s * (1 - Math.abs((2 * l) - 1)) / 2)); + const s_ = (2 * (1 - (l / v))); + return make_hsv({ + "hue": h_, + "saturation": s_, + "value": v, + }); + } + color_1.make_hsl = make_hsl; + /** + * @author fenris + */ + function make_rgb(model_rgb) { + return { + "model": { + "red": lib_plankton.math.clamp(0, 1, model_rgb.red), + "green": lib_plankton.math.clamp(0, 1, model_rgb.green), + "blue": lib_plankton.math.clamp(0, 1, model_rgb.blue), + } + }; + } + color_1.make_rgb = make_rgb; + /** + * @author fenris + */ + function to_hsv(color) { + const { "red": r, "green": g, "blue": b } = color.model; + const p = Math.min(r, g, b); + const q = Math.max(r, g, b); + const c = (q - p); + let h; + { + if (p === q) { + h = 0; + } + else if (q === r) { + h = ((0 / 3) + ((g - b) / (c * 6))); + } + else if (q === g) { + h = ((1 / 3) + ((b - r) / (c * 6))); + } + else if (q === b) { + h = ((2 / 3) + ((r - g) / (c * 6))); + } + else { + throw (new Error("impossible?")); + } + } + const s = ((q === 0) ? 0 : c); + const v = q; + return { + "hue": h, + "saturation": s, + "value": v, + }; + } + color_1.to_hsv = to_hsv; + /** + * @author fenris + */ + function to_hsl(color) { + const { "hue": h, "saturation": s, "value": v } = to_hsv(color); + const h_ = h; + const l = (1 / 2 * v * (2 - s)); + const s_ = ((v * s) / (1 - Math.abs((2 * l) - 1))); + return { + "hue": h, + "saturation": s, + "lightness": l, + }; + } + color_1.to_hsl = to_hsl; + /** + * @author fenris + */ + function to_rgb(color) { + return color.model; + } + color_1.to_rgb = to_rgb; + /** + * @author fenris + */ + function to_cmyk(color) { + throw (new Error("not implemented")); + } + color_1.to_cmyk = to_cmyk; + /** + * @author fenris + */ + function add(color1, color2) { + const rgb1 = to_rgb(color1); + const rgb2 = to_rgb(color2); + return make_rgb({ + "red": (rgb1.red + rgb2.red), + "green": (rgb1.green + rgb2.green), + "blue": (rgb1.blue + rgb2.blue), + }); + } + color_1.add = add; + /** + * @author fenris + */ + function multiply(color1, color2) { + const rgb1 = to_rgb(color1); + const rgb2 = to_rgb(color2); + return make_rgb({ + "red": (rgb1.red * rgb2.red), + "green": (rgb1.green * rgb2.green), + "blue": (rgb1.blue * rgb2.blue), + }); + } + color_1.multiply = multiply; + /** + * @author fenris + * @todo blend through other model? + */ + function blend(color1, color2, strength = 0.5) { + let rgb1 = to_rgb(color1); + let rgb2 = to_rgb(color2); + let t = strength; + return (make_rgb({ + "red": lib_plankton.math.interpolate_linear(rgb1.red, rgb2.red, t), + "green": lib_plankton.math.interpolate_linear(rgb1.green, rgb2.green, t), + "blue": lib_plankton.math.interpolate_linear(rgb1.blue, rgb2.blue, t) + })); + } + color_1.blend = blend; + /** + * @author fenris + */ + function mix(color1, color2, strength1 = 1, strength2 = 1) { + return (blend(color1, color2, strength1 / (strength1 + strength2))); + } + color_1.mix = mix; + /** + * @author fenris + */ + function output_rgb(color) { + const format = (value => Math.round(value * 255).toFixed(0)); + const rgb = to_rgb(color); + return ("rgb" + "(" + ["red", "green", "blue"].map(key => rgb[key]).map(format).join(",") + ")"); + } + color_1.output_rgb = output_rgb; + /** + * @author fenris + */ + function output_hex(color) { + const rgb = to_rgb(color); + const format = function (value) { + const value_ = Math.round(value * 255); + // let str : string = lib_plankton.string.pad(value_.toString(16), 2, "0", true); + let str = value_.toString(16); + while (str.length < 2) + str = ("0" + str); + return str; + }; + return ("#" + ["red", "green", "blue"].map(key => rgb[key]).map(format).join("") + ""); + } + color_1.output_hex = output_hex; + /** + * @author fenris + */ + function output_dot(color) { + let hsv = to_hsv(color); + let format = function (value) { + let str = value.toFixed(8); + return str; + }; + return ("" + ["hue", "saturation", "value"].map(key => hsv[key]).map(format).join("+") + ""); + } + color_1.output_dot = output_dot; + /** + * @author fenris + */ + function give_generic({ "n": n, "offset": offset = 0, "saturation": saturation = undefined, "value": value = undefined, }) { + let hue = (((lib_plankton.math.phi * n) + offset) % 1); + return make_hsv({ "hue": hue, "saturation": saturation, "value": value }); + } + color_1.give_generic = give_generic; + /** + * @author fenris + */ + function give_gray(value = 0.5) { + return make_hsv({ "hue": 0, "saturation": 0, "value": value }); + } + color_1.give_gray = give_gray; + /** + * @author fenris + */ + function give_black() { + return give_gray(0.0); + } + color_1.give_black = give_black; + /** + * @author fenris + */ + function give_white() { + return give_gray(1.0); + } + color_1.give_white = give_white; + /** + * @author fenris + */ + function give_red({ "saturation": saturation = undefined, "value": value = undefined, } = {}) { + return make_hsv({ "hue": 0 / 6, "saturation": saturation, "value": value }); + } + color_1.give_red = give_red; + /** + * @author fenris + */ + function give_green({ "saturation": saturation = undefined, "value": value = undefined, } = {}) { + return make_hsv({ "hue": 2 / 6, "saturation": saturation, "value": value }); + } + color_1.give_green = give_green; + /** + * @author fenris + */ + function give_blue({ "saturation": saturation = undefined, "value": value = undefined, } = {}) { + return make_hsv({ "hue": 4 / 6, "saturation": saturation, "value": value }); + } + color_1.give_blue = give_blue; + /** + * @author fenris + */ + function give_yellow({ "saturation": saturation = undefined, "value": value = undefined, } = {}) { + return make_hsv({ "hue": 1 / 6, "saturation": saturation, "value": value }); + } + color_1.give_yellow = give_yellow; + /** + * @author fenris + */ + function give_cyan({ "saturation": saturation = undefined, "value": value = undefined, } = {}) { + return make_hsv({ "hue": 3 / 6, "saturation": saturation, "value": value }); + } + color_1.give_cyan = give_cyan; + /** + * @author fenris + */ + function give_magenta({ "saturation": saturation = undefined, "value": value = undefined, } = {}) { + return make_hsv({ "hue": 5 / 6, "saturation": saturation, "value": value }); + } + color_1.give_magenta = give_magenta; + })(color = lib_plankton.color || (lib_plankton.color = {})); +})(lib_plankton || (lib_plankton = {})); +/* +This file is part of »bacterio-plankton:color«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:color« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:color« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:color«. If not, see . + */ +var lib_plankton; +(function (lib_plankton) { + var color; + (function (color_2) { + /** + * @author fenris + */ + class class_color { + /** + * @author fenris + */ + constructor(subject) { + this.subject = subject; + } + /** + * @author fenris + */ + static _cram(subject) { + return (new class_color(subject)); + } + /** + * @author fenris + */ + static _tear(instance) { + return (instance.subject); + } + /** + * @author fenris + */ + static make_hsv({ "hue": hue = undefined, "saturation": saturation = undefined, "value": value = undefined }) { + return (class_color._cram(color_2.make_hsv({ + "hue": hue, + "saturation": saturation, + "value": value + }))); + } + /** + * @author fenris + */ + blend(color, strength = 0.5) { + return (class_color._cram(color_2.blend(class_color._tear(this), class_color._tear(color), strength))); + } + /** + * @author fenris + */ + output_rgb() { + return (color_2.output_rgb(class_color._tear(this))); + } + /** + * @author fenris + */ + output_hex() { + return (color_2.output_hex(class_color._tear(this))); + } + /** + * @author fenris + */ + output_dot() { + return (color_2.output_dot(class_color._tear(this))); + } + /** + * @author fenris + */ + static give_generic({ "n": n, "offset": offset = undefined, "saturation": saturation = undefined, "value": value = undefined, }) { + return (class_color._cram(color_2.give_generic({ + "n": n, + "offset": offset, + "saturation": saturation, + "value": value, + }))); + } + static generic(x) { return class_color.give_generic(x); } + ; + /** + * @author fenris + */ + static give_gray(value = 0.5) { + return (class_color._cram(color_2.give_gray(value))); + } + /** + * @author fenris + */ + static give_black() { + return (class_color._cram(color_2.give_black())); + } + /** + * @author fenris + */ + static give_white() { + return (class_color._cram(color_2.give_white())); + } + /** + * @author fenris + */ + static give_red({ "saturation": saturation = undefined, "value": value = undefined, } = {}) { + return (class_color._cram(color_2.give_red({ + "saturation": saturation, + "value": value, + }))); + } + /** + * @author fenris + */ + static give_green({ "saturation": saturation = undefined, "value": value = undefined, } = {}) { + return (class_color._cram(color_2.give_green({ + "saturation": saturation, + "value": value, + }))); + } + /** + * @author fenris + */ + static give_blue({ "saturation": saturation = undefined, "value": value = undefined, } = {}) { + return (class_color._cram(color_2.give_blue({ + "saturation": saturation, + "value": value, + }))); + } + /** + * @author fenris + */ + static give_yellow({ "saturation": saturation = undefined, "value": value = undefined, } = {}) { + return (class_color._cram(color_2.give_yellow({ + "saturation": saturation, + "value": value, + }))); + } + /** + * @author fenris + */ + static give_cyan({ "saturation": saturation = undefined, "value": value = undefined, } = {}) { + return (class_color._cram(color_2.give_cyan({ + "saturation": saturation, + "value": value, + }))); + } + /** + * @author fenris + */ + static give_magenta({ "saturation": saturation = undefined, "value": value = undefined, } = {}) { + return (class_color._cram(color_2.give_magenta({ + "saturation": saturation, + "value": value, + }))); + } + } + color_2.class_color = class_color; + })(color = lib_plankton.color || (lib_plankton.color = {})); +})(lib_plankton || (lib_plankton = {})); +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +/* +This file is part of »bacterio-plankton:xml«. + +Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' + + +»bacterio-plankton:xml« is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +»bacterio-plankton:xml« is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with »bacterio-plankton:xml«. If not, see . + */ +/** + * @author fenris + */ +var lib_plankton; +(function (lib_plankton) { + var xml; + (function (xml) { + /** + * @author fenris + */ + function string_repeat(symbol, count) { + return ((count <= 0) ? "" : (string_repeat(symbol, count - 1) + symbol)); + } + /** + * @author fenris + */ + var class_node = /** @class */ (function () { + function class_node() { + } + return class_node; + }()); + xml.class_node = class_node; + /** + * @author fenris + */ + var class_node_text = /** @class */ (function (_super) { + __extends(class_node_text, _super); + /** + * @author fenris + */ + function class_node_text(content) { + var _this = _super.call(this) || this; + _this.content = content; + return _this; + } + /** + * @author fenris + */ + class_node_text.prototype.compile = function (depth) { + if (depth === void 0) { depth = 0; } + return (string_repeat("\t", depth) + this.content + "\n"); + }; + return class_node_text; + }(class_node)); + xml.class_node_text = class_node_text; + /** + * @author fenris + */ + var class_node_comment = /** @class */ (function (_super) { + __extends(class_node_comment, _super); + /** + * @author fenris + */ + function class_node_comment(content) { + var _this = _super.call(this) || this; + _this.content = content; + return _this; + } + /** + * @author fenris + */ + class_node_comment.prototype.compile = function (depth) { + if (depth === void 0) { depth = 0; } + return (string_repeat("\t", depth) + "" + "\n"); + }; + return class_node_comment; + }(class_node)); + xml.class_node_comment = class_node_comment; + /** + * @author fenris + */ + var class_node_complex = /** @class */ (function (_super) { + __extends(class_node_complex, _super); + /** + * @author fenris + */ + function class_node_complex(name, attributes, children) { + if (attributes === void 0) { attributes = {}; } + if (children === void 0) { children = []; } + var _this = _super.call(this) || this; + _this.name = name; + _this.attributes = attributes; + _this.children = children; + return _this; + } + /** + * @author fenris + */ + class_node_complex.prototype.compile = function (depth) { + var _this = this; + if (depth === void 0) { depth = 0; } + var output = ""; + var attributes = (Object.keys(this.attributes) + .filter(function (key) { return (_this.attributes[key] !== null); }) + .map(function (key) { return (" " + key + "=" + ("\"" + _this.attributes[key] + "\"")); }) + .join("")); + output += (string_repeat("\t", depth) + "<" + this.name + attributes + ">" + "\n"); + this.children.forEach(function (child) { return (output += child.compile(depth + 1)); }); + output += (string_repeat("\t", depth) + "" + "\n"); + return output; + }; + return class_node_complex; + }(class_node)); + xml.class_node_complex = class_node_complex; + })(xml = lib_plankton.xml || (lib_plankton.xml = {})); +})(lib_plankton || (lib_plankton = {})); diff --git a/tools/update-plankton b/tools/update-plankton index 8c997c7..b8878f3 100755 --- a/tools/update-plankton +++ b/tools/update-plankton @@ -11,6 +11,8 @@ modules="${modules} file" modules="${modules} json" modules="${modules} args" modules="${modules} string" +modules="${modules} color" +modules="${modules} xml" ## exec