jsxgraph 1.3.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/distrib/README.md +2 -2
- package/distrib/geogebra.min.js +3 -3
- package/distrib/geonext.min.js +3 -3
- package/distrib/index.d.ts +651 -448
- package/distrib/intergeo.min.js +3 -3
- package/distrib/jsxgraph.css +4 -13
- package/distrib/jsxgraphcore.js +9 -25
- package/distrib/jsxgraphsrc.js +28203 -25234
- package/distrib/sketch.min.js +3 -3
- package/package.json +11 -22
- package/src/base/board.js +674 -469
- package/src/base/chart.js +1 -1
- package/src/base/circle.js +23 -1
- package/src/base/composition.js +1 -1
- package/src/base/constants.js +32 -11
- package/src/base/coords.js +4 -4
- package/src/base/coordselement.js +51 -24
- package/src/base/curve.js +308 -117
- package/src/base/element.js +79 -50
- package/src/base/foreignobject.js +463 -0
- package/src/base/group.js +2 -2
- package/src/base/image.js +12 -15
- package/src/base/line.js +108 -21
- package/src/base/point.js +24 -28
- package/src/base/polygon.js +75 -18
- package/src/base/text.js +116 -63
- package/src/base/ticks.js +29 -11
- package/src/base/transformation.js +1 -1
- package/src/base/turtle.js +1 -1
- package/src/element/arc.js +1 -1
- package/src/element/button.js +29 -2
- package/src/element/checkbox.js +31 -1
- package/src/element/comb.js +5 -2
- package/src/element/composition.js +127 -19
- package/src/element/conic.js +46 -5
- package/src/element/input.js +32 -1
- package/src/element/locus.js +2 -2
- package/src/element/measure.js +9 -4
- package/src/element/sector.js +46 -12
- package/src/element/slider.js +17 -12
- package/src/element/slopetriangle.js +1 -1
- package/src/jsxgraph.js +28 -9
- package/src/jxg.js +4 -3
- package/src/loadjsxgraph.js +3 -2
- package/src/math/bst.js +1 -1
- package/src/math/clip.js +550 -345
- package/src/math/complex.js +1 -1
- package/src/math/extrapolate.js +1 -1
- package/src/math/geometry.js +155 -126
- package/src/math/ia.js +290 -21
- package/src/math/math.js +30 -1
- package/src/math/metapost.js +1 -1
- package/src/math/nlp.js +25 -5
- package/src/math/numerics.js +183 -4
- package/src/math/plot.js +4 -4
- package/src/math/poly.js +1 -1
- package/src/math/probfuncs.js +2 -1
- package/src/math/qdt.js +68 -62
- package/src/math/statistics.js +58 -7
- package/src/math/symbolic.js +1 -1
- package/src/options.js +377 -114
- package/src/parser/ca.js +1297 -1291
- package/src/parser/datasource.js +1 -1
- package/src/parser/geonext.js +6 -6
- package/src/parser/jessiecode.js +275 -79
- package/src/parser/jessiescript.js +1 -1
- package/src/reader/cinderella.js +1 -1
- package/src/reader/file.js +1 -1
- package/src/reader/geogebra.js +1 -1
- package/src/reader/geonext.js +1 -1
- package/src/reader/graph.js +1 -1
- package/src/reader/intergeo.js +1 -1
- package/src/reader/sketch.js +21 -13
- package/src/renderer/abstract.js +21 -6
- package/src/renderer/canvas.js +22 -15
- package/src/renderer/no.js +11 -4
- package/src/renderer/svg.js +76 -53
- package/src/renderer/vml.js +36 -32
- package/src/server/server.js +1 -1
- package/src/utils/base64.js +2 -2
- package/src/utils/color.js +148 -3
- package/src/utils/dump.js +21 -15
- package/src/utils/env.js +63 -104
- package/src/utils/event.js +1 -1
- package/src/utils/expect.js +1 -1
- package/src/utils/type.js +30 -19
- package/src/utils/xml.js +1 -1
- package/src/utils/zip.js +1 -1
- package/CHANGELOG.md +0 -1281
package/src/math/nlp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2008-
|
|
2
|
+
Copyright 2008-2022
|
|
3
3
|
Matthias Ehmann,
|
|
4
4
|
Carsten Miller,
|
|
5
5
|
Reinhard Oldenburg,
|
|
@@ -86,6 +86,12 @@ define(['jxg'], function (JXG) {
|
|
|
86
86
|
|
|
87
87
|
"use strict";
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* The JXG.Math.Nlp namespace holds numerical algorithms for non-linear optimization.
|
|
91
|
+
* @name JXG.Math.Nlp
|
|
92
|
+
* @namespace
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
89
95
|
JXG.Math.Nlp = {
|
|
90
96
|
|
|
91
97
|
arr: function(n) {
|
|
@@ -124,6 +130,7 @@ define(['jxg'], function (JXG) {
|
|
|
124
130
|
/**
|
|
125
131
|
* Minimizes the objective function F with respect to a set of inequality constraints CON,
|
|
126
132
|
* and returns the optimal variable array. F and CON may be non-linear, and should preferably be smooth.
|
|
133
|
+
* Calls {@link JXG.Math.Nlp#cobylb}.
|
|
127
134
|
*
|
|
128
135
|
* @param calcfc Interface implementation for calculating objective function and constraints.
|
|
129
136
|
* @param n Number of variables.
|
|
@@ -135,10 +142,10 @@ define(['jxg'], function (JXG) {
|
|
|
135
142
|
* @param iprint Print level, 0 <= iprint <= 3, where 0 provides no output and
|
|
136
143
|
* 3 provides full output to the console.
|
|
137
144
|
* @param maxfun Maximum number of function evaluations before terminating.
|
|
138
|
-
* @
|
|
145
|
+
* @returns {Number} Exit status of the COBYLA2 optimization.
|
|
139
146
|
*/
|
|
140
|
-
// CobylaExitStatus FindMinimum(final Calcfc calcfc, int n, int m, double[] x, double rhobeg, double rhoend, int iprint, int maxfun)
|
|
141
147
|
FindMinimum: function(calcfc, n, m, x, rhobeg, rhoend, iprint, maxfun) {
|
|
148
|
+
// CobylaExitStatus FindMinimum(final Calcfc calcfc, int n, int m, double[] x, double rhobeg, double rhoend, int iprint, int maxfun)
|
|
142
149
|
// This subroutine minimizes an objective function F(X) subject to M
|
|
143
150
|
// inequality constraints on X, where X is a vector of variables that has
|
|
144
151
|
// N components. The algorithm employs linear approximations to the
|
|
@@ -220,8 +227,21 @@ define(['jxg'], function (JXG) {
|
|
|
220
227
|
|
|
221
228
|
// private static CobylaExitStatus cobylb(Calcfc calcfc, int n, int m, int mpp, double[] x,
|
|
222
229
|
// double rhobeg, double rhoend, int iprint, int maxfun)
|
|
230
|
+
/**
|
|
231
|
+
* JavaScript implementation of the non-linear optimization method COBYLA.
|
|
232
|
+
* @param {Function} calcfc
|
|
233
|
+
* @param {Number} n
|
|
234
|
+
* @param {Number} m
|
|
235
|
+
* @param {Number} mpp
|
|
236
|
+
* @param {Number} x
|
|
237
|
+
* @param {Number} rhobeg
|
|
238
|
+
* @param {Number} rhoend
|
|
239
|
+
* @param {Number} iprint
|
|
240
|
+
* @param {Number} maxfun
|
|
241
|
+
* @returns {Number} Exit status of the COBYLA2 optimization
|
|
242
|
+
*/
|
|
223
243
|
cobylb: function (calcfc, n, m, mpp, x, rhobeg, rhoend, iprint, maxfun) {
|
|
224
|
-
|
|
244
|
+
// calcf ist funktion die aufgerufen wird wie calcfc(n, m, ix, ocon)
|
|
225
245
|
// N.B. Arguments CON, SIM, SIMI, DATMAT, A, VSIG, VETA, SIGBAR, DX, W & IACT
|
|
226
246
|
// have been removed.
|
|
227
247
|
|
|
@@ -294,7 +314,7 @@ define(['jxg'], function (JXG) {
|
|
|
294
314
|
// Make the next call of the user-supplied subroutine CALCFC. These
|
|
295
315
|
// instructions are also used for calling CALCFC during the iterations of
|
|
296
316
|
// the algorithm.
|
|
297
|
-
|
|
317
|
+
//alert("Iteration "+nfvals+" x="+x);
|
|
298
318
|
L_40:
|
|
299
319
|
do {
|
|
300
320
|
if (nfvals >= maxfun && nfvals > 0) {
|
package/src/math/numerics.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2008-
|
|
2
|
+
Copyright 2008-2022
|
|
3
3
|
Matthias Ehmann,
|
|
4
4
|
Michael Gerhaeuser,
|
|
5
5
|
Carsten Miller,
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
|
|
32
32
|
/*global JXG: true, define: true*/
|
|
33
33
|
/*jslint nomen: true, plusplus: true*/
|
|
34
|
+
/*eslint no-loss-of-precision: off */
|
|
34
35
|
|
|
35
36
|
/* depends:
|
|
36
37
|
utils/type
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
* algorithms for solving linear equations etc.
|
|
43
44
|
*/
|
|
44
45
|
|
|
45
|
-
define(['jxg', 'utils/type', 'math/math'], function (JXG, Type, Mat) {
|
|
46
|
+
define(['jxg', 'utils/type', 'utils/env', 'math/math'], function (JXG, Type, Env, Mat) {
|
|
46
47
|
|
|
47
48
|
"use strict";
|
|
48
49
|
|
|
@@ -1767,6 +1768,8 @@ define(['jxg', 'utils/type', 'math/math'], function (JXG, Type, Mat) {
|
|
|
1767
1768
|
* Returns the Lagrange polynomials, see
|
|
1768
1769
|
* Jean-Paul Berrut, Lloyd N. Trefethen: Barycentric Lagrange Interpolation,
|
|
1769
1770
|
* SIAM Review, Vol 46, No 3, (2004) 501-517.
|
|
1771
|
+
* <p>
|
|
1772
|
+
* It possesses the method getTerm() which returns the string containing the function term of the polynomial.
|
|
1770
1773
|
* @param {Array} p Array of JXG.Points
|
|
1771
1774
|
* @returns {function} A function of one parameter which returns the value of the polynomial, whose graph runs through the given points.
|
|
1772
1775
|
* @memberof JXG.Math.Numerics
|
|
@@ -1797,9 +1800,38 @@ define(['jxg', 'utils/type', 'math/math'], function (JXG, Type, Mat) {
|
|
|
1797
1800
|
*
|
|
1798
1801
|
* </script><pre>
|
|
1799
1802
|
*
|
|
1803
|
+
* @example
|
|
1804
|
+
* var points = [];
|
|
1805
|
+
* points[0] = board.create('point', [-1,2], {size:4});
|
|
1806
|
+
* points[1] = board.create('point', [0, 0], {size:4});
|
|
1807
|
+
* points[2] = board.create('point', [2, 1], {size:4});
|
|
1808
|
+
*
|
|
1809
|
+
* var f = JXG.Math.Numerics.lagrangePolynomial(points);
|
|
1810
|
+
* var graph = board.create('functiongraph', [f,-10, 10], {strokeWidth:3});
|
|
1811
|
+
* var txt = board.create('text', [-3, -4, () => f.getTerm(2, 't', ' * ')], {fontSize: 16});
|
|
1812
|
+
*
|
|
1813
|
+
* </pre><div id="JXG73fdaf12-e257-4374-b488-ae063e4eecbb" class="jxgbox" style="width: 300px; height: 300px;"></div>
|
|
1814
|
+
* <script type="text/javascript">
|
|
1815
|
+
* (function() {
|
|
1816
|
+
* var board = JXG.JSXGraph.initBoard('JXG73fdaf12-e257-4374-b488-ae063e4eecbb',
|
|
1817
|
+
* {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
|
|
1818
|
+
* var points = [];
|
|
1819
|
+
* points[0] = board.create('point', [-1,2], {size:4});
|
|
1820
|
+
* points[1] = board.create('point', [0, 0], {size:4});
|
|
1821
|
+
* points[2] = board.create('point', [2, 1], {size:4});
|
|
1822
|
+
*
|
|
1823
|
+
* var f = JXG.Math.Numerics.lagrangePolynomial(points);
|
|
1824
|
+
* var graph = board.create('functiongraph', [f,-10, 10], {strokeWidth:3});
|
|
1825
|
+
* var txt = board.create('text', [-3, -4, () => f.getTerm(2, 't', ' * ')], {fontSize: 16});
|
|
1826
|
+
*
|
|
1827
|
+
* })();
|
|
1828
|
+
*
|
|
1829
|
+
* </script><pre>
|
|
1830
|
+
*
|
|
1800
1831
|
*/
|
|
1801
1832
|
lagrangePolynomial: function (p) {
|
|
1802
1833
|
var w = [],
|
|
1834
|
+
that = this,
|
|
1803
1835
|
/** @ignore */
|
|
1804
1836
|
fct = function (x, suspendedUpdate) {
|
|
1805
1837
|
var i, // j,
|
|
@@ -1843,12 +1875,159 @@ define(['jxg', 'utils/type', 'math/math'], function (JXG, Type, Mat) {
|
|
|
1843
1875
|
return num / denom;
|
|
1844
1876
|
};
|
|
1845
1877
|
|
|
1846
|
-
|
|
1847
|
-
|
|
1878
|
+
/**
|
|
1879
|
+
* Get the term of the Lagrange polynomial as string.
|
|
1880
|
+
* Calls {@link JXG.Math.Numerics#lagrangePolynomialTerm}.
|
|
1881
|
+
*
|
|
1882
|
+
* @name JXG.Math.Numerics#lagrangePolynomial.getTerm
|
|
1883
|
+
* @param {Number} digits Number of digits of the coefficients
|
|
1884
|
+
* @param {String} param Variable name
|
|
1885
|
+
* @param {String} dot Dot symbol
|
|
1886
|
+
* @returns {String} containing the term of Lagrange polynomial as string.
|
|
1887
|
+
* @see JXG.Math.Numerics#lagrangePolynomialTerm
|
|
1888
|
+
* @example
|
|
1889
|
+
* var points = [];
|
|
1890
|
+
* points[0] = board.create('point', [-1,2], {size:4});
|
|
1891
|
+
* points[1] = board.create('point', [0, 0], {size:4});
|
|
1892
|
+
* points[2] = board.create('point', [2, 1], {size:4});
|
|
1893
|
+
*
|
|
1894
|
+
* var f = JXG.Math.Numerics.lagrangePolynomial(points);
|
|
1895
|
+
* var graph = board.create('functiongraph', [f,-10, 10], {strokeWidth:3});
|
|
1896
|
+
* var txt = board.create('text', [-3, -4, () => f.getTerm(2, 't', ' * ')], {fontSize: 16});
|
|
1897
|
+
*
|
|
1898
|
+
* </pre><div id="JXG73fdaf12-e257-4374-b488-ae063e4eeccf" class="jxgbox" style="width: 300px; height: 300px;"></div>
|
|
1899
|
+
* <script type="text/javascript">
|
|
1900
|
+
* (function() {
|
|
1901
|
+
* var board = JXG.JSXGraph.initBoard('JXG73fdaf12-e257-4374-b488-ae063e4eeccf',
|
|
1902
|
+
* {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
|
|
1903
|
+
* var points = [];
|
|
1904
|
+
* points[0] = board.create('point', [-1,2], {size:4});
|
|
1905
|
+
* points[1] = board.create('point', [0, 0], {size:4});
|
|
1906
|
+
* points[2] = board.create('point', [2, 1], {size:4});
|
|
1907
|
+
*
|
|
1908
|
+
* var f = JXG.Math.Numerics.lagrangePolynomial(points);
|
|
1909
|
+
* var graph = board.create('functiongraph', [f,-10, 10], {strokeWidth:3});
|
|
1910
|
+
* var txt = board.create('text', [-3, -4, () => f.getTerm(2, 't', ' * ')], {fontSize: 16});
|
|
1911
|
+
*
|
|
1912
|
+
* })();
|
|
1913
|
+
*
|
|
1914
|
+
* </script><pre>
|
|
1915
|
+
*
|
|
1916
|
+
*/
|
|
1917
|
+
fct.getTerm = function(digits, param, dot) {
|
|
1918
|
+
return that.lagrangePolynomialTerm(p, digits, param, dot)();
|
|
1848
1919
|
};
|
|
1849
1920
|
|
|
1850
1921
|
return fct;
|
|
1851
1922
|
},
|
|
1923
|
+
// fct.getTerm = that.lagrangePolynomialTerm(p, 2, 'x');
|
|
1924
|
+
|
|
1925
|
+
/**
|
|
1926
|
+
* Determine the Lagrange polynomial through an array of points and
|
|
1927
|
+
* return the term of the polynomial as string.
|
|
1928
|
+
*
|
|
1929
|
+
* @param {Array} points Array of JXG.Points
|
|
1930
|
+
* @param {Number} digits Number of decimal digits of the coefficients
|
|
1931
|
+
* @param {String} param Name of the parameter. Default: 'x'.
|
|
1932
|
+
* @param {String} dot Multiplication symbol. Default: ' * '.
|
|
1933
|
+
* @returns {String} containing the Lagrange polynomial through
|
|
1934
|
+
* the supplied points.
|
|
1935
|
+
* @memberof JXG.Math.Numerics
|
|
1936
|
+
*
|
|
1937
|
+
* @example
|
|
1938
|
+
* var points = [];
|
|
1939
|
+
* points[0] = board.create('point', [-1,2], {size:4});
|
|
1940
|
+
* points[1] = board.create('point', [0, 0], {size:4});
|
|
1941
|
+
* points[2] = board.create('point', [2, 1], {size:4});
|
|
1942
|
+
*
|
|
1943
|
+
* var f = JXG.Math.Numerics.lagrangePolynomial(points);
|
|
1944
|
+
* var graph = board.create('functiongraph', [f,-10, 10], {strokeWidth:3});
|
|
1945
|
+
*
|
|
1946
|
+
* var f_txt = JXG.Math.Numerics.lagrangePolynomialTerm(points, 2, 't', ' * ');
|
|
1947
|
+
* var txt = board.create('text', [-3, -4, f_txt], {fontSize: 16});
|
|
1948
|
+
*
|
|
1949
|
+
* </pre><div id="JXGd45e9e96-7526-486d-aa43-e1178d5f2baa" class="jxgbox" style="width: 300px; height: 300px;"></div>
|
|
1950
|
+
* <script type="text/javascript">
|
|
1951
|
+
* (function() {
|
|
1952
|
+
* var board = JXG.JSXGraph.initBoard('JXGd45e9e96-7526-486d-aa43-e1178d5f2baa',
|
|
1953
|
+
* {boundingbox: [-8, 8, 8,-8], axis: true, showcopyright: false, shownavigation: false});
|
|
1954
|
+
* var points = [];
|
|
1955
|
+
* points[0] = board.create('point', [-1,2], {size:4});
|
|
1956
|
+
* points[1] = board.create('point', [0, 0], {size:4});
|
|
1957
|
+
* points[2] = board.create('point', [2, 1], {size:4});
|
|
1958
|
+
*
|
|
1959
|
+
* var f = JXG.Math.Numerics.lagrangePolynomial(points);
|
|
1960
|
+
* var graph = board.create('functiongraph', [f,-10, 10], {strokeWidth:3});
|
|
1961
|
+
*
|
|
1962
|
+
* var f_txt = JXG.Math.Numerics.lagrangePolynomialTerm(points, 2, 't', ' * ');
|
|
1963
|
+
* var txt = board.create('text', [-3, -4, f_txt], {fontSize: 16});
|
|
1964
|
+
*
|
|
1965
|
+
* })();
|
|
1966
|
+
*
|
|
1967
|
+
* </script><pre>
|
|
1968
|
+
*
|
|
1969
|
+
*/
|
|
1970
|
+
lagrangePolynomialTerm: function(points, digits, param, dot) {
|
|
1971
|
+
return function() {
|
|
1972
|
+
var len = points.length,
|
|
1973
|
+
zeroes = [],
|
|
1974
|
+
coeffs = [],
|
|
1975
|
+
coeffs_sum = [],
|
|
1976
|
+
isLeading = true,
|
|
1977
|
+
n, t,
|
|
1978
|
+
i, j, c, p;
|
|
1979
|
+
|
|
1980
|
+
param = param || 'x';
|
|
1981
|
+
if (dot === undefined) {
|
|
1982
|
+
dot = ' * ';
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
n = len - 1; // (Max) degree of the polynomial
|
|
1986
|
+
for (j = 0; j < len; j++) {
|
|
1987
|
+
coeffs_sum[j] = 0;
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
for (i = 0; i < len; i++) {
|
|
1991
|
+
c = points[i].Y();
|
|
1992
|
+
p = points[i].X();
|
|
1993
|
+
zeroes = [];
|
|
1994
|
+
for (j = 0; j < len; j++) {
|
|
1995
|
+
if (j !== i) {
|
|
1996
|
+
c /= p - points[j].X();
|
|
1997
|
+
zeroes.push(points[j].X());
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
coeffs = [1].concat(Mat.Vieta(zeroes));
|
|
2001
|
+
for (j = 0; j < coeffs.length; j++) {
|
|
2002
|
+
coeffs_sum[j] += (j%2===1?(-1):1) * coeffs[j] * c;
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
t = '';
|
|
2007
|
+
for (j = 0; j < coeffs_sum.length; j++) {
|
|
2008
|
+
c = coeffs_sum[j];
|
|
2009
|
+
if (Math.abs(c) < Mat.eps) {
|
|
2010
|
+
continue;
|
|
2011
|
+
}
|
|
2012
|
+
if (JXG.exists(digits)) {
|
|
2013
|
+
c = Env._round10(c, -digits);
|
|
2014
|
+
}
|
|
2015
|
+
if (isLeading) {
|
|
2016
|
+
t += (c > 0) ? (c) : ('-' + (-c));
|
|
2017
|
+
isLeading = false;
|
|
2018
|
+
} else {
|
|
2019
|
+
t += (c > 0) ? (' + ' + c) : (' - ' + (-c));
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
if (n - j > 1) {
|
|
2023
|
+
t += dot + param + '^' + (n - j);
|
|
2024
|
+
} else if (n - j === 1) {
|
|
2025
|
+
t += dot + param;
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
return t; // board.jc.manipulate('f = map(x) -> ' + t + ';');
|
|
2029
|
+
};
|
|
2030
|
+
},
|
|
1852
2031
|
|
|
1853
2032
|
/**
|
|
1854
2033
|
* Determine the coefficients of a cardinal spline polynom, See
|
package/src/math/plot.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2008-
|
|
2
|
+
Copyright 2008-2022
|
|
3
3
|
Matthias Ehmann,
|
|
4
4
|
Michael Gerhaeuser,
|
|
5
5
|
Carsten Miller,
|
|
@@ -457,7 +457,7 @@ define(['jxg', 'base/constants', 'base/coords', 'math/math', 'math/extrapolate',
|
|
|
457
457
|
vy = curve.Y(t_real, true) ;
|
|
458
458
|
vy2 = curve.Y(t_real2, true) ;
|
|
459
459
|
dy = (vy - vy2) / (t_real - t_real2);
|
|
460
|
-
|
|
460
|
+
|
|
461
461
|
if (p_good !== null) {
|
|
462
462
|
this._insertPoint_v2(curve, new Coords(Const.COORDS_BY_USER, p_good, curve.board, false));
|
|
463
463
|
return true;
|
|
@@ -1016,7 +1016,7 @@ define(['jxg', 'base/constants', 'base/coords', 'math/math', 'math/extrapolate',
|
|
|
1016
1016
|
},
|
|
1017
1017
|
|
|
1018
1018
|
/**
|
|
1019
|
-
*
|
|
1019
|
+
*
|
|
1020
1020
|
* @param {JXG.Curve} curve JSXGraph curve element
|
|
1021
1021
|
* @param {Number} ta
|
|
1022
1022
|
* @param {Number} tb
|
|
@@ -1959,7 +1959,7 @@ console.log("Polynomial of degree", level);
|
|
|
1959
1959
|
dx, dy;
|
|
1960
1960
|
|
|
1961
1961
|
//console.log("Level", level)
|
|
1962
|
-
if (level
|
|
1962
|
+
if (level === 0) {
|
|
1963
1963
|
this._insertPoint_v4(curve, [1, NaN, NaN], t);
|
|
1964
1964
|
return;
|
|
1965
1965
|
}
|
package/src/math/poly.js
CHANGED
package/src/math/probfuncs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2008-
|
|
2
|
+
Copyright 2008-2022
|
|
3
3
|
Matthias Ehmann,
|
|
4
4
|
Carsten Miller,
|
|
5
5
|
Andreas Walter,
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
/*global JXG: true, define: true*/
|
|
32
32
|
/*jslint nomen: true, plusplus: true*/
|
|
33
|
+
/*eslint no-loss-of-precision: off */
|
|
33
34
|
|
|
34
35
|
/* depends:
|
|
35
36
|
jxg
|
package/src/math/qdt.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2008-
|
|
2
|
+
Copyright 2008-2022
|
|
3
3
|
Matthias Ehmann,
|
|
4
4
|
Michael Gerhaeuser,
|
|
5
5
|
Carsten Miller,
|
|
@@ -10,20 +10,20 @@
|
|
|
10
10
|
This file is part of JSXGraph.
|
|
11
11
|
|
|
12
12
|
JSXGraph is free software dual licensed under the GNU LGPL or MIT License.
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
You can redistribute it and/or modify it under the terms of the
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
* GNU Lesser General Public License as published by
|
|
17
17
|
the Free Software Foundation, either version 3 of the License, or
|
|
18
18
|
(at your option) any later version
|
|
19
19
|
OR
|
|
20
20
|
* MIT License: https://github.com/jsxgraph/jsxgraph/blob/master/LICENSE.MIT
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
JSXGraph is distributed in the hope that it will be useful,
|
|
23
23
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
24
24
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
25
25
|
GNU Lesser General Public License for more details.
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
You should have received a copy of the GNU Lesser General Public License and
|
|
28
28
|
the MIT License along with JSXGraph. If not, see <http://www.gnu.org/licenses/>
|
|
29
29
|
and <http://opensource.org/licenses/MIT/>.
|
|
@@ -42,58 +42,64 @@ define(['math/math', 'utils/type'], function (Mat, Type) {
|
|
|
42
42
|
|
|
43
43
|
"use strict";
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Instantiate a new quad tree.
|
|
47
|
+
*
|
|
48
|
+
* @name JXG.Math.Quadtree
|
|
49
|
+
* @exports Mat.Quadtree as JXG.Math.Quadtree
|
|
50
|
+
* @param {Array} bbox Bounding box of the new quad (sub)tree.
|
|
51
|
+
* @constructor
|
|
52
|
+
*/
|
|
53
|
+
Mat.Quadtree = function (bbox) {
|
|
46
54
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
55
|
+
* The maximum number of points stored in a quad tree node
|
|
56
|
+
* before it is subdivided.
|
|
57
|
+
* @type Number
|
|
58
|
+
* @default 10
|
|
50
59
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
Type.extend(Quadtree.prototype, /** @lends JXG.Quadtree.prototype */ {
|
|
60
|
+
this.capacity = 10;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Point storage.
|
|
64
|
+
* @name JXG.Math.Quadtree#points
|
|
65
|
+
* @type Array
|
|
66
|
+
*/
|
|
67
|
+
this.points = [];
|
|
68
|
+
this.xlb = bbox[0];
|
|
69
|
+
this.xub = bbox[2];
|
|
70
|
+
this.ylb = bbox[3];
|
|
71
|
+
this.yub = bbox[1];
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* In a subdivided quad tree this represents the top left subtree.
|
|
75
|
+
* @name JXG.Math.Quadtree#northWest
|
|
76
|
+
* @type JXG.Math.Quadtree
|
|
77
|
+
*/
|
|
78
|
+
this.northWest = null;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* In a subdivided quad tree this represents the top right subtree.
|
|
82
|
+
* @name JXG.Math.Quadtree#northEast
|
|
83
|
+
* @type JXG.Math.Quadtree
|
|
84
|
+
*/
|
|
85
|
+
this.northEast = null;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* In a subdivided quad tree this represents the bottom right subtree.
|
|
89
|
+
* @name JXG.Math.Quadtree#southEast
|
|
90
|
+
* @type JXG.Math.Quadtree
|
|
91
|
+
*/
|
|
92
|
+
this.southEast = null;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* In a subdivided quad tree this represents the bottom left subtree.
|
|
96
|
+
* @name JXG.Math.Quadtree#southWest
|
|
97
|
+
* @type JXG.Math.Quadtree
|
|
98
|
+
*/
|
|
99
|
+
this.southWest = null;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
Type.extend(Mat.Quadtree.prototype, /** @lends JXG.Math.Quadtree.prototype */ {
|
|
97
103
|
/**
|
|
98
104
|
* Checks if the given coordinates are inside the quad tree.
|
|
99
105
|
* @param {Number} x
|
|
@@ -149,10 +155,10 @@ define(['math/math', 'utils/type'], function (Mat, Type) {
|
|
|
149
155
|
mx = this.xlb + (this.xub - this.xlb) / 2,
|
|
150
156
|
my = this.ylb + (this.yub - this.ylb) / 2;
|
|
151
157
|
|
|
152
|
-
this.northWest = new Quadtree([this.xlb, this.yub, mx, my]);
|
|
153
|
-
this.northEast = new Quadtree([mx, this.yub, this.xub, my]);
|
|
154
|
-
this.southEast = new Quadtree([this.xlb, my, mx, this.ylb]);
|
|
155
|
-
this.southWest = new Quadtree([mx, my, this.xub, this.ylb]);
|
|
158
|
+
this.northWest = new Mat.Quadtree([this.xlb, this.yub, mx, my]);
|
|
159
|
+
this.northEast = new Mat.Quadtree([mx, this.yub, this.xub, my]);
|
|
160
|
+
this.southEast = new Mat.Quadtree([this.xlb, my, mx, this.ylb]);
|
|
161
|
+
this.southWest = new Mat.Quadtree([mx, my, this.xub, this.ylb]);
|
|
156
162
|
|
|
157
163
|
for (i = 0; i < l; i += 1) {
|
|
158
164
|
this.northWest.insert(this.points[i]);
|
|
@@ -164,6 +170,7 @@ define(['math/math', 'utils/type'], function (Mat, Type) {
|
|
|
164
170
|
|
|
165
171
|
/**
|
|
166
172
|
* Internal _query method that lacks adjustment of the parameter.
|
|
173
|
+
* @name JXG.Math.Quadtree#_query
|
|
167
174
|
* @param {Number} x
|
|
168
175
|
* @param {Number} y
|
|
169
176
|
* @returns {Boolean|JXG.Quadtree} The quad tree if the point is found, false
|
|
@@ -205,6 +212,7 @@ define(['math/math', 'utils/type'], function (Mat, Type) {
|
|
|
205
212
|
|
|
206
213
|
/**
|
|
207
214
|
* Retrieve the smallest quad tree that contains the given point.
|
|
215
|
+
* @name JXG.Math.Quadtree#_query
|
|
208
216
|
* @param {JXG.Coords|Number} xp
|
|
209
217
|
* @param {Number} y
|
|
210
218
|
* @returns {Boolean|JXG.Quadtree} The quad tree if the point is found, false
|
|
@@ -227,7 +235,5 @@ define(['math/math', 'utils/type'], function (Mat, Type) {
|
|
|
227
235
|
}
|
|
228
236
|
});
|
|
229
237
|
|
|
230
|
-
Mat.Quadtree
|
|
231
|
-
|
|
232
|
-
return Quadtree;
|
|
238
|
+
return Mat.Quadtree;
|
|
233
239
|
});
|
package/src/math/statistics.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2008-
|
|
2
|
+
Copyright 2008-2022
|
|
3
3
|
Matthias Ehmann,
|
|
4
4
|
Michael Gerhaeuser,
|
|
5
5
|
Carsten Miller,
|
|
@@ -130,6 +130,57 @@ define(['jxg', 'math/math', 'utils/type'], function (JXG, Mat, Type) {
|
|
|
130
130
|
return 0.0;
|
|
131
131
|
},
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* The P-th percentile ( 0 < P ≤ 100 ) of a list of N ordered values (sorted from least to greatest)
|
|
135
|
+
* is the smallest value in the list such that no more than P percent of the data is strictly less
|
|
136
|
+
* than the value and at least P percent of the data is less than or equal to that value. See {@link https://en.wikipedia.org/wiki/Percentile}.
|
|
137
|
+
*
|
|
138
|
+
* Here, the <i>linear interpolation between closest ranks</i> method is used.
|
|
139
|
+
* @param {Array} arr The set of values, need not be ordered.
|
|
140
|
+
* @param {Number|Array} percentile One or several percentiles
|
|
141
|
+
* @returns {Number|Array} Depending if a number or an array is the input for percentile, a number or an array containing the percentils
|
|
142
|
+
* is returned.
|
|
143
|
+
*/
|
|
144
|
+
percentile: function(arr, percentile) {
|
|
145
|
+
var tmp, len, i, p, res = [], per;
|
|
146
|
+
|
|
147
|
+
if (arr.length > 0) {
|
|
148
|
+
if (ArrayBuffer.isView(arr)) {
|
|
149
|
+
tmp = new Float64Array(arr);
|
|
150
|
+
tmp.sort();
|
|
151
|
+
} else {
|
|
152
|
+
tmp = arr.slice(0);
|
|
153
|
+
tmp.sort(function (a, b) {
|
|
154
|
+
return a - b;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
len = tmp.length;
|
|
158
|
+
|
|
159
|
+
if (Type.isArray(percentile)) {
|
|
160
|
+
p = percentile;
|
|
161
|
+
} else {
|
|
162
|
+
p = [percentile];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
for (i = 0; i < p.length; i++) {
|
|
166
|
+
per = len * p[i] * 0.01;
|
|
167
|
+
if (parseInt(per, 10) === per) {
|
|
168
|
+
res.push( (tmp[per - 1] + tmp[per]) * 0.5 );
|
|
169
|
+
} else {
|
|
170
|
+
res.push( tmp[parseInt(per, 10)] );
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (Type.isArray(percentile)) {
|
|
175
|
+
return res;
|
|
176
|
+
} else {
|
|
177
|
+
return res[0];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return 0.0;
|
|
182
|
+
},
|
|
183
|
+
|
|
133
184
|
/**
|
|
134
185
|
* Bias-corrected sample variance. A variance is a measure of how far a
|
|
135
186
|
* set of numbers are spread out from each other.
|
|
@@ -234,7 +285,7 @@ define(['jxg', 'math/math', 'utils/type'], function (JXG, Mat, Type) {
|
|
|
234
285
|
} else {
|
|
235
286
|
len = arr.length;
|
|
236
287
|
res = [];
|
|
237
|
-
|
|
288
|
+
|
|
238
289
|
for (i = 0; i < len; i++) {
|
|
239
290
|
res[i] = Math.abs(arr[i]);
|
|
240
291
|
}
|
|
@@ -489,7 +540,7 @@ define(['jxg', 'math/math', 'utils/type'], function (JXG, Mat, Type) {
|
|
|
489
540
|
* () => JXG.Math.Statistics.TheilSenRegression(a.map(el => el.coords))
|
|
490
541
|
* ],
|
|
491
542
|
* {strokeWidth:1, strokeColor:'black'});
|
|
492
|
-
*
|
|
543
|
+
*
|
|
493
544
|
* </pre><div id="JXG0a28be85-91c5-44d3-aae6-114e81217cf0" class="jxgbox" style="width: 300px; height: 300px;"></div>
|
|
494
545
|
* <script type="text/javascript">
|
|
495
546
|
* (function() {
|
|
@@ -500,16 +551,16 @@ define(['jxg', 'math/math', 'utils/type'], function (JXG, Mat, Type) {
|
|
|
500
551
|
* a[0]=board.create('point', [0,0]);
|
|
501
552
|
* a[1]=board.create('point', [3,0]);
|
|
502
553
|
* a[2]=board.create('point', [0,3]);
|
|
503
|
-
*
|
|
554
|
+
*
|
|
504
555
|
* board.create('line', [
|
|
505
556
|
* () => JXG.Math.Statistics.TheilSenRegression(a.map(el => el.coords))
|
|
506
557
|
* ],
|
|
507
558
|
* {strokeWidth:1, strokeColor:'black'});
|
|
508
|
-
*
|
|
559
|
+
*
|
|
509
560
|
* })();
|
|
510
|
-
*
|
|
561
|
+
*
|
|
511
562
|
* </script><pre>
|
|
512
|
-
*
|
|
563
|
+
*
|
|
513
564
|
*/
|
|
514
565
|
TheilSenRegression: function (coords) {
|
|
515
566
|
var i, j,
|
package/src/math/symbolic.js
CHANGED