@zushah/chalkboard 2.3.0 → 2.4.0
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/CHANGELOG.md +20 -0
- package/README.md +5 -5
- package/dist/Chalkboard.d.ts +60 -51
- package/dist/Chalkboard.d.ts.map +1 -1
- package/dist/Chalkboard.js +1884 -1335
- package/dist/Chalkboard.js.map +1 -1
- package/package.json +3 -2
package/dist/Chalkboard.js
CHANGED
|
@@ -164,8 +164,8 @@ var Chalkboard;
|
|
|
164
164
|
Chalkboard.VERSIONALIAS +
|
|
165
165
|
" released 04/14/2025\nAuthored by Zushah ===> https://www.github.com/Zushah\nAvailable under the MIT License ===> https://www.opensource.org/license/mit/\n\nThe Chalkboard library is a JavaScript namespace that provides a plethora of both practical and abstract mathematical functionalities for its user.\n\nRepository ===> https://www.github.com/Zushah/Chalkboard\nWebsite ===> https://zushah.github.io/Chalkboard");
|
|
166
166
|
};
|
|
167
|
-
Chalkboard.VERSION = "2.
|
|
168
|
-
Chalkboard.VERSIONALIAS = "
|
|
167
|
+
Chalkboard.VERSION = "2.4.0";
|
|
168
|
+
Chalkboard.VERSIONALIAS = "Noether";
|
|
169
169
|
})(Chalkboard || (Chalkboard = {}));
|
|
170
170
|
if (typeof window === "undefined") {
|
|
171
171
|
module.exports = Chalkboard;
|
|
@@ -458,16 +458,24 @@ var Chalkboard;
|
|
|
458
458
|
struc2.operation(a[1], b[1])
|
|
459
459
|
]; };
|
|
460
460
|
var identity = [struc1.identity, struc2.identity];
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
461
|
+
if ("inverter" in struc1 && "inverter" in struc2) {
|
|
462
|
+
var inverter = function (a) { return [
|
|
463
|
+
struc1.inverter(a[0]),
|
|
464
|
+
struc2.inverter(a[1])
|
|
465
|
+
]; };
|
|
466
|
+
if (type === "sum") {
|
|
467
|
+
if (!struc1.set.elements || !struc2.set.elements) {
|
|
468
|
+
throw new Error("Direct sum is only defined for finite groups.");
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return Chalkboard.abal.group(set, operation, identity, inverter);
|
|
472
|
+
}
|
|
465
473
|
if (type === "sum") {
|
|
466
474
|
if (!struc1.set.elements || !struc2.set.elements) {
|
|
467
|
-
throw new Error("Direct sum is only defined for finite
|
|
475
|
+
throw new Error("Direct sum is only defined for finite structures.");
|
|
468
476
|
}
|
|
469
477
|
}
|
|
470
|
-
return Chalkboard.abal.
|
|
478
|
+
return Chalkboard.abal.monoid(set, operation, identity);
|
|
471
479
|
}
|
|
472
480
|
if ("add" in struc1 && "add" in struc2 && "mul" in struc1 && "mul" in struc2) {
|
|
473
481
|
if (type === "sum") {
|
|
@@ -495,34 +503,11 @@ var Chalkboard;
|
|
|
495
503
|
return morphism;
|
|
496
504
|
};
|
|
497
505
|
abal.field = function (set, add, mul, addIdentity, mulIdentity, addInverter, mulInverter) {
|
|
498
|
-
var _a, _b;
|
|
499
|
-
var presets = {
|
|
500
|
-
addition: {
|
|
501
|
-
Z: function (a, b) { return a + b; },
|
|
502
|
-
Q: function (a, b) { return a + b; },
|
|
503
|
-
R: function (a, b) { return a + b; },
|
|
504
|
-
C: Chalkboard.comp.add,
|
|
505
|
-
M: Chalkboard.matr.add
|
|
506
|
-
},
|
|
507
|
-
multiplication: {
|
|
508
|
-
Z: function (a, b) { return a * b; },
|
|
509
|
-
Q: function (a, b) { return a * b; },
|
|
510
|
-
R: function (a, b) { return a * b; },
|
|
511
|
-
C: Chalkboard.comp.mul,
|
|
512
|
-
M: Chalkboard.matr.mul
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
var _set = typeof set === "string" && typeof Chalkboard.abal[set] === "function" ? Chalkboard.abal[set]() : set;
|
|
516
|
-
var _add = typeof add === "string" ? presets[add]["addition"] || presets[add][(_a = _set.id) !== null && _a !== void 0 ? _a : ""] : add;
|
|
517
|
-
var _mul = typeof mul === "string" ? presets[mul]["multiplication"] || presets[mul][(_b = _set.id) !== null && _b !== void 0 ? _b : ""] : mul;
|
|
518
|
-
if (!_add || !_mul) {
|
|
519
|
-
throw new Error("Preset operations \"".concat(add, "\" or \"").concat(mul, "\" are not defined for set \"").concat(_set.id, "\"."));
|
|
520
|
-
}
|
|
521
506
|
var autoconfig = function () {
|
|
522
|
-
if (!
|
|
507
|
+
if (!set.id) {
|
|
523
508
|
throw new Error('The "set" must have a valid "id" property, or you must input "addIdentity", "mulIdentity", "addInverter", and "mulInverter" explicitly.');
|
|
524
509
|
}
|
|
525
|
-
if (
|
|
510
|
+
if (set.id === "Q" || set.id === "R") {
|
|
526
511
|
return {
|
|
527
512
|
addIdentity: 0,
|
|
528
513
|
mulIdentity: 1,
|
|
@@ -530,7 +515,7 @@ var Chalkboard;
|
|
|
530
515
|
mulInverter: function (a) { return (1 / a); }
|
|
531
516
|
};
|
|
532
517
|
}
|
|
533
|
-
else if (
|
|
518
|
+
else if (set.id === "C") {
|
|
534
519
|
return {
|
|
535
520
|
addIdentity: Chalkboard.comp.init(0, 0),
|
|
536
521
|
mulIdentity: Chalkboard.comp.init(1, 0),
|
|
@@ -541,7 +526,7 @@ var Chalkboard;
|
|
|
541
526
|
throw new Error('Automatic configuration of the "addIdentity", "mulIdentity", "addInverter", and "mulInverter" properties is not available for the inputted "set".');
|
|
542
527
|
};
|
|
543
528
|
var configured = typeof addIdentity === "undefined" || typeof mulIdentity === "undefined" || typeof addInverter === "undefined" || typeof mulInverter === "undefined" ? autoconfig() : { addIdentity: addIdentity, mulIdentity: mulIdentity, addInverter: addInverter, mulInverter: mulInverter };
|
|
544
|
-
var field = { set:
|
|
529
|
+
var field = { set: set, add: add, mul: mul, addIdentity: configured.addIdentity, mulIdentity: configured.mulIdentity, addInverter: configured.addInverter, mulInverter: configured.mulInverter };
|
|
545
530
|
if (!Chalkboard.abal.isField(field)) {
|
|
546
531
|
throw new Error('The inputted "set", "add", "mul", "addIdentity", "mulIdentity", "addInverter", and "mulInverter" do not form a field.');
|
|
547
532
|
}
|
|
@@ -585,76 +570,52 @@ var Chalkboard;
|
|
|
585
570
|
id: "GL".concat(n)
|
|
586
571
|
}); };
|
|
587
572
|
abal.group = function (set, operation, identity, inverter) {
|
|
588
|
-
var presets = {
|
|
589
|
-
addition: {
|
|
590
|
-
Z: function (a, b) { return a + b; },
|
|
591
|
-
Q: function (a, b) { return a + b; },
|
|
592
|
-
R: function (a, b) { return a + b; },
|
|
593
|
-
C: Chalkboard.comp.add,
|
|
594
|
-
M: Chalkboard.matr.add
|
|
595
|
-
},
|
|
596
|
-
multiplication: {
|
|
597
|
-
Z: function (a, b) { return a * b; },
|
|
598
|
-
Q: function (a, b) { return a * b; },
|
|
599
|
-
R: function (a, b) { return a * b; },
|
|
600
|
-
C: Chalkboard.comp.mul,
|
|
601
|
-
M: Chalkboard.matr.mul
|
|
602
|
-
}
|
|
603
|
-
};
|
|
604
|
-
var _set = typeof set === "string" && typeof Chalkboard.abal[set] === "function" ? Chalkboard.abal[set]() : set;
|
|
605
|
-
var _operation = typeof operation === "string" && _set.id ? presets[operation][_set.id] : operation;
|
|
606
|
-
if (!_operation) {
|
|
607
|
-
throw new Error("Preset operation \"".concat(operation, "\" is not defined for set \"").concat(_set.id, "\"."));
|
|
608
|
-
}
|
|
609
|
-
if (!_operation) {
|
|
610
|
-
throw new Error("Preset operation \"".concat(operation, "\" is not defined for set \"").concat(_set.id, "\"."));
|
|
611
|
-
}
|
|
612
573
|
var autoconfig = function () {
|
|
613
|
-
if (!
|
|
574
|
+
if (!set.id) {
|
|
614
575
|
throw new Error('The "set" must have a valid "id" property, or you must input "identity" and "inverter" explicitly.');
|
|
615
576
|
}
|
|
616
|
-
if (
|
|
577
|
+
if (set.id === "Z" || set.id === "Q" || set.id === "R") {
|
|
617
578
|
return {
|
|
618
579
|
identity: 0,
|
|
619
580
|
inverter: function (a) { return -a; }
|
|
620
581
|
};
|
|
621
582
|
}
|
|
622
|
-
else if (
|
|
583
|
+
else if (set.id === "C") {
|
|
623
584
|
return {
|
|
624
585
|
identity: Chalkboard.comp.init(0, 0),
|
|
625
586
|
inverter: function (a) { return Chalkboard.comp.negate(a); }
|
|
626
587
|
};
|
|
627
588
|
}
|
|
628
|
-
else if (
|
|
629
|
-
var n_1 = parseInt(
|
|
589
|
+
else if (set.id.startsWith("Z") && set.id.length > 1) {
|
|
590
|
+
var n_1 = parseInt(set.id.slice(1), 10);
|
|
630
591
|
return {
|
|
631
592
|
identity: 0,
|
|
632
593
|
inverter: function (a) { return ((n_1 - a % n_1) % n_1); }
|
|
633
594
|
};
|
|
634
595
|
}
|
|
635
|
-
else if (
|
|
596
|
+
else if (set.id.startsWith("C") && set.id.length > 1) {
|
|
636
597
|
return {
|
|
637
598
|
identity: Chalkboard.comp.init(1, 0),
|
|
638
599
|
inverter: function (a) { return Chalkboard.comp.conjugate(a); }
|
|
639
600
|
};
|
|
640
601
|
}
|
|
641
|
-
else if (
|
|
642
|
-
var rows =
|
|
643
|
-
var cols =
|
|
602
|
+
else if (set.id.startsWith("M(")) {
|
|
603
|
+
var rows = set.rows;
|
|
604
|
+
var cols = set.cols;
|
|
644
605
|
return {
|
|
645
606
|
identity: Chalkboard.matr.fill(0, rows, cols),
|
|
646
607
|
inverter: function (a) { return Chalkboard.matr.negate(a); }
|
|
647
608
|
};
|
|
648
609
|
}
|
|
649
|
-
else if (
|
|
650
|
-
var n = parseInt(
|
|
610
|
+
else if (set.id.startsWith("GL")) {
|
|
611
|
+
var n = parseInt(set.id.slice(2), 10);
|
|
651
612
|
return {
|
|
652
613
|
identity: Chalkboard.matr.identity(n),
|
|
653
614
|
inverter: function (a) { return Chalkboard.matr.invert(a); }
|
|
654
615
|
};
|
|
655
616
|
}
|
|
656
|
-
else if (
|
|
657
|
-
var n = parseInt(
|
|
617
|
+
else if (set.id.match(/^[SA]\d+$/)) {
|
|
618
|
+
var n = parseInt(set.id.slice(1), 10);
|
|
658
619
|
return {
|
|
659
620
|
identity: Array.from({ length: n }, function (_, i) { return i; }),
|
|
660
621
|
inverter: function (a) {
|
|
@@ -669,7 +630,7 @@ var Chalkboard;
|
|
|
669
630
|
throw new Error('Automatic configuration of the "identity" and "inverter" properties is not available for the inputted "set".');
|
|
670
631
|
};
|
|
671
632
|
var configured = typeof identity === "undefined" || typeof inverter === "undefined" ? autoconfig() : { identity: identity, inverter: inverter };
|
|
672
|
-
var group = { set:
|
|
633
|
+
var group = { set: set, operation: operation, identity: configured.identity, inverter: configured.inverter };
|
|
673
634
|
if (!Chalkboard.abal.isGroup(group)) {
|
|
674
635
|
throw new Error('The inputted "set", "operation", "identity", and "inverter" do not form a group.');
|
|
675
636
|
}
|
|
@@ -730,80 +691,40 @@ var Chalkboard;
|
|
|
730
691
|
return Chalkboard.abal.isInjective(morph) && Chalkboard.abal.isSurjective(morph);
|
|
731
692
|
};
|
|
732
693
|
abal.isClosed = function (set, operation) {
|
|
733
|
-
var _a;
|
|
734
|
-
if (
|
|
735
|
-
|
|
736
|
-
return true;
|
|
737
|
-
return false;
|
|
694
|
+
var _a, _b;
|
|
695
|
+
if (set.id && ["Z", "Q", "R", "C"].includes(set.id)) {
|
|
696
|
+
return true;
|
|
738
697
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
Z: function (a, b) { return a + b; },
|
|
742
|
-
Q: function (a, b) { return a + b; },
|
|
743
|
-
R: function (a, b) { return a + b; },
|
|
744
|
-
C: Chalkboard.comp.add,
|
|
745
|
-
M: Chalkboard.matr.add,
|
|
746
|
-
},
|
|
747
|
-
multiplication: {
|
|
748
|
-
Z: function (a, b) { return a * b; },
|
|
749
|
-
Q: function (a, b) { return a * b; },
|
|
750
|
-
R: function (a, b) { return a * b; },
|
|
751
|
-
C: Chalkboard.comp.mul,
|
|
752
|
-
M: Chalkboard.matr.mul,
|
|
753
|
-
}
|
|
754
|
-
};
|
|
755
|
-
var _set = typeof set === "string" && (set in Chalkboard.abal) && typeof Chalkboard.abal[set] === "function"
|
|
756
|
-
? (Object.prototype.hasOwnProperty.call(Chalkboard.abal, set) && typeof Chalkboard.abal[set] === "function" ? Chalkboard.abal[set]() : undefined)
|
|
757
|
-
: set;
|
|
758
|
-
if (!_set || typeof _set !== "object") {
|
|
759
|
-
throw new Error('The "set" must have a valid "id" property or be resolvable from a string.');
|
|
760
|
-
}
|
|
761
|
-
var _operation = typeof operation === "string" && typeof _set !== "string" && _set.id && operation in presets && _set.id in presets[operation]
|
|
762
|
-
? presets[operation][_set.id]
|
|
763
|
-
: operation;
|
|
764
|
-
if (!_operation) {
|
|
765
|
-
throw new Error("Preset operation \"".concat(operation, "\" is not defined for set \"").concat(_set.id, "\"."));
|
|
766
|
-
}
|
|
767
|
-
if (_set.id === "Z" || _set.id === "Q" || _set.id === "R") {
|
|
768
|
-
if (_operation === presets.addition[_set.id] ||
|
|
769
|
-
_operation === presets.multiplication[_set.id]) {
|
|
698
|
+
if ((_a = set.id) === null || _a === void 0 ? void 0 : _a.startsWith("M(")) {
|
|
699
|
+
if (operation === Chalkboard.matr.add) {
|
|
770
700
|
return true;
|
|
771
701
|
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
return true;
|
|
702
|
+
if (operation === Chalkboard.matr.mul) {
|
|
703
|
+
var dimensions = (_b = set.id.match(/\d+/g)) === null || _b === void 0 ? void 0 : _b.map(Number);
|
|
704
|
+
if (dimensions && dimensions.length >= 2) {
|
|
705
|
+
return dimensions[0] === dimensions[1];
|
|
706
|
+
}
|
|
778
707
|
}
|
|
779
708
|
return false;
|
|
780
709
|
}
|
|
781
|
-
if (
|
|
782
|
-
|
|
783
|
-
var cols = _set.cols;
|
|
784
|
-
if (_operation === Chalkboard.matr.add) {
|
|
710
|
+
if (set.id === "C") {
|
|
711
|
+
if (operation === Chalkboard.comp.add || operation === Chalkboard.comp.mul) {
|
|
785
712
|
return true;
|
|
786
713
|
}
|
|
787
|
-
if (_operation === Chalkboard.matr.mul) {
|
|
788
|
-
return rows === cols;
|
|
789
|
-
}
|
|
790
714
|
return false;
|
|
791
715
|
}
|
|
792
|
-
if (typeof
|
|
793
|
-
for (var _i = 0,
|
|
794
|
-
var a =
|
|
795
|
-
for (var
|
|
796
|
-
var b = _d
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
if (_set.contains(result)) {
|
|
800
|
-
continue;
|
|
801
|
-
}
|
|
716
|
+
if (typeof set === "object" && "elements" in set && set.elements) {
|
|
717
|
+
for (var _i = 0, _c = set.elements; _i < _c.length; _i++) {
|
|
718
|
+
var a = _c[_i];
|
|
719
|
+
for (var _d = 0, _e = set.elements; _d < _e.length; _d++) {
|
|
720
|
+
var b = _e[_d];
|
|
721
|
+
var result = operation(a, b);
|
|
722
|
+
if (!set.contains(result)) {
|
|
802
723
|
return false;
|
|
803
724
|
}
|
|
804
|
-
return false;
|
|
805
725
|
}
|
|
806
726
|
}
|
|
727
|
+
return true;
|
|
807
728
|
}
|
|
808
729
|
return true;
|
|
809
730
|
};
|
|
@@ -906,14 +827,20 @@ var Chalkboard;
|
|
|
906
827
|
return set1.every(function (x) { return struc2.contains(x); }) && set2.every(function (x) { return struc1.contains(x); });
|
|
907
828
|
}
|
|
908
829
|
if ("operation" in struc1 && "operation" in struc2) {
|
|
909
|
-
var
|
|
910
|
-
var
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
(
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
830
|
+
var monoiroup1 = struc1;
|
|
831
|
+
var monoiroup2 = struc2;
|
|
832
|
+
var monoidEqual = Chalkboard.abal.isEqual(monoiroup1.set, monoiroup2.set) &&
|
|
833
|
+
monoiroup1.identity === monoiroup2.identity &&
|
|
834
|
+
(monoiroup1.operation === monoiroup2.operation ||
|
|
835
|
+
monoiroup1.operation.toString() === monoiroup2.operation.toString());
|
|
836
|
+
if ("inverter" in monoiroup1 && "inverter" in monoiroup2) {
|
|
837
|
+
return monoidEqual && (monoiroup1.inverter === monoiroup2.inverter ||
|
|
838
|
+
monoiroup1.inverter.toString() === monoiroup2.inverter.toString());
|
|
839
|
+
}
|
|
840
|
+
if (("inverter" in monoiroup1) !== ("inverter" in monoiroup2)) {
|
|
841
|
+
return false;
|
|
842
|
+
}
|
|
843
|
+
return monoidEqual;
|
|
917
844
|
}
|
|
918
845
|
if ("add" in struc1 && "add" in struc2 && "mul" in struc1 && "mul" in struc2) {
|
|
919
846
|
var ring1 = struc1;
|
|
@@ -1153,6 +1080,40 @@ var Chalkboard;
|
|
|
1153
1080
|
abal.isIsomorphism = function (morph) {
|
|
1154
1081
|
return Chalkboard.abal.isHomomorphism(morph) && Chalkboard.abal.isBijective(morph);
|
|
1155
1082
|
};
|
|
1083
|
+
abal.isMonoid = function (monoid) {
|
|
1084
|
+
var set = monoid.set, operation = monoid.operation, identity = monoid.identity;
|
|
1085
|
+
if (set.id === "Z" || set.id === "Q" || set.id === "R" || set.id === "C" || set.id === "GL") {
|
|
1086
|
+
return true;
|
|
1087
|
+
}
|
|
1088
|
+
if (typeof set.elements === "undefined") {
|
|
1089
|
+
return false;
|
|
1090
|
+
}
|
|
1091
|
+
if (typeof operation === "undefined" || typeof identity === "undefined") {
|
|
1092
|
+
return false;
|
|
1093
|
+
}
|
|
1094
|
+
if (!Chalkboard.abal.isClosed(set, operation)) {
|
|
1095
|
+
return false;
|
|
1096
|
+
}
|
|
1097
|
+
for (var _i = 0, _a = set.elements; _i < _a.length; _i++) {
|
|
1098
|
+
var a = _a[_i];
|
|
1099
|
+
if ($(operation(a, identity)) !== $(a) || $(operation(identity, a)) !== $(a)) {
|
|
1100
|
+
return false;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
for (var _b = 0, _c = set.elements; _b < _c.length; _b++) {
|
|
1104
|
+
var a = _c[_b];
|
|
1105
|
+
for (var _d = 0, _e = set.elements; _d < _e.length; _d++) {
|
|
1106
|
+
var b = _e[_d];
|
|
1107
|
+
for (var _f = 0, _g = set.elements; _f < _g.length; _f++) {
|
|
1108
|
+
var c = _g[_f];
|
|
1109
|
+
if ($(operation(operation(a, b), c)) !== $(operation(a, operation(b, c)))) {
|
|
1110
|
+
return false;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
return true;
|
|
1116
|
+
};
|
|
1156
1117
|
abal.isNormalSubgroup = function (group, subgroup) {
|
|
1157
1118
|
var set = group.set, operation = group.operation, inverter = group.inverter;
|
|
1158
1119
|
if (!operation || !inverter) {
|
|
@@ -1224,6 +1185,20 @@ var Chalkboard;
|
|
|
1224
1185
|
};
|
|
1225
1186
|
abal.isSubfield = function (field, subset) {
|
|
1226
1187
|
var add = field.add, mul = field.mul, addIdentity = field.addIdentity, mulIdentity = field.mulIdentity, addInverter = field.addInverter, mulInverter = field.mulInverter;
|
|
1188
|
+
if (field.set.id && subset.id) {
|
|
1189
|
+
if (subset.id === field.set.id && ["Q", "R", "C"].includes(subset.id)) {
|
|
1190
|
+
return true;
|
|
1191
|
+
}
|
|
1192
|
+
if (subset.id === "Q" && ["R", "C"].includes(field.set.id)) {
|
|
1193
|
+
return true;
|
|
1194
|
+
}
|
|
1195
|
+
if (subset.id === "R" && field.set.id === "C") {
|
|
1196
|
+
return true;
|
|
1197
|
+
}
|
|
1198
|
+
if (subset.id === "Z") {
|
|
1199
|
+
return false;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1227
1202
|
if (typeof add === "undefined" || typeof mul === "undefined" || typeof addIdentity === "undefined" || typeof mulIdentity === "undefined" || typeof addInverter === "undefined" || typeof mulInverter === "undefined") {
|
|
1228
1203
|
return false;
|
|
1229
1204
|
}
|
|
@@ -1248,7 +1223,32 @@ var Chalkboard;
|
|
|
1248
1223
|
return true;
|
|
1249
1224
|
};
|
|
1250
1225
|
abal.isSubgroup = function (group, subset) {
|
|
1226
|
+
var _a;
|
|
1251
1227
|
var operation = group.operation, identity = group.identity, inverter = group.inverter;
|
|
1228
|
+
if (group.set.id && subset.id) {
|
|
1229
|
+
if (subset.id === "Z" && ["Z", "Q", "R", "C"].includes(group.set.id)) {
|
|
1230
|
+
return true;
|
|
1231
|
+
}
|
|
1232
|
+
if (subset.id === "Q" && ["Q", "R", "C"].includes(group.set.id)) {
|
|
1233
|
+
return true;
|
|
1234
|
+
}
|
|
1235
|
+
if (subset.id === "R" && ["R", "C"].includes(group.set.id)) {
|
|
1236
|
+
return true;
|
|
1237
|
+
}
|
|
1238
|
+
if (subset.id === "C" && group.set.id === "C") {
|
|
1239
|
+
return true;
|
|
1240
|
+
}
|
|
1241
|
+
if (subset.id.startsWith("Z") && group.set.id.startsWith("Z")) {
|
|
1242
|
+
var nSubset = parseInt(subset.id.slice(1), 10);
|
|
1243
|
+
var nGroup = parseInt(group.set.id.slice(1), 10);
|
|
1244
|
+
if (!isNaN(nSubset) && !isNaN(nGroup)) {
|
|
1245
|
+
return nGroup % nSubset === 0;
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
if (((_a = subset.id) === null || _a === void 0 ? void 0 : _a.startsWith("GL")) && subset.id === group.set.id) {
|
|
1249
|
+
return true;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
1252
|
if (typeof operation === "undefined" || typeof identity === "undefined" || typeof inverter === "undefined") {
|
|
1253
1253
|
return false;
|
|
1254
1254
|
}
|
|
@@ -1258,16 +1258,64 @@ var Chalkboard;
|
|
|
1258
1258
|
if (!Chalkboard.abal.isClosed(subset, operation)) {
|
|
1259
1259
|
return false;
|
|
1260
1260
|
}
|
|
1261
|
-
for (var _i = 0,
|
|
1262
|
-
var a =
|
|
1261
|
+
for (var _i = 0, _b = subset.elements || []; _i < _b.length; _i++) {
|
|
1262
|
+
var a = _b[_i];
|
|
1263
1263
|
if (!subset.contains(inverter(a))) {
|
|
1264
1264
|
return false;
|
|
1265
1265
|
}
|
|
1266
1266
|
}
|
|
1267
1267
|
return true;
|
|
1268
1268
|
};
|
|
1269
|
+
abal.isSubmonoid = function (monoid, subset) {
|
|
1270
|
+
var operation = monoid.operation, identity = monoid.identity;
|
|
1271
|
+
if (monoid.set.id && subset.id) {
|
|
1272
|
+
if (subset.id === monoid.set.id) {
|
|
1273
|
+
return true;
|
|
1274
|
+
}
|
|
1275
|
+
if (subset.id === "Z" && ["Z", "Q", "R", "C"].includes(monoid.set.id)) {
|
|
1276
|
+
return true;
|
|
1277
|
+
}
|
|
1278
|
+
if (subset.id === "Q" && ["Q", "R", "C"].includes(monoid.set.id)) {
|
|
1279
|
+
return true;
|
|
1280
|
+
}
|
|
1281
|
+
if (subset.id === "R" && ["R", "C"].includes(monoid.set.id)) {
|
|
1282
|
+
return true;
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
if (typeof operation === "undefined" || typeof identity === "undefined") {
|
|
1286
|
+
return false;
|
|
1287
|
+
}
|
|
1288
|
+
if (!subset.contains(identity)) {
|
|
1289
|
+
return false;
|
|
1290
|
+
}
|
|
1291
|
+
if (!Chalkboard.abal.isClosed(subset, operation)) {
|
|
1292
|
+
return false;
|
|
1293
|
+
}
|
|
1294
|
+
return true;
|
|
1295
|
+
};
|
|
1269
1296
|
abal.isSubring = function (ring, subset) {
|
|
1270
1297
|
var add = ring.add, mul = ring.mul, addIdentity = ring.addIdentity, addInverter = ring.addInverter;
|
|
1298
|
+
if (ring.set.id && subset.id) {
|
|
1299
|
+
if (subset.id === ring.set.id) {
|
|
1300
|
+
return true;
|
|
1301
|
+
}
|
|
1302
|
+
if (subset.id === "Z" && ["Z", "Q", "R", "C"].includes(ring.set.id)) {
|
|
1303
|
+
return true;
|
|
1304
|
+
}
|
|
1305
|
+
if (subset.id === "Q" && ["Q", "R", "C"].includes(ring.set.id)) {
|
|
1306
|
+
return true;
|
|
1307
|
+
}
|
|
1308
|
+
if (subset.id === "R" && ["R", "C"].includes(ring.set.id)) {
|
|
1309
|
+
return true;
|
|
1310
|
+
}
|
|
1311
|
+
if (subset.id.startsWith("Z") && ring.set.id.startsWith("Z")) {
|
|
1312
|
+
var nSubset = parseInt(subset.id.slice(1), 10);
|
|
1313
|
+
var nRing = parseInt(ring.set.id.slice(1), 10);
|
|
1314
|
+
if (!isNaN(nSubset) && !isNaN(nRing)) {
|
|
1315
|
+
return nRing % nSubset === 0;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1271
1319
|
if (typeof add === "undefined" || typeof mul === "undefined" || typeof addIdentity === "undefined" || typeof addInverter === "undefined") {
|
|
1272
1320
|
return false;
|
|
1273
1321
|
}
|
|
@@ -1286,6 +1334,30 @@ var Chalkboard;
|
|
|
1286
1334
|
return true;
|
|
1287
1335
|
};
|
|
1288
1336
|
abal.isSubset = function (set, superset) {
|
|
1337
|
+
if (set.id && superset.id) {
|
|
1338
|
+
if (set.id === superset.id) {
|
|
1339
|
+
return true;
|
|
1340
|
+
}
|
|
1341
|
+
if (set.id === "Z") {
|
|
1342
|
+
return ["Z", "Q", "R", "C"].includes(superset.id);
|
|
1343
|
+
}
|
|
1344
|
+
if (set.id === "Q") {
|
|
1345
|
+
return ["Q", "R", "C"].includes(superset.id);
|
|
1346
|
+
}
|
|
1347
|
+
if (set.id === "R") {
|
|
1348
|
+
return ["R", "C"].includes(superset.id);
|
|
1349
|
+
}
|
|
1350
|
+
if (set.id === "N") {
|
|
1351
|
+
return ["N", "Z", "Q", "R", "C"].includes(superset.id);
|
|
1352
|
+
}
|
|
1353
|
+
if (set.id.startsWith("Z") && superset.id.startsWith("Z")) {
|
|
1354
|
+
var nSet = parseInt(set.id.slice(1), 10);
|
|
1355
|
+
var nSuper = parseInt(superset.id.slice(1), 10);
|
|
1356
|
+
if (!isNaN(nSet) && !isNaN(nSuper)) {
|
|
1357
|
+
return nSuper % nSet === 0;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1289
1361
|
return (set.elements || []).every(function (element) { return superset.contains(element); });
|
|
1290
1362
|
};
|
|
1291
1363
|
abal.isSuperset = function (set, subset) {
|
|
@@ -1341,6 +1413,45 @@ var Chalkboard;
|
|
|
1341
1413
|
id: "M(".concat(rows, ", ").concat(cols, ")")
|
|
1342
1414
|
});
|
|
1343
1415
|
};
|
|
1416
|
+
abal.monoid = function (set, operation, identity) {
|
|
1417
|
+
var autoconfig = function () {
|
|
1418
|
+
if (!set.id) {
|
|
1419
|
+
throw new Error('The "set" must have a valid "id" property, or you must input "identity" explicitly.');
|
|
1420
|
+
}
|
|
1421
|
+
if (set.id === "Z" || set.id === "Q" || set.id === "R") {
|
|
1422
|
+
return { identity: 0 };
|
|
1423
|
+
}
|
|
1424
|
+
else if (set.id === "C") {
|
|
1425
|
+
return { identity: Chalkboard.comp.init(0, 0) };
|
|
1426
|
+
}
|
|
1427
|
+
else if (set.id.startsWith("Z") && set.id.length > 1) {
|
|
1428
|
+
return { identity: 0 };
|
|
1429
|
+
}
|
|
1430
|
+
else if (set.id.startsWith("C") && set.id.length > 1) {
|
|
1431
|
+
return { identity: Chalkboard.comp.init(1, 0) };
|
|
1432
|
+
}
|
|
1433
|
+
else if (set.id.startsWith("M(")) {
|
|
1434
|
+
var rows = set.rows;
|
|
1435
|
+
var cols = set.cols;
|
|
1436
|
+
return { identity: Chalkboard.matr.fill(0, rows, cols) };
|
|
1437
|
+
}
|
|
1438
|
+
else if (set.id.startsWith("GL")) {
|
|
1439
|
+
var n = parseInt(set.id.slice(2), 10);
|
|
1440
|
+
return { identity: Chalkboard.matr.identity(n) };
|
|
1441
|
+
}
|
|
1442
|
+
else if (set.id.match(/^[SA]\d+$/)) {
|
|
1443
|
+
var n = parseInt(set.id.slice(1), 10);
|
|
1444
|
+
return { identity: Array.from({ length: n }, function (_, i) { return i; }) };
|
|
1445
|
+
}
|
|
1446
|
+
throw new Error('Automatic configuration of the "identity" property is not available for the inputted "set".');
|
|
1447
|
+
};
|
|
1448
|
+
var configured = typeof identity === "undefined" ? autoconfig() : { identity: identity };
|
|
1449
|
+
var monoid = { set: set, operation: operation, identity: configured.identity };
|
|
1450
|
+
if (!Chalkboard.abal.isMonoid(monoid)) {
|
|
1451
|
+
throw new Error('The inputted "set", "operation", and "identity" do not form a monoid.');
|
|
1452
|
+
}
|
|
1453
|
+
return monoid;
|
|
1454
|
+
};
|
|
1344
1455
|
abal.N = function () { return ({
|
|
1345
1456
|
contains: function (element) { return Number.isInteger(element) && element > 0; },
|
|
1346
1457
|
id: "N"
|
|
@@ -1459,51 +1570,28 @@ var Chalkboard;
|
|
|
1459
1570
|
id: "R"
|
|
1460
1571
|
}); };
|
|
1461
1572
|
abal.ring = function (set, add, mul, addIdentity, mulIdentity, addInverter) {
|
|
1462
|
-
var _a, _b;
|
|
1463
|
-
var presets = {
|
|
1464
|
-
addition: {
|
|
1465
|
-
Z: function (a, b) { return a + b; },
|
|
1466
|
-
Q: function (a, b) { return a + b; },
|
|
1467
|
-
R: function (a, b) { return a + b; },
|
|
1468
|
-
C: Chalkboard.comp.add,
|
|
1469
|
-
M: Chalkboard.matr.add
|
|
1470
|
-
},
|
|
1471
|
-
multiplication: {
|
|
1472
|
-
Z: function (a, b) { return a * b; },
|
|
1473
|
-
Q: function (a, b) { return a * b; },
|
|
1474
|
-
R: function (a, b) { return a * b; },
|
|
1475
|
-
C: Chalkboard.comp.mul,
|
|
1476
|
-
M: Chalkboard.matr.mul
|
|
1477
|
-
},
|
|
1478
|
-
};
|
|
1479
|
-
var _set = typeof set === "string" && typeof Chalkboard.abal[set] === "function" ? Chalkboard.abal[set]() : set;
|
|
1480
|
-
var _add = typeof add === "string" ? presets[add]["addition"] || presets[add][(_a = _set.id) !== null && _a !== void 0 ? _a : ""] : add;
|
|
1481
|
-
var _mul = typeof mul === "string" ? presets[mul]["multiplication"] || presets[mul][(_b = _set.id) !== null && _b !== void 0 ? _b : ""] : mul;
|
|
1482
|
-
if (!_add || !_mul) {
|
|
1483
|
-
throw new Error("Preset operations \"".concat(add, "\" or \"").concat(mul, "\" are not defined for set \"").concat(_set.id, "\"."));
|
|
1484
|
-
}
|
|
1485
1573
|
var autoconfig = function () {
|
|
1486
|
-
if (!
|
|
1574
|
+
if (!set.id) {
|
|
1487
1575
|
throw new Error('The "set" must have a valid "id" property, or you must input "addIdentity", "mulIdentity", and "addInverter" explicitly.');
|
|
1488
1576
|
}
|
|
1489
|
-
if (
|
|
1577
|
+
if (set.id === "Z" || set.id === "Q" || set.id === "R") {
|
|
1490
1578
|
return {
|
|
1491
1579
|
addIdentity: 0,
|
|
1492
1580
|
mulIdentity: 1,
|
|
1493
1581
|
addInverter: function (a) { return -a; }
|
|
1494
1582
|
};
|
|
1495
1583
|
}
|
|
1496
|
-
else if (
|
|
1584
|
+
else if (set.id === "C") {
|
|
1497
1585
|
return {
|
|
1498
1586
|
addIdentity: Chalkboard.comp.init(0, 0),
|
|
1499
1587
|
mulIdentity: Chalkboard.comp.init(1, 0),
|
|
1500
1588
|
addInverter: function (a) { return Chalkboard.comp.negate(a); }
|
|
1501
1589
|
};
|
|
1502
1590
|
}
|
|
1503
|
-
else if (
|
|
1504
|
-
var n_2 = parseInt(
|
|
1591
|
+
else if (set.id.startsWith("Z") && set.id.length > 1) {
|
|
1592
|
+
var n_2 = parseInt(set.id.slice(1), 10);
|
|
1505
1593
|
if (isNaN(n_2) || n_2 <= 0) {
|
|
1506
|
-
throw new Error("Invalid modulus in set \"".concat(
|
|
1594
|
+
throw new Error("Invalid modulus in set \"".concat(set.id, "\"."));
|
|
1507
1595
|
}
|
|
1508
1596
|
return {
|
|
1509
1597
|
addIdentity: 0,
|
|
@@ -1511,9 +1599,9 @@ var Chalkboard;
|
|
|
1511
1599
|
addInverter: function (a) { return ((n_2 - a % n_2) % n_2); }
|
|
1512
1600
|
};
|
|
1513
1601
|
}
|
|
1514
|
-
else if (
|
|
1515
|
-
var rows =
|
|
1516
|
-
var cols =
|
|
1602
|
+
else if (set.id.startsWith("M(")) {
|
|
1603
|
+
var rows = set.rows;
|
|
1604
|
+
var cols = set.cols;
|
|
1517
1605
|
if (rows !== cols) {
|
|
1518
1606
|
throw new Error("Only square matrices can form a ring.");
|
|
1519
1607
|
}
|
|
@@ -1526,7 +1614,7 @@ var Chalkboard;
|
|
|
1526
1614
|
throw new Error('Automatic configuration of the "addIdentity", "mulIdentity", and "addInverter" properties is not available for the inputted "set".');
|
|
1527
1615
|
};
|
|
1528
1616
|
var configured = typeof addIdentity === "undefined" || typeof mulIdentity === "undefined" || typeof addInverter === "undefined" ? autoconfig() : { addIdentity: addIdentity, mulIdentity: mulIdentity, addInverter: addInverter };
|
|
1529
|
-
var ring = { set:
|
|
1617
|
+
var ring = { set: set, add: add, mul: mul, addIdentity: configured.addIdentity, mulIdentity: configured.mulIdentity, addInverter: configured.addInverter };
|
|
1530
1618
|
if (!Chalkboard.abal.isRing(ring)) {
|
|
1531
1619
|
throw new Error('The inputted "set", "add", "mul", "addIdentity", "mulIdentity", and "addInverter" do not form a ring.');
|
|
1532
1620
|
}
|
|
@@ -1652,6 +1740,33 @@ var Chalkboard;
|
|
|
1652
1740
|
size = size[0];
|
|
1653
1741
|
return (_a = Chalkboard.tens).resize.apply(_a, __spreadArray([result.elements], size, false));
|
|
1654
1742
|
};
|
|
1743
|
+
abal.toTypedArray = function (struc, type) {
|
|
1744
|
+
if (type === void 0) { type = "float32"; }
|
|
1745
|
+
var result = "set" in struc ? struc.set : struc;
|
|
1746
|
+
if (!result.elements) {
|
|
1747
|
+
throw new Error("Cannot convert infinite set to typed array.");
|
|
1748
|
+
}
|
|
1749
|
+
var arr = Chalkboard.abal.toArray(result);
|
|
1750
|
+
if (type === "int8") {
|
|
1751
|
+
return new Int8Array(arr);
|
|
1752
|
+
}
|
|
1753
|
+
else if (type === "int16") {
|
|
1754
|
+
return new Int16Array(arr);
|
|
1755
|
+
}
|
|
1756
|
+
else if (type === "int32") {
|
|
1757
|
+
return new Int32Array(arr);
|
|
1758
|
+
}
|
|
1759
|
+
else if (type === "float32") {
|
|
1760
|
+
return new Float32Array(arr);
|
|
1761
|
+
}
|
|
1762
|
+
else if (type === "float64") {
|
|
1763
|
+
return new Float64Array(arr);
|
|
1764
|
+
}
|
|
1765
|
+
else if (type === "bigint64") {
|
|
1766
|
+
return new BigInt64Array(arr.map(function (n) { return BigInt(Math.floor(n)); }));
|
|
1767
|
+
}
|
|
1768
|
+
throw new TypeError('Parameter "type" must be "int8", "int16", "int32", "float32", "float64", or "bigint64".');
|
|
1769
|
+
};
|
|
1655
1770
|
abal.toVector = function (struc, dimension, index) {
|
|
1656
1771
|
if (index === void 0) { index = 0; }
|
|
1657
1772
|
var elements = "set" in struc ? struc.set.elements : struc.elements;
|
|
@@ -1967,10 +2082,11 @@ var Chalkboard;
|
|
|
1967
2082
|
};
|
|
1968
2083
|
var mode = "boolean";
|
|
1969
2084
|
bool.modeConfig = function (config) {
|
|
1970
|
-
|
|
2085
|
+
var _config = config.toLowerCase();
|
|
2086
|
+
if (_config !== "boolean" && _config !== "binary") {
|
|
1971
2087
|
throw new Error('The mode must be either "boolean" or "binary".');
|
|
1972
2088
|
}
|
|
1973
|
-
mode =
|
|
2089
|
+
mode = _config;
|
|
1974
2090
|
};
|
|
1975
2091
|
bool.NAND = function () {
|
|
1976
2092
|
var vals = [];
|
|
@@ -2733,6 +2849,7 @@ var Chalkboard;
|
|
|
2733
2849
|
return Chalkboard.calc.fxdx(Chalkboard.real.define("(" + func1.definition + ") * (" + func2.definition.replace(/x/g, "(" + val + " + x)") + ")"), -100, 100);
|
|
2734
2850
|
};
|
|
2735
2851
|
calc.curl = function (vectfield, vect) {
|
|
2852
|
+
vect = vect;
|
|
2736
2853
|
var h = 0.000000001;
|
|
2737
2854
|
if (Chalkboard.vect.dimension(vectfield) === 2 && typeof vect.x === "number" && typeof vect.y === "number" && typeof vect.z === "undefined" && typeof vect.w === "undefined") {
|
|
2738
2855
|
var p = Chalkboard.real.parse("(x, y) => " + vectfield.p), q = Chalkboard.real.parse("(x, y) => " + vectfield.q);
|
|
@@ -2751,7 +2868,8 @@ var Chalkboard;
|
|
|
2751
2868
|
calc.curvature = function (func, val) {
|
|
2752
2869
|
if (func.type === "curv") {
|
|
2753
2870
|
if (func.definition.length === 2) {
|
|
2754
|
-
var
|
|
2871
|
+
var d = Chalkboard.calc.dfdx(func, val), d2 = Chalkboard.calc.d2fdx2(func, val);
|
|
2872
|
+
var dxdt = d.x, dydt = d.y, d2xdt2 = d2.x, d2ydt2 = d2.y;
|
|
2755
2873
|
return Math.abs(dxdt * d2ydt2 - dydt * d2xdt2) / Math.sqrt((dxdt * dxdt + dydt * dydt) * (dxdt * dxdt + dydt * dydt) * (dxdt * dxdt + dydt * dydt));
|
|
2756
2874
|
}
|
|
2757
2875
|
else {
|
|
@@ -2852,11 +2970,13 @@ var Chalkboard;
|
|
|
2852
2970
|
if (func1.type === "mult") {
|
|
2853
2971
|
if (func2.type === "curv") {
|
|
2854
2972
|
if (func2.definition.length === 2) {
|
|
2855
|
-
var
|
|
2973
|
+
var g = Chalkboard.calc.grad(func1, Chalkboard.real.val(func2, val)), d = Chalkboard.calc.dfdx(func2, val);
|
|
2974
|
+
var dfdx_1 = g.x, dfdy = g.y, dxdt = d.x, dydt = d.y;
|
|
2856
2975
|
return dfdx_1 * dxdt + dfdy * dydt;
|
|
2857
2976
|
}
|
|
2858
2977
|
else {
|
|
2859
|
-
var
|
|
2978
|
+
var g = Chalkboard.calc.grad(func1, Chalkboard.real.val(func2, val)), d = Chalkboard.calc.dfdx(func2, val);
|
|
2979
|
+
var dfdx_2 = g.x, dfdy = g.y, dfdz_1 = g.z, dxdt = d.x, dydt = d.y, dzdt = d.z;
|
|
2860
2980
|
return dfdx_2 * dxdt + dfdy * dydt + dfdz_1 * dzdt;
|
|
2861
2981
|
}
|
|
2862
2982
|
}
|
|
@@ -3076,6 +3196,7 @@ var Chalkboard;
|
|
|
3076
3196
|
}
|
|
3077
3197
|
};
|
|
3078
3198
|
calc.grad = function (funcORvectfield, vect) {
|
|
3199
|
+
vect = vect;
|
|
3079
3200
|
var h = 0.000000001;
|
|
3080
3201
|
var func = funcORvectfield;
|
|
3081
3202
|
var vectfield = funcORvectfield;
|
|
@@ -3109,6 +3230,7 @@ var Chalkboard;
|
|
|
3109
3230
|
}
|
|
3110
3231
|
};
|
|
3111
3232
|
calc.grad2 = function (funcORvectfield, vect) {
|
|
3233
|
+
vect = vect;
|
|
3112
3234
|
var h = 0.00001;
|
|
3113
3235
|
var func = funcORvectfield;
|
|
3114
3236
|
var vectfield = funcORvectfield;
|
|
@@ -3426,6 +3548,29 @@ var Chalkboard;
|
|
|
3426
3548
|
return comp.a.toString() + " - " + Math.abs(comp.b).toString() + "i";
|
|
3427
3549
|
}
|
|
3428
3550
|
};
|
|
3551
|
+
comp_2.toTypedArray = function (comp, type) {
|
|
3552
|
+
if (type === void 0) { type = "float32"; }
|
|
3553
|
+
var arr = Chalkboard.comp.toArray(comp);
|
|
3554
|
+
if (type === "int8") {
|
|
3555
|
+
return new Int8Array(arr);
|
|
3556
|
+
}
|
|
3557
|
+
else if (type === "int16") {
|
|
3558
|
+
return new Int16Array(arr);
|
|
3559
|
+
}
|
|
3560
|
+
else if (type === "int32") {
|
|
3561
|
+
return new Int32Array(arr);
|
|
3562
|
+
}
|
|
3563
|
+
else if (type === "float32") {
|
|
3564
|
+
return new Float32Array(arr);
|
|
3565
|
+
}
|
|
3566
|
+
else if (type === "float64") {
|
|
3567
|
+
return new Float64Array(arr);
|
|
3568
|
+
}
|
|
3569
|
+
else if (type === "bigint64") {
|
|
3570
|
+
return new BigInt64Array(arr.map(function (n) { return BigInt(Math.floor(n)); }));
|
|
3571
|
+
}
|
|
3572
|
+
throw new TypeError('Parameter "type" must be "int8", "int16", "int32", "float32", "float64", or "bigint64".');
|
|
3573
|
+
};
|
|
3429
3574
|
comp_2.toVector = function (comp) {
|
|
3430
3575
|
return Chalkboard.vect.init(comp.a, comp.b);
|
|
3431
3576
|
};
|
|
@@ -3438,9 +3583,6 @@ var Chalkboard;
|
|
|
3438
3583
|
throw new TypeError('Parameter "func" must be of type "ChalkboardFunction" with a type property of "comp".');
|
|
3439
3584
|
}
|
|
3440
3585
|
};
|
|
3441
|
-
comp_2.zero = function (comp) {
|
|
3442
|
-
return Chalkboard.comp.init(0, 0);
|
|
3443
|
-
};
|
|
3444
3586
|
})(comp = Chalkboard.comp || (Chalkboard.comp = {}));
|
|
3445
3587
|
})(Chalkboard || (Chalkboard = {}));
|
|
3446
3588
|
var Chalkboard;
|
|
@@ -3602,6 +3744,77 @@ var Chalkboard;
|
|
|
3602
3744
|
(function (Chalkboard) {
|
|
3603
3745
|
var matr;
|
|
3604
3746
|
(function (matr_2) {
|
|
3747
|
+
var $ = function (input) {
|
|
3748
|
+
var v = input;
|
|
3749
|
+
if (v && typeof v.x === "number" && typeof v.y === "number") {
|
|
3750
|
+
return input;
|
|
3751
|
+
}
|
|
3752
|
+
if (Array.isArray(input)) {
|
|
3753
|
+
if (input.length > 0 && Array.isArray(input[0])) {
|
|
3754
|
+
var matr_3 = input;
|
|
3755
|
+
var rows_2 = Chalkboard.matr.rows(matr_3);
|
|
3756
|
+
var cols_2 = Chalkboard.matr.cols(matr_3);
|
|
3757
|
+
if (cols_2 === 1) {
|
|
3758
|
+
if (rows_2 === 2)
|
|
3759
|
+
return Chalkboard.vect.init(matr_3[0][0], matr_3[1][0]);
|
|
3760
|
+
if (rows_2 === 3)
|
|
3761
|
+
return Chalkboard.vect.init(matr_3[0][0], matr_3[1][0], matr_3[2][0]);
|
|
3762
|
+
if (rows_2 === 4)
|
|
3763
|
+
return Chalkboard.vect.init(matr_3[0][0], matr_3[1][0], matr_3[2][0], matr_3[3][0]);
|
|
3764
|
+
}
|
|
3765
|
+
else if (rows_2 === 1) {
|
|
3766
|
+
if (cols_2 === 2)
|
|
3767
|
+
return Chalkboard.vect.init(matr_3[0][0], matr_3[0][1]);
|
|
3768
|
+
if (cols_2 === 3)
|
|
3769
|
+
return Chalkboard.vect.init(matr_3[0][0], matr_3[0][1], matr_3[0][2]);
|
|
3770
|
+
if (cols_2 === 4)
|
|
3771
|
+
return Chalkboard.vect.init(matr_3[0][0], matr_3[0][1], matr_3[0][2], matr_3[0][3]);
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
else {
|
|
3775
|
+
var arr = input;
|
|
3776
|
+
if (arr.length === 2)
|
|
3777
|
+
return Chalkboard.vect.init(arr[0], arr[1]);
|
|
3778
|
+
if (arr.length === 3)
|
|
3779
|
+
return Chalkboard.vect.init(arr[0], arr[1], arr[2]);
|
|
3780
|
+
if (arr.length === 4)
|
|
3781
|
+
return Chalkboard.vect.init(arr[0], arr[1], arr[2], arr[3]);
|
|
3782
|
+
}
|
|
3783
|
+
}
|
|
3784
|
+
if (input instanceof Float32Array || input instanceof Float64Array) {
|
|
3785
|
+
var arr = input;
|
|
3786
|
+
if (arr.length === 2)
|
|
3787
|
+
return Chalkboard.vect.init(arr[0], arr[1]);
|
|
3788
|
+
if (arr.length === 3)
|
|
3789
|
+
return Chalkboard.vect.init(arr[0], arr[1], arr[2]);
|
|
3790
|
+
if (arr.length === 4)
|
|
3791
|
+
return Chalkboard.vect.init(arr[0], arr[1], arr[2], arr[3]);
|
|
3792
|
+
}
|
|
3793
|
+
if (typeof input === "string") {
|
|
3794
|
+
try {
|
|
3795
|
+
var parsed = JSON.parse(input);
|
|
3796
|
+
if (parsed && typeof parsed === "object" && typeof parsed.x === "number" && typeof parsed.y === "number") {
|
|
3797
|
+
return Chalkboard.vect.init(parsed.x, parsed.y, parsed.z !== undefined ? parsed.z : undefined, parsed.w !== undefined ? parsed.w : undefined);
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
catch (e) {
|
|
3801
|
+
var str = input.trim();
|
|
3802
|
+
if (str.startsWith("(") && str.endsWith(")")) {
|
|
3803
|
+
var content = str.substring(1, str.length - 1);
|
|
3804
|
+
var components = content.split(",").map(function (part) { return parseFloat(part.trim()); });
|
|
3805
|
+
if (components.length >= 2 && components.every(function (p) { return !isNaN(p); })) {
|
|
3806
|
+
if (components.length === 2)
|
|
3807
|
+
return Chalkboard.vect.init(components[0], components[1]);
|
|
3808
|
+
if (components.length === 3)
|
|
3809
|
+
return Chalkboard.vect.init(components[0], components[1], components[2]);
|
|
3810
|
+
if (components.length === 4)
|
|
3811
|
+
return Chalkboard.vect.init(components[0], components[1], components[2], components[3]);
|
|
3812
|
+
}
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
throw new TypeError("Invalid ChalkboardVector input: ".concat(JSON.stringify(input)));
|
|
3817
|
+
};
|
|
3605
3818
|
matr_2.absolute = function (matr) {
|
|
3606
3819
|
if (Chalkboard.matr.isSizeOf(matr, 2)) {
|
|
3607
3820
|
return Chalkboard.matr.init([Math.abs(matr[0][0]), Math.abs(matr[0][1])], [Math.abs(matr[1][0]), Math.abs(matr[1][1])]);
|
|
@@ -4330,7 +4543,7 @@ var Chalkboard;
|
|
|
4330
4543
|
}
|
|
4331
4544
|
};
|
|
4332
4545
|
matr_2.isZero = function (matr) {
|
|
4333
|
-
return Chalkboard.matr.isEqual(matr, Chalkboard.matr.zero(matr));
|
|
4546
|
+
return Chalkboard.matr.isEqual(matr, Chalkboard.matr.zero(Chalkboard.matr.rows(matr), Chalkboard.matr.cols(matr)));
|
|
4334
4547
|
};
|
|
4335
4548
|
matr_2.Lehmer = function (size) {
|
|
4336
4549
|
if (size === 2) {
|
|
@@ -4907,6 +5120,7 @@ var Chalkboard;
|
|
|
4907
5120
|
}
|
|
4908
5121
|
};
|
|
4909
5122
|
matr_2.mulVector = function (matr, vect) {
|
|
5123
|
+
vect = $(vect);
|
|
4910
5124
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
4911
5125
|
if (Chalkboard.matr.rows(matr) === 2) {
|
|
4912
5126
|
return Chalkboard.matr.toVector(Chalkboard.matr.mul(matr, Chalkboard.vect.toMatrix(vect)), 2);
|
|
@@ -5248,8 +5462,10 @@ var Chalkboard;
|
|
|
5248
5462
|
}
|
|
5249
5463
|
return { Q: Q, R: R };
|
|
5250
5464
|
};
|
|
5251
|
-
matr_2.random = function (
|
|
5465
|
+
matr_2.random = function (rows, cols, inf, sup) {
|
|
5252
5466
|
if (cols === void 0) { cols = rows; }
|
|
5467
|
+
if (inf === void 0) { inf = 0; }
|
|
5468
|
+
if (sup === void 0) { sup = 1; }
|
|
5253
5469
|
if (rows === 2 && cols === 2) {
|
|
5254
5470
|
return Chalkboard.matr.init([Chalkboard.numb.random(inf, sup), Chalkboard.numb.random(inf, sup)], [Chalkboard.numb.random(inf, sup), Chalkboard.numb.random(inf, sup)]);
|
|
5255
5471
|
}
|
|
@@ -5352,6 +5568,7 @@ var Chalkboard;
|
|
|
5352
5568
|
});
|
|
5353
5569
|
};
|
|
5354
5570
|
matr_2.scaler = function (vect) {
|
|
5571
|
+
vect = $(vect);
|
|
5355
5572
|
if (typeof vect.x === "number" && typeof vect.y === "number" && typeof vect.z === "undefined" && typeof vect.w === "undefined") {
|
|
5356
5573
|
return Chalkboard.matr.init([vect.x, 0], [0, vect.y]);
|
|
5357
5574
|
}
|
|
@@ -5607,6 +5824,29 @@ var Chalkboard;
|
|
|
5607
5824
|
size = Array.isArray(size[0]) ? size[0] : size;
|
|
5608
5825
|
return (_a = Chalkboard.tens).resize.apply(_a, __spreadArray([matr], size, false));
|
|
5609
5826
|
};
|
|
5827
|
+
matr_2.toTypedArray = function (matr, type) {
|
|
5828
|
+
if (type === void 0) { type = "float32"; }
|
|
5829
|
+
var arr = Chalkboard.matr.toArray(matr);
|
|
5830
|
+
if (type === "int8") {
|
|
5831
|
+
return new Int8Array(arr);
|
|
5832
|
+
}
|
|
5833
|
+
else if (type === "int16") {
|
|
5834
|
+
return new Int16Array(arr);
|
|
5835
|
+
}
|
|
5836
|
+
else if (type === "int32") {
|
|
5837
|
+
return new Int32Array(arr);
|
|
5838
|
+
}
|
|
5839
|
+
else if (type === "float32") {
|
|
5840
|
+
return new Float32Array(arr);
|
|
5841
|
+
}
|
|
5842
|
+
else if (type === "float64") {
|
|
5843
|
+
return new Float64Array(arr);
|
|
5844
|
+
}
|
|
5845
|
+
else if (type === "bigint64") {
|
|
5846
|
+
return new BigInt64Array(arr.map(function (n) { return BigInt(Math.floor(n)); }));
|
|
5847
|
+
}
|
|
5848
|
+
throw new TypeError('Parameter "type" must be "int8", "int16", "int32", "float32", "float64", or "bigint64".');
|
|
5849
|
+
};
|
|
5610
5850
|
matr_2.toVector = function (matr, dimension, index, axis) {
|
|
5611
5851
|
if (index === void 0) { index = 0; }
|
|
5612
5852
|
if (axis === void 0) { axis = 0; }
|
|
@@ -5692,6 +5932,7 @@ var Chalkboard;
|
|
|
5692
5932
|
}
|
|
5693
5933
|
};
|
|
5694
5934
|
matr_2.translator = function (vect) {
|
|
5935
|
+
vect = $(vect);
|
|
5695
5936
|
if (typeof vect.x === "number" && typeof vect.y === "number" && typeof vect.z === "undefined" && typeof vect.w === "undefined") {
|
|
5696
5937
|
return Chalkboard.matr.init([1, 0, vect.x], [0, 1, vect.y], [0, 0, 1]);
|
|
5697
5938
|
}
|
|
@@ -5774,21 +6015,22 @@ var Chalkboard;
|
|
|
5774
6015
|
return result;
|
|
5775
6016
|
}
|
|
5776
6017
|
};
|
|
5777
|
-
matr_2.zero = function (
|
|
5778
|
-
if (
|
|
6018
|
+
matr_2.zero = function (rows, cols) {
|
|
6019
|
+
if (cols === void 0) { cols = rows; }
|
|
6020
|
+
if (rows === 2 && cols === 2) {
|
|
5779
6021
|
return Chalkboard.matr.init([0, 0], [0, 0]);
|
|
5780
6022
|
}
|
|
5781
|
-
else if (
|
|
6023
|
+
else if (rows === 3 && cols === 3) {
|
|
5782
6024
|
return Chalkboard.matr.init([0, 0, 0], [0, 0, 0], [0, 0, 0]);
|
|
5783
6025
|
}
|
|
5784
|
-
else if (
|
|
6026
|
+
else if (rows === 4 && cols === 4) {
|
|
5785
6027
|
return Chalkboard.matr.init([0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]);
|
|
5786
6028
|
}
|
|
5787
6029
|
else {
|
|
5788
6030
|
var result = Chalkboard.matr.init();
|
|
5789
|
-
for (var i = 0; i <
|
|
6031
|
+
for (var i = 0; i < rows; i++) {
|
|
5790
6032
|
result[i] = [];
|
|
5791
|
-
for (var j = 0; j <
|
|
6033
|
+
for (var j = 0; j < cols; j++) {
|
|
5792
6034
|
result[i][j] = 0;
|
|
5793
6035
|
}
|
|
5794
6036
|
}
|
|
@@ -5954,9 +6196,44 @@ var Chalkboard;
|
|
|
5954
6196
|
if (tolerance === void 0) { tolerance = 1e-8; }
|
|
5955
6197
|
if (!isFinite(num))
|
|
5956
6198
|
return false;
|
|
6199
|
+
var mult = num / Chalkboard.PI();
|
|
6200
|
+
if (mult !== 0 && Math.abs(Math.round(mult) - mult) < tolerance) {
|
|
6201
|
+
return false;
|
|
6202
|
+
}
|
|
6203
|
+
if (num > 0) {
|
|
6204
|
+
var ln = Math.log(num);
|
|
6205
|
+
if (ln !== 0 && Math.abs(Math.round(ln) - ln) < tolerance) {
|
|
6206
|
+
var pow = Chalkboard.E(Math.round(ln));
|
|
6207
|
+
if (Math.abs(num - pow) < tolerance) {
|
|
6208
|
+
return false;
|
|
6209
|
+
}
|
|
6210
|
+
}
|
|
6211
|
+
}
|
|
6212
|
+
for (var d = 2; d <= 6; d++) {
|
|
6213
|
+
var fract = Chalkboard.PI() / d;
|
|
6214
|
+
for (var n = 1; n <= d * 4; n++) {
|
|
6215
|
+
if (n % d !== 0) {
|
|
6216
|
+
if (Math.abs(num - n * fract) < tolerance) {
|
|
6217
|
+
return false;
|
|
6218
|
+
}
|
|
6219
|
+
}
|
|
6220
|
+
}
|
|
6221
|
+
}
|
|
6222
|
+
var knownIrrationals = [Chalkboard.E(-1), Chalkboard.E(0.5), Chalkboard.real.sqrt(Chalkboard.PI()), Chalkboard.E(), Chalkboard.PI(), Chalkboard.E(2)];
|
|
6223
|
+
for (var i = 2; i <= 100; i++) {
|
|
6224
|
+
if (Number.isInteger(Math.sqrt(i)))
|
|
6225
|
+
continue;
|
|
6226
|
+
knownIrrationals.push(Chalkboard.real.sqrt(i));
|
|
6227
|
+
}
|
|
6228
|
+
for (var _i = 0, knownIrrationals_1 = knownIrrationals; _i < knownIrrationals_1.length; _i++) {
|
|
6229
|
+
var irr = knownIrrationals_1[_i];
|
|
6230
|
+
if (Math.abs(num - irr) < tolerance) {
|
|
6231
|
+
return false;
|
|
6232
|
+
}
|
|
6233
|
+
}
|
|
5957
6234
|
try {
|
|
5958
6235
|
var _a = Chalkboard.numb.toFraction(num, tolerance), n = _a[0], d = _a[1];
|
|
5959
|
-
return Math.abs(num - n / d) < tolerance;
|
|
6236
|
+
return (Math.abs(num - n / d) < tolerance) && (Math.abs(d) <= 100000);
|
|
5960
6237
|
}
|
|
5961
6238
|
catch (_b) {
|
|
5962
6239
|
return false;
|
|
@@ -6155,771 +6432,563 @@ var Chalkboard;
|
|
|
6155
6432
|
})(Chalkboard || (Chalkboard = {}));
|
|
6156
6433
|
var Chalkboard;
|
|
6157
6434
|
(function (Chalkboard) {
|
|
6158
|
-
var
|
|
6159
|
-
(function (
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
return Chalkboard.real.
|
|
6163
|
-
}
|
|
6164
|
-
else if (func.type === "curv" && Array.isArray(func.definition)) {
|
|
6165
|
-
if (func.definition.length === 2) {
|
|
6166
|
-
return Chalkboard.real.define(["Math.abs(".concat(func.definition[0], ")"), "Math.abs(".concat(func.definition[1], ")")], "curv");
|
|
6167
|
-
}
|
|
6168
|
-
else if (func.definition.length === 3) {
|
|
6169
|
-
return Chalkboard.real.define(["Math.abs(".concat(func.definition[0], ")"), "Math.abs(".concat(func.definition[1], ")"), "Math.abs(".concat(func.definition[2], ")")], "curv");
|
|
6170
|
-
}
|
|
6435
|
+
var plot;
|
|
6436
|
+
(function (plot) {
|
|
6437
|
+
var getContext = function () {
|
|
6438
|
+
try {
|
|
6439
|
+
return Chalkboard.real.parse(Chalkboard.CONTEXT);
|
|
6171
6440
|
}
|
|
6172
|
-
|
|
6173
|
-
|
|
6441
|
+
catch (e) {
|
|
6442
|
+
throw new Error("Cannot initialize canvas context. Make sure an HTML <canvas> element exists in the webpage before using Chalkboard.plot functions.");
|
|
6174
6443
|
}
|
|
6175
|
-
throw new TypeError('Property "type" of "func" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
6176
6444
|
};
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6445
|
+
plot.autocorrelation = function (func, config) {
|
|
6446
|
+
(config = {
|
|
6447
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6448
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6449
|
+
size: config.size || 1,
|
|
6450
|
+
strokeStyle: config.strokeStyle || "black",
|
|
6451
|
+
lineWidth: config.lineWidth || 2,
|
|
6452
|
+
domain: config.domain || [-10, 10],
|
|
6453
|
+
res: config.res || 25,
|
|
6454
|
+
context: config.context || getContext()
|
|
6455
|
+
}).size /= 100;
|
|
6456
|
+
var data = [];
|
|
6457
|
+
config.context.save();
|
|
6458
|
+
config.context.translate(config.x, config.y);
|
|
6459
|
+
config.context.lineWidth = config.lineWidth;
|
|
6460
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
6461
|
+
config.context.beginPath();
|
|
6462
|
+
for (var i = config.domain[0] / config.size; i <= config.domain[1] / config.size; i += config.res) {
|
|
6463
|
+
config.context.lineTo(i, -Chalkboard.calc.autocorrelation(func, i * config.size) / config.size);
|
|
6464
|
+
data.push([i, Chalkboard.calc.autocorrelation(func, i)]);
|
|
6188
6465
|
}
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
throw new TypeError('Property "type" of "func1" and "func2" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
6466
|
+
config.context.stroke();
|
|
6467
|
+
config.context.restore();
|
|
6468
|
+
return data;
|
|
6193
6469
|
};
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
}
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6470
|
+
plot.barplot = function (arr, bins, config) {
|
|
6471
|
+
(config = {
|
|
6472
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6473
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6474
|
+
size: config.size || 1,
|
|
6475
|
+
fillStyle: config.fillStyle || "white",
|
|
6476
|
+
strokeStyle: config.strokeStyle || "black",
|
|
6477
|
+
lineWidth: config.lineWidth || 2,
|
|
6478
|
+
context: config.context || getContext()
|
|
6479
|
+
}).size /= 100;
|
|
6480
|
+
config.context.save();
|
|
6481
|
+
config.context.translate(config.x, config.y);
|
|
6482
|
+
config.context.lineWidth = config.lineWidth;
|
|
6483
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
6484
|
+
config.context.fillStyle = config.fillStyle;
|
|
6485
|
+
var bars = [];
|
|
6486
|
+
for (var i = 0; i < bins.length; i++) {
|
|
6487
|
+
if (i === 0) {
|
|
6488
|
+
bars.push(Chalkboard.stat.lt(arr, bins[0], true));
|
|
6207
6489
|
}
|
|
6208
|
-
else if (
|
|
6209
|
-
|
|
6490
|
+
else if (i === bins.length) {
|
|
6491
|
+
bars.push(Chalkboard.stat.gt(arr, bins[bins.length - 1], true));
|
|
6492
|
+
}
|
|
6493
|
+
else {
|
|
6494
|
+
bars.push(Chalkboard.stat.ineq(arr, bins[i - 1], bins[i], false, true));
|
|
6210
6495
|
}
|
|
6211
6496
|
}
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
throw new TypeError('Property "type" of "func1" and "func2" must be either "expl", "inve", "pola", "curv", or "surf".');
|
|
6216
|
-
};
|
|
6217
|
-
real.define = function (definition, type) {
|
|
6218
|
-
if (type === void 0) { type = "expl"; }
|
|
6219
|
-
if (type === "expl" || type === "inve" || type === "pola" || type === "mult") {
|
|
6220
|
-
return { definition: definition, type: type };
|
|
6221
|
-
}
|
|
6222
|
-
else if (type === "curv" && Array.isArray(definition)) {
|
|
6223
|
-
var _definition = definition.length === 2 ? [definition[0], definition[1]] : [definition[0], definition[1], definition[2]];
|
|
6224
|
-
return { definition: _definition, type: type };
|
|
6497
|
+
var counts = [];
|
|
6498
|
+
for (var i = 0; i < bars.length; i++) {
|
|
6499
|
+
counts.push(bars[i].length);
|
|
6225
6500
|
}
|
|
6226
|
-
|
|
6227
|
-
|
|
6501
|
+
var x = 0;
|
|
6502
|
+
var width = counts.length / (2 * config.size);
|
|
6503
|
+
for (var i = 0; i < counts.length; i++) {
|
|
6504
|
+
config.context.fillRect(x - width, 0, 1 / config.size, -counts[i] / config.size);
|
|
6505
|
+
config.context.strokeRect(x - width, 0, 1 / config.size, -counts[i] / config.size);
|
|
6506
|
+
x += 1 / config.size;
|
|
6228
6507
|
}
|
|
6229
|
-
|
|
6508
|
+
config.context.restore();
|
|
6509
|
+
return bars;
|
|
6230
6510
|
};
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
}
|
|
6511
|
+
plot.comp = function (comp, config) {
|
|
6512
|
+
(config = {
|
|
6513
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6514
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6515
|
+
size: config.size || 1,
|
|
6516
|
+
fillStyle: config.fillStyle || "black",
|
|
6517
|
+
lineWidth: config.lineWidth || 5,
|
|
6518
|
+
context: config.context || getContext()
|
|
6519
|
+
}).size /= 100;
|
|
6520
|
+
config.context.fillStyle = config.fillStyle;
|
|
6521
|
+
config.context.save();
|
|
6522
|
+
config.context.translate(config.x, config.y);
|
|
6523
|
+
config.context.beginPath();
|
|
6524
|
+
config.context.ellipse(comp.a / config.size, -comp.b / config.size, config.lineWidth, config.lineWidth, 0, 0, Chalkboard.PI(2));
|
|
6525
|
+
config.context.fill();
|
|
6526
|
+
config.context.restore();
|
|
6527
|
+
return [[comp.a], [comp.b]];
|
|
6240
6528
|
};
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6529
|
+
plot.convolution = function (func1, func2, config) {
|
|
6530
|
+
(config = {
|
|
6531
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6532
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6533
|
+
size: config.size || 1,
|
|
6534
|
+
strokeStyle: config.strokeStyle || "black",
|
|
6535
|
+
lineWidth: config.lineWidth || 2,
|
|
6536
|
+
domain: config.domain || [-10, 10],
|
|
6537
|
+
res: config.res || 25,
|
|
6538
|
+
context: config.context || getContext()
|
|
6539
|
+
}).size /= 100;
|
|
6540
|
+
var data = [];
|
|
6541
|
+
config.context.save();
|
|
6542
|
+
config.context.translate(config.x, config.y);
|
|
6543
|
+
config.context.lineWidth = config.lineWidth;
|
|
6544
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
6545
|
+
config.context.beginPath();
|
|
6546
|
+
for (var i = config.domain[0] / config.size; i <= config.domain[1] / config.size; i += config.res) {
|
|
6547
|
+
config.context.lineTo(i, -Chalkboard.calc.convolution(func1, func2, i * config.size) / config.size);
|
|
6548
|
+
data.push([i, Chalkboard.calc.convolution(func1, func2, i)]);
|
|
6248
6549
|
}
|
|
6249
|
-
|
|
6250
|
-
|
|
6550
|
+
config.context.stroke();
|
|
6551
|
+
config.context.restore();
|
|
6552
|
+
return data;
|
|
6553
|
+
};
|
|
6554
|
+
plot.correlation = function (func1, func2, config) {
|
|
6555
|
+
(config = {
|
|
6556
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6557
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6558
|
+
size: config.size || 1,
|
|
6559
|
+
strokeStyle: config.strokeStyle || "black",
|
|
6560
|
+
lineWidth: config.lineWidth || 2,
|
|
6561
|
+
domain: config.domain || [-10, 10],
|
|
6562
|
+
res: config.res || 25,
|
|
6563
|
+
context: config.context || getContext()
|
|
6564
|
+
}).size /= 100;
|
|
6565
|
+
var data = [];
|
|
6566
|
+
config.context.save();
|
|
6567
|
+
config.context.translate(config.x, config.y);
|
|
6568
|
+
config.context.lineWidth = config.lineWidth;
|
|
6569
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
6570
|
+
config.context.beginPath();
|
|
6571
|
+
for (var i = config.domain[0] / config.size; i <= config.domain[1] / config.size; i += config.res) {
|
|
6572
|
+
config.context.lineTo(i, -Chalkboard.calc.correlation(func1, func2, i * config.size) / config.size);
|
|
6573
|
+
data.push([i, Chalkboard.calc.correlation(func1, func2, i)]);
|
|
6251
6574
|
}
|
|
6575
|
+
config.context.stroke();
|
|
6576
|
+
config.context.restore();
|
|
6577
|
+
return data;
|
|
6252
6578
|
};
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6579
|
+
plot.definition = function (func, config) {
|
|
6580
|
+
(config = {
|
|
6581
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6582
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6583
|
+
size: config.size || 1,
|
|
6584
|
+
strokeStyle: config.strokeStyle || "black",
|
|
6585
|
+
lineWidth: config.lineWidth || 2,
|
|
6586
|
+
domain: config.domain ||
|
|
6587
|
+
(func.type === "comp"
|
|
6588
|
+
? [
|
|
6589
|
+
[-10, 10],
|
|
6590
|
+
[-10, 10]
|
|
6591
|
+
]
|
|
6592
|
+
: [-10, 10]),
|
|
6593
|
+
context: config.context || getContext()
|
|
6594
|
+
}).size /= 100;
|
|
6595
|
+
var xdomain = config.domain;
|
|
6596
|
+
var xydomain = config.domain;
|
|
6597
|
+
var data = [];
|
|
6598
|
+
config.context.save();
|
|
6599
|
+
config.context.translate(config.x, config.y);
|
|
6600
|
+
config.context.lineWidth = config.lineWidth;
|
|
6601
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
6602
|
+
config.context.beginPath();
|
|
6603
|
+
if (func.type === "expl") {
|
|
6604
|
+
var f = Chalkboard.real.parse("x => " + func.definition);
|
|
6605
|
+
for (var i = xdomain[0] / config.size; i <= xdomain[1] / config.size; i++) {
|
|
6606
|
+
config.context.lineTo(i, -f(i * config.size) / config.size);
|
|
6607
|
+
data.push([i, f(i)]);
|
|
6608
|
+
}
|
|
6256
6609
|
}
|
|
6257
|
-
else if (
|
|
6258
|
-
|
|
6259
|
-
|
|
6610
|
+
else if (func.type === "inve") {
|
|
6611
|
+
var f = Chalkboard.real.parse("y => " + func.definition);
|
|
6612
|
+
for (var i = xdomain[0] / config.size; i <= xdomain[1] / config.size; i++) {
|
|
6613
|
+
config.context.lineTo(f(i * config.size) / config.size, -i);
|
|
6614
|
+
data.push([f(i), i]);
|
|
6260
6615
|
}
|
|
6261
|
-
|
|
6262
|
-
|
|
6616
|
+
}
|
|
6617
|
+
else if (func.type === "pola") {
|
|
6618
|
+
var r = Chalkboard.real.parse("O => " + func.definition);
|
|
6619
|
+
for (var i = xdomain[0] / config.size; i <= xdomain[1] / config.size; i++) {
|
|
6620
|
+
config.context.lineTo((r(i * config.size) / config.size) * Chalkboard.trig.cos(i * config.size), (-r(i * config.size) / config.size) * Chalkboard.trig.sin(i * config.size));
|
|
6621
|
+
data.push([i, r(i)]);
|
|
6263
6622
|
}
|
|
6264
6623
|
}
|
|
6265
|
-
else if (
|
|
6266
|
-
|
|
6624
|
+
else if (func.type === "curv") {
|
|
6625
|
+
var x = Chalkboard.real.parse("t => " + func.definition[0]), y = Chalkboard.real.parse("t => " + func.definition[1]);
|
|
6626
|
+
for (var i = xdomain[0] / config.size; i <= xdomain[1] / config.size; i++) {
|
|
6627
|
+
config.context.lineTo(x(i * config.size) / config.size, -y(i * config.size) / config.size);
|
|
6628
|
+
data.push([x(i), y(i)]);
|
|
6629
|
+
}
|
|
6267
6630
|
}
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6631
|
+
else if (func.type === "comp") {
|
|
6632
|
+
var u = Chalkboard.comp.parse("(a, b) => " + func.definition[0]), v = Chalkboard.comp.parse("(a, b) => " + func.definition[1]);
|
|
6633
|
+
for (var i = xydomain[0][0] / config.size; i <= xydomain[0][1] / config.size; i += 5) {
|
|
6634
|
+
for (var j = xydomain[1][0] / config.size; j <= xydomain[1][1] / config.size; j += 5) {
|
|
6635
|
+
var z = Chalkboard.comp.init(u(i * config.size, j * config.size) / config.size, v(i * config.size, j * config.size) / config.size);
|
|
6636
|
+
if (z.a === 0 && z.b === 0) {
|
|
6637
|
+
config.context.fillStyle = "rgb(0, 0, 0)";
|
|
6638
|
+
}
|
|
6639
|
+
else if (z.a === Infinity && z.b === Infinity) {
|
|
6640
|
+
config.context.fillStyle = "rgb(255, 255, 255)";
|
|
6641
|
+
}
|
|
6642
|
+
else {
|
|
6643
|
+
config.context.fillStyle =
|
|
6644
|
+
"hsl(" + Chalkboard.trig.toDeg(Chalkboard.comp.arg(z)) + ", 100%, " + (Chalkboard.trig.tanh(Chalkboard.comp.mag(z) / Chalkboard.real.pow(10, 20)) + 0.5) * 100 + "%)";
|
|
6645
|
+
}
|
|
6646
|
+
config.context.fillRect(i, j, 5, 5);
|
|
6647
|
+
data.push([u(i, j), v(i, j)]);
|
|
6648
|
+
}
|
|
6649
|
+
}
|
|
6275
6650
|
}
|
|
6276
6651
|
else {
|
|
6277
|
-
|
|
6652
|
+
throw new TypeError('Parameter "func" must be of type "ChalkboardFunction" with a property "type" of "expl", "inve", "pola", "curv", or "comp".');
|
|
6278
6653
|
}
|
|
6654
|
+
config.context.stroke();
|
|
6655
|
+
config.context.restore();
|
|
6656
|
+
return data;
|
|
6279
6657
|
};
|
|
6280
|
-
|
|
6281
|
-
|
|
6658
|
+
plot.dfdx = function (func, config) {
|
|
6659
|
+
(config = {
|
|
6660
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6661
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6662
|
+
size: config.size || 1,
|
|
6663
|
+
strokeStyle: config.strokeStyle || "black",
|
|
6664
|
+
lineWidth: config.lineWidth || 2,
|
|
6665
|
+
domain: config.domain || [-10, 10],
|
|
6666
|
+
res: config.res || 25,
|
|
6667
|
+
context: config.context || getContext()
|
|
6668
|
+
}).size /= 100;
|
|
6669
|
+
var data = [];
|
|
6670
|
+
config.context.save();
|
|
6671
|
+
config.context.translate(config.x, config.y);
|
|
6672
|
+
config.context.lineWidth = config.lineWidth;
|
|
6673
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
6674
|
+
config.context.beginPath();
|
|
6675
|
+
for (var i = config.domain[0] / config.size; i <= config.domain[1] / config.size; i += config.res) {
|
|
6676
|
+
if (func.type === "expl") {
|
|
6677
|
+
config.context.lineTo(i, -Chalkboard.calc.dfdx(func, i * config.size) / config.size);
|
|
6678
|
+
data.push([i, Chalkboard.calc.dfdx(func, i)]);
|
|
6679
|
+
}
|
|
6680
|
+
else if (func.type === "inve") {
|
|
6681
|
+
config.context.lineTo(Chalkboard.calc.dfdx(func, i * config.size) / config.size, -i);
|
|
6682
|
+
data.push([Chalkboard.calc.dfdx(func, i), i]);
|
|
6683
|
+
}
|
|
6684
|
+
}
|
|
6685
|
+
config.context.stroke();
|
|
6686
|
+
config.context.restore();
|
|
6687
|
+
return data;
|
|
6282
6688
|
};
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6689
|
+
plot.d2fdx2 = function (func, config) {
|
|
6690
|
+
(config = {
|
|
6691
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6692
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6693
|
+
size: config.size || 1,
|
|
6694
|
+
strokeStyle: config.strokeStyle || "black",
|
|
6695
|
+
lineWidth: config.lineWidth || 2,
|
|
6696
|
+
domain: config.domain || [-10, 10],
|
|
6697
|
+
res: config.res || 25,
|
|
6698
|
+
context: config.context || getContext()
|
|
6699
|
+
}).size /= 100;
|
|
6700
|
+
var data = [];
|
|
6701
|
+
config.context.save();
|
|
6702
|
+
config.context.translate(config.x, config.y);
|
|
6703
|
+
config.context.lineWidth = config.lineWidth;
|
|
6704
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
6705
|
+
config.context.beginPath();
|
|
6706
|
+
for (var i = config.domain[0] / config.size; i <= config.domain[1] / config.size; i += config.res) {
|
|
6707
|
+
if (func.type === "expl") {
|
|
6708
|
+
config.context.lineTo(i, -Chalkboard.calc.d2fdx2(func, i * config.size) / config.size);
|
|
6709
|
+
data.push([i, Chalkboard.calc.d2fdx2(func, i)]);
|
|
6710
|
+
}
|
|
6711
|
+
else if (func.type === "inve") {
|
|
6712
|
+
config.context.lineTo(Chalkboard.calc.d2fdx2(func, i * config.size) / config.size, -i);
|
|
6713
|
+
data.push([Chalkboard.calc.d2fdx2(func, i), i]);
|
|
6714
|
+
}
|
|
6295
6715
|
}
|
|
6716
|
+
config.context.stroke();
|
|
6717
|
+
config.context.restore();
|
|
6718
|
+
return data;
|
|
6296
6719
|
};
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
|
|
6300
|
-
|
|
6301
|
-
|
|
6302
|
-
|
|
6303
|
-
|
|
6304
|
-
|
|
6720
|
+
plot.field = function (vectfield, config) {
|
|
6721
|
+
(config = {
|
|
6722
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6723
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6724
|
+
size: config.size || 1,
|
|
6725
|
+
strokeStyle: config.strokeStyle || "black",
|
|
6726
|
+
lineWidth: config.lineWidth || 2,
|
|
6727
|
+
domain: config.domain || [
|
|
6728
|
+
[-10, 10],
|
|
6729
|
+
[-10, 10]
|
|
6730
|
+
],
|
|
6731
|
+
res: config.res || 25,
|
|
6732
|
+
context: config.context || getContext()
|
|
6733
|
+
}).size /= 100;
|
|
6734
|
+
var data = [];
|
|
6735
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
6736
|
+
config.context.lineWidth = config.lineWidth;
|
|
6737
|
+
config.context.save();
|
|
6738
|
+
config.context.translate(config.x, config.y);
|
|
6739
|
+
for (var i = config.domain[0][0] / config.size; i <= config.domain[0][1] / config.size; i += config.res) {
|
|
6740
|
+
for (var j = config.domain[1][0] / config.size; j <= config.domain[1][1] / config.size; j += config.res) {
|
|
6741
|
+
var v = Chalkboard.vect.fromField(vectfield, Chalkboard.vect.init(i, j));
|
|
6742
|
+
config.context.beginPath();
|
|
6743
|
+
config.context.moveTo(i, j);
|
|
6744
|
+
config.context.lineTo(i + v.x, j + v.y);
|
|
6745
|
+
config.context.stroke();
|
|
6746
|
+
data.push([i + v.x, j + v.y]);
|
|
6747
|
+
}
|
|
6748
|
+
}
|
|
6749
|
+
config.context.restore();
|
|
6750
|
+
return data;
|
|
6305
6751
|
};
|
|
6306
|
-
|
|
6307
|
-
|
|
6308
|
-
|
|
6752
|
+
plot.Fourier = function (func, config) {
|
|
6753
|
+
(config = {
|
|
6754
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6755
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6756
|
+
size: config.size || 1,
|
|
6757
|
+
strokeStyle: config.strokeStyle || "black",
|
|
6758
|
+
lineWidth: config.lineWidth || 2,
|
|
6759
|
+
domain: config.domain || [-10, 10],
|
|
6760
|
+
res: config.res || 25,
|
|
6761
|
+
context: config.context || getContext()
|
|
6762
|
+
}).size /= 100;
|
|
6763
|
+
var data = [];
|
|
6764
|
+
config.context.save();
|
|
6765
|
+
config.context.translate(config.x, config.y);
|
|
6766
|
+
config.context.lineWidth = config.lineWidth;
|
|
6767
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
6768
|
+
config.context.beginPath();
|
|
6769
|
+
for (var i = config.domain[0] / config.size; i <= config.domain[1] / config.size; i += config.res) {
|
|
6770
|
+
config.context.lineTo(i, -Chalkboard.calc.Fourier(func, i * config.size) / config.size);
|
|
6771
|
+
data.push([i, Chalkboard.calc.Fourier(func, i)]);
|
|
6309
6772
|
}
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
6773
|
+
config.context.stroke();
|
|
6774
|
+
config.context.restore();
|
|
6775
|
+
return data;
|
|
6776
|
+
};
|
|
6777
|
+
plot.fxdx = function (func, config) {
|
|
6778
|
+
(config = {
|
|
6779
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6780
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6781
|
+
size: config.size || 1,
|
|
6782
|
+
strokeStyle: config.strokeStyle || "black",
|
|
6783
|
+
lineWidth: config.lineWidth || 2,
|
|
6784
|
+
domain: config.domain || [-10, 10],
|
|
6785
|
+
res: config.res || 25,
|
|
6786
|
+
context: config.context || getContext()
|
|
6787
|
+
}).size /= 100;
|
|
6788
|
+
var data = [];
|
|
6789
|
+
config.context.save();
|
|
6790
|
+
config.context.translate(config.x, config.y);
|
|
6791
|
+
config.context.lineWidth = config.lineWidth;
|
|
6792
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
6793
|
+
config.context.beginPath();
|
|
6794
|
+
for (var i = config.domain[0] / config.size; i <= config.domain[1] / config.size; i += config.res) {
|
|
6795
|
+
if (func.type === "expl") {
|
|
6796
|
+
config.context.lineTo(i, -Chalkboard.calc.fxdx(func, 0, i * config.size) / config.size);
|
|
6797
|
+
data.push([i, Chalkboard.calc.fxdx(func, 0, i)]);
|
|
6313
6798
|
}
|
|
6314
|
-
else if (
|
|
6315
|
-
|
|
6799
|
+
else if (func.type === "inve") {
|
|
6800
|
+
config.context.lineTo(Chalkboard.calc.fxdx(func, 0, i * config.size) / config.size, -i);
|
|
6801
|
+
data.push([Chalkboard.calc.fxdx(func, 0, i), i]);
|
|
6316
6802
|
}
|
|
6317
6803
|
}
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
throw new TypeError('Property "type" of "func1" and "func2" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
6322
|
-
};
|
|
6323
|
-
real.negate = function (func) {
|
|
6324
|
-
return Chalkboard.real.scl(func, -1);
|
|
6325
|
-
};
|
|
6326
|
-
real.parse = function (str) {
|
|
6327
|
-
return Function('"use strict"; ' + Chalkboard.PARSEPREFIX + " return (" + str + ")")();
|
|
6804
|
+
config.context.stroke();
|
|
6805
|
+
config.context.restore();
|
|
6806
|
+
return data;
|
|
6328
6807
|
};
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6808
|
+
plot.Laplace = function (func, config) {
|
|
6809
|
+
(config = {
|
|
6810
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6811
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6812
|
+
size: config.size || 1,
|
|
6813
|
+
strokeStyle: config.strokeStyle || "black",
|
|
6814
|
+
lineWidth: config.lineWidth || 2,
|
|
6815
|
+
domain: config.domain || [-10, 10],
|
|
6816
|
+
res: config.res || 25,
|
|
6817
|
+
context: config.context || getContext()
|
|
6818
|
+
}).size /= 100;
|
|
6819
|
+
var data = [];
|
|
6820
|
+
config.context.save();
|
|
6821
|
+
config.context.translate(config.x, config.y);
|
|
6822
|
+
config.context.lineWidth = config.lineWidth;
|
|
6823
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
6824
|
+
config.context.beginPath();
|
|
6825
|
+
if (config.domain[0] >= 0) {
|
|
6826
|
+
for (var i = config.domain[0] / config.size; i <= config.domain[1] / config.size; i += config.res) {
|
|
6827
|
+
config.context.lineTo(i, -Chalkboard.calc.Laplace(func, i * config.size) / config.size);
|
|
6828
|
+
data.push([i, Chalkboard.calc.Laplace(func, i)]);
|
|
6829
|
+
}
|
|
6334
6830
|
}
|
|
6335
6831
|
else {
|
|
6336
|
-
|
|
6832
|
+
for (var i = 0; i <= config.domain[1] / config.size; i += config.res) {
|
|
6833
|
+
config.context.lineTo(i, -Chalkboard.calc.Laplace(func, i * config.size) / config.size);
|
|
6834
|
+
data.push([i, Chalkboard.calc.Laplace(func, i)]);
|
|
6835
|
+
}
|
|
6337
6836
|
}
|
|
6837
|
+
config.context.stroke();
|
|
6838
|
+
config.context.restore();
|
|
6839
|
+
return data;
|
|
6338
6840
|
};
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
}
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
continue;
|
|
6357
|
-
if (result !== "") {
|
|
6358
|
-
result += coeff >= 0 ? " + " : " - ";
|
|
6359
|
-
}
|
|
6360
|
-
else if (coeff < 0) {
|
|
6361
|
-
result += "-";
|
|
6362
|
-
}
|
|
6363
|
-
var abscoeff = Math.abs(coeff);
|
|
6364
|
-
var term = "";
|
|
6365
|
-
if (exponent === 0) {
|
|
6366
|
-
term = abscoeff.toString();
|
|
6841
|
+
plot.lineplot = function (arr, bins, config) {
|
|
6842
|
+
(config = {
|
|
6843
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6844
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6845
|
+
size: config.size || 1,
|
|
6846
|
+
strokeStyle: config.strokeStyle || "black",
|
|
6847
|
+
lineWidth: config.lineWidth || 2,
|
|
6848
|
+
context: config.context || getContext()
|
|
6849
|
+
}).size /= 100;
|
|
6850
|
+
config.context.save();
|
|
6851
|
+
config.context.translate(config.x, config.y);
|
|
6852
|
+
config.context.lineWidth = config.lineWidth;
|
|
6853
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
6854
|
+
var verts = [];
|
|
6855
|
+
for (var i = 0; i < bins.length; i++) {
|
|
6856
|
+
if (i === 0) {
|
|
6857
|
+
verts.push(Chalkboard.stat.lt(arr, bins[0], true));
|
|
6367
6858
|
}
|
|
6368
|
-
else if (
|
|
6369
|
-
|
|
6859
|
+
else if (i === bins.length) {
|
|
6860
|
+
verts.push(Chalkboard.stat.gt(arr, bins[bins.length - 1], true));
|
|
6370
6861
|
}
|
|
6371
6862
|
else {
|
|
6372
|
-
|
|
6863
|
+
verts.push(Chalkboard.stat.ineq(arr, bins[i - 1], bins[i], false, true));
|
|
6373
6864
|
}
|
|
6374
|
-
result += "(" + term + ")";
|
|
6375
6865
|
}
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
};
|
|
6380
|
-
real.pow = function (base, num) {
|
|
6381
|
-
if (typeof base === "number") {
|
|
6382
|
-
if (base === 0 && num === 0) {
|
|
6383
|
-
return 1;
|
|
6384
|
-
}
|
|
6385
|
-
else {
|
|
6386
|
-
return Math.exp(num * Math.log(base));
|
|
6387
|
-
}
|
|
6866
|
+
var counts = [];
|
|
6867
|
+
for (var i = 0; i < verts.length; i++) {
|
|
6868
|
+
counts.push(verts[i].length);
|
|
6388
6869
|
}
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
return Chalkboard.real.define("(".concat(func.definition, ") ** ").concat(num), func.type);
|
|
6393
|
-
}
|
|
6394
|
-
else if (func.type === "curv" && Array.isArray(func.definition)) {
|
|
6395
|
-
if (func.definition.length === 2) {
|
|
6396
|
-
return Chalkboard.real.define(["(".concat(func.definition[0], ") ** ").concat(num), "(".concat(func.definition[1], ") ** ").concat(num)], "curv");
|
|
6397
|
-
}
|
|
6398
|
-
else if (func.definition.length === 3) {
|
|
6399
|
-
return Chalkboard.real.define(["(".concat(func.definition[0], ") ** ").concat(num), "(".concat(func.definition[1], ") ** ").concat(num), "(".concat(func.definition[2], ") ** ").concat(num)], "curv");
|
|
6400
|
-
}
|
|
6401
|
-
}
|
|
6402
|
-
else if (func.type === "surf" && Array.isArray(func.definition)) {
|
|
6403
|
-
return Chalkboard.real.define(["(".concat(func.definition[0], ") ** ").concat(num), "(".concat(func.definition[1], ") ** ").concat(num), "(".concat(func.definition[2], ") ** ").concat(num)], "surf");
|
|
6404
|
-
}
|
|
6405
|
-
throw new TypeError('Property "type" of "base" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
6870
|
+
config.context.beginPath();
|
|
6871
|
+
for (var i = 0; i < counts.length; i++) {
|
|
6872
|
+
config.context.lineTo(i / config.size, -counts[i] / config.size);
|
|
6406
6873
|
}
|
|
6874
|
+
config.context.stroke();
|
|
6875
|
+
config.context.restore();
|
|
6876
|
+
return verts;
|
|
6407
6877
|
};
|
|
6408
|
-
|
|
6409
|
-
var a = p1[1] / ((p1[0] - p2[0]) * (p1[0] - p3[0])) + p2[1] / ((p2[0] - p1[0]) * (p2[0] - p3[0])) + p3[1] / ((p3[0] - p1[0]) * (p3[0] - p2[0]));
|
|
6410
|
-
var b = (-p1[1] * (p2[0] + p3[0])) / ((p1[0] - p2[0]) * (p1[0] - p3[0])) -
|
|
6411
|
-
(p2[1] * (p1[0] + p3[0])) / ((p2[0] - p1[0]) * (p2[0] - p3[0])) -
|
|
6412
|
-
(p3[1] * (p1[0] + p2[0])) / ((p3[0] - p1[0]) * (p3[0] - p2[0]));
|
|
6413
|
-
var c = (p1[1] * p2[0] * p3[0]) / ((p1[0] - p2[0]) * (p1[0] - p3[0])) +
|
|
6414
|
-
(p2[1] * p1[0] * p3[0]) / ((p2[0] - p1[0]) * (p2[0] - p3[0])) +
|
|
6415
|
-
(p3[1] * p1[0] * p2[0]) / ((p3[0] - p1[0]) * (p3[0] - p2[0]));
|
|
6416
|
-
return a * t * t + b * t + c;
|
|
6417
|
-
};
|
|
6418
|
-
real.quadratic = function (a, b, c, form) {
|
|
6419
|
-
if (form === void 0) { form = "stan"; }
|
|
6420
|
-
if (form === "stan") {
|
|
6421
|
-
return Chalkboard.real.define(a.toString() + "* x * x + " + b.toString() + " * x +" + c.toString());
|
|
6422
|
-
}
|
|
6423
|
-
else if (form === "vert") {
|
|
6424
|
-
return Chalkboard.real.define(a.toString() + " * ((x - " + b.toString() + ") * (x - " + b.toString() + ")) +" + c.toString());
|
|
6425
|
-
}
|
|
6426
|
-
else {
|
|
6427
|
-
throw new TypeError('Parameter "form" must be "stan" or "vert".');
|
|
6428
|
-
}
|
|
6429
|
-
};
|
|
6430
|
-
real.quadraticFormula = function (a, b, c, form) {
|
|
6431
|
-
if (form === void 0) { form = "stan"; }
|
|
6432
|
-
if (form === "stan") {
|
|
6433
|
-
return [(-b + Chalkboard.real.sqrt(Chalkboard.real.discriminant(a, b, c, "stan"))) / (2 * a), (-b - Math.sqrt(Chalkboard.real.discriminant(a, b, c, "stan"))) / (2 * a)];
|
|
6434
|
-
}
|
|
6435
|
-
else if (form === "vert") {
|
|
6436
|
-
return [b + Chalkboard.real.sqrt(-c / a), b - Chalkboard.real.sqrt(-c / a)];
|
|
6437
|
-
}
|
|
6438
|
-
else {
|
|
6439
|
-
throw new TypeError('Parameter "form" must be "stan" or "vert".');
|
|
6440
|
-
}
|
|
6441
|
-
};
|
|
6442
|
-
real.ramp = function (num, edge, scl) {
|
|
6443
|
-
if (edge === void 0) { edge = 0; }
|
|
6444
|
-
if (scl === void 0) { scl = 1; }
|
|
6445
|
-
if (num >= edge) {
|
|
6446
|
-
return num * scl;
|
|
6447
|
-
}
|
|
6448
|
-
else {
|
|
6449
|
-
return 0;
|
|
6450
|
-
}
|
|
6451
|
-
};
|
|
6452
|
-
real.randomPolynomial = function (degree, inf, sup) {
|
|
6453
|
-
var _a;
|
|
6454
|
-
if (inf === void 0) { inf = 0; }
|
|
6455
|
-
if (sup === void 0) { sup = 1; }
|
|
6456
|
-
return (_a = Chalkboard.real).polynomial.apply(_a, Chalkboard.stat.random(degree + 1, inf, sup));
|
|
6457
|
-
};
|
|
6458
|
-
real.reciprocate = function (func) {
|
|
6459
|
-
if (func.type === "expl" || func.type === "inve" || func.type === "pola" || func.type === "mult") {
|
|
6460
|
-
return Chalkboard.real.define("1 / (".concat(func.definition, ")"), func.type);
|
|
6461
|
-
}
|
|
6462
|
-
else if (func.type === "curv" && Array.isArray(func.definition)) {
|
|
6463
|
-
if (func.definition.length === 2) {
|
|
6464
|
-
return Chalkboard.real.define(["1 / (".concat(func.definition[0], ")"), "1 / (".concat(func.definition[1], ")")], "curv");
|
|
6465
|
-
}
|
|
6466
|
-
else if (func.definition.length === 3) {
|
|
6467
|
-
return Chalkboard.real.define(["1 / (".concat(func.definition[0], ")"), "1 / (".concat(func.definition[1], ")"), "1 / (".concat(func.definition[2], ")")], "curv");
|
|
6468
|
-
}
|
|
6469
|
-
}
|
|
6470
|
-
else if (func.type === "surf" && Array.isArray(func.definition)) {
|
|
6471
|
-
return Chalkboard.real.define(["1 / (".concat(func.definition[0], ")"), "1 / (".concat(func.definition[1], ")"), "1 / (".concat(func.definition[2], ")")], "surf");
|
|
6472
|
-
}
|
|
6473
|
-
throw new TypeError('Property "type" of "func" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
6474
|
-
};
|
|
6475
|
-
real.rect = function (num, center, width, scl) {
|
|
6476
|
-
if (center === void 0) { center = 0; }
|
|
6477
|
-
if (width === void 0) { width = 2; }
|
|
6478
|
-
if (scl === void 0) { scl = 1; }
|
|
6479
|
-
if (num > center + width / 2 || num < center - width / 2) {
|
|
6480
|
-
return 0;
|
|
6481
|
-
}
|
|
6482
|
-
else {
|
|
6483
|
-
return scl;
|
|
6484
|
-
}
|
|
6485
|
-
};
|
|
6486
|
-
real.root = function (num, index) {
|
|
6487
|
-
if (index === void 0) { index = 3; }
|
|
6488
|
-
return Math.exp(Math.log(num) / index);
|
|
6489
|
-
};
|
|
6490
|
-
real.scl = function (func, num) {
|
|
6491
|
-
if (func.type === "expl" || func.type === "inve" || func.type === "pola" || func.type === "mult") {
|
|
6492
|
-
return Chalkboard.real.define("".concat(num, " * (").concat(func.definition, ")"), func.type);
|
|
6493
|
-
}
|
|
6494
|
-
else if (func.type === "curv" && Array.isArray(func.definition)) {
|
|
6495
|
-
if (func.definition.length === 2) {
|
|
6496
|
-
return Chalkboard.real.define(["".concat(num, " * (").concat(func.definition[0], ")"), "".concat(num, " * (").concat(func.definition[1], ")")], "curv");
|
|
6497
|
-
}
|
|
6498
|
-
else if (func.definition.length === 3) {
|
|
6499
|
-
return Chalkboard.real.define(["".concat(num, " * (").concat(func.definition[0], ")"), "".concat(num, " * (").concat(func.definition[1], ")"), "".concat(num, " * (").concat(func.definition[2], ")")], "curv");
|
|
6500
|
-
}
|
|
6501
|
-
}
|
|
6502
|
-
else if (func.type === "surf" && Array.isArray(func.definition)) {
|
|
6503
|
-
return Chalkboard.real.define(["".concat(num, " * (").concat(func.definition[0], ")"), "".concat(num, " * (").concat(func.definition[1], ")"), "".concat(num, " * (").concat(func.definition[2], ")")], "surf");
|
|
6504
|
-
}
|
|
6505
|
-
throw new TypeError('Property "type" of "func" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
6506
|
-
};
|
|
6507
|
-
real.slope = function (x1, y1, x2, y2) {
|
|
6508
|
-
return (y2 - y1) / (x2 - x1);
|
|
6509
|
-
};
|
|
6510
|
-
real.sqrt = function (num) {
|
|
6511
|
-
if (num >= 0) {
|
|
6512
|
-
return Math.exp(Math.log(num) / 2);
|
|
6513
|
-
}
|
|
6514
|
-
else {
|
|
6515
|
-
return NaN;
|
|
6516
|
-
}
|
|
6517
|
-
};
|
|
6518
|
-
real.sub = function (func1, func2) {
|
|
6519
|
-
if ((func1.type === "expl" && func2.type === "expl") || (func1.type === "inve" && func2.type === "inve") || (func1.type === "pola" && func2.type === "pola") || (func1.type === "mult" && func2.type === "mult")) {
|
|
6520
|
-
return Chalkboard.real.define("(".concat(func1.definition, ") - (").concat(func2.definition, ")"), func1.type);
|
|
6521
|
-
}
|
|
6522
|
-
else if (func1.type === "curv" && func2.type === "curv" && Array.isArray(func1.definition) && Array.isArray(func2.definition)) {
|
|
6523
|
-
if (func1.definition.length === 2 && func2.definition.length === 2) {
|
|
6524
|
-
return Chalkboard.real.define(["(".concat(func1.definition[0], ") - (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") - (").concat(func2.definition[1], ")")], "curv");
|
|
6525
|
-
}
|
|
6526
|
-
else if (func1.definition.length === 3 && func2.definition.length === 3) {
|
|
6527
|
-
return Chalkboard.real.define(["(".concat(func1.definition[0], ") - (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") - (").concat(func2.definition[1], ")"), "(".concat(func1.definition[2], ") - (").concat(func2.definition[2], ")")], "curv");
|
|
6528
|
-
}
|
|
6529
|
-
}
|
|
6530
|
-
else if (func1.type === "surf" && func2.type === "surf" && Array.isArray(func1.definition) && Array.isArray(func2.definition)) {
|
|
6531
|
-
return Chalkboard.real.define(["(".concat(func1.definition[0], ") - (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") - (").concat(func2.definition[1], ")"), "(".concat(func1.definition[2], ") - (").concat(func2.definition[2], ")")], "surf");
|
|
6532
|
-
}
|
|
6533
|
-
throw new TypeError('Property "type" of "func1" and "func2" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
6534
|
-
};
|
|
6535
|
-
real.tetration = function (base, num) {
|
|
6536
|
-
if (num === 0) {
|
|
6537
|
-
return 1;
|
|
6538
|
-
}
|
|
6539
|
-
else if (num > 0) {
|
|
6540
|
-
return Math.pow(base, Chalkboard.real.tetration(base, num - 1));
|
|
6541
|
-
}
|
|
6542
|
-
};
|
|
6543
|
-
real.translate = function (func, h, v) {
|
|
6544
|
-
if (h === void 0) { h = 0; }
|
|
6545
|
-
if (v === void 0) { v = 0; }
|
|
6546
|
-
if (func.type === "expl") {
|
|
6547
|
-
if (h !== 0 && v !== 0) {
|
|
6548
|
-
return Chalkboard.real.define("(".concat(func.definition.toString().replace(/x/g, "(x - ".concat(h, ")")), ") + ").concat(v), "expl");
|
|
6549
|
-
}
|
|
6550
|
-
else if (h !== 0) {
|
|
6551
|
-
return Chalkboard.real.define("".concat(func.definition.toString().replace(/x/g, "(x - ".concat(h, ")"))), "expl");
|
|
6552
|
-
}
|
|
6553
|
-
else if (v !== 0) {
|
|
6554
|
-
return Chalkboard.real.define("(".concat(func.definition, ") + ").concat(v), "expl");
|
|
6555
|
-
}
|
|
6556
|
-
else {
|
|
6557
|
-
return func;
|
|
6558
|
-
}
|
|
6559
|
-
}
|
|
6560
|
-
throw new TypeError('Property "type" of "func" must be "expl".');
|
|
6561
|
-
};
|
|
6562
|
-
real.val = function (func, val) {
|
|
6563
|
-
if (func.type === "expl") {
|
|
6564
|
-
var f = Chalkboard.real.parse("x => " + func.definition);
|
|
6565
|
-
return f(val);
|
|
6566
|
-
}
|
|
6567
|
-
else if (func.type === "inve") {
|
|
6568
|
-
var f = Chalkboard.real.parse("y => " + func.definition);
|
|
6569
|
-
return f(val);
|
|
6570
|
-
}
|
|
6571
|
-
else if (func.type === "pola") {
|
|
6572
|
-
var r = Chalkboard.real.parse("O => " + func.definition);
|
|
6573
|
-
return r(val);
|
|
6574
|
-
}
|
|
6575
|
-
else if (func.type === "curv") {
|
|
6576
|
-
if (func.definition.length === 2) {
|
|
6577
|
-
var x = Chalkboard.real.parse("t => " + func.definition[0]), y = Chalkboard.real.parse("t => " + func.definition[1]);
|
|
6578
|
-
return Chalkboard.vect.init(x(val), y(val));
|
|
6579
|
-
}
|
|
6580
|
-
else {
|
|
6581
|
-
var x = Chalkboard.real.parse("t => " + func.definition[0]), y = Chalkboard.real.parse("t => " + func.definition[1]), z = Chalkboard.real.parse("t => " + func.definition[2]);
|
|
6582
|
-
return Chalkboard.vect.init(x(val), y(val), z(val));
|
|
6583
|
-
}
|
|
6584
|
-
}
|
|
6585
|
-
else if (func.type === "surf") {
|
|
6586
|
-
var vect_2 = val;
|
|
6587
|
-
var x = Chalkboard.real.parse("(s, t) => " + func.definition[0]), y = Chalkboard.real.parse("(s, t) => " + func.definition[1]), z = Chalkboard.real.parse("(s, t) => " + func.definition[2]);
|
|
6588
|
-
return Chalkboard.vect.init(x(vect_2.x, vect_2.y), y(vect_2.x, vect_2.y), z(vect_2.x, vect_2.y));
|
|
6589
|
-
}
|
|
6590
|
-
else if (func.type === "mult" && typeof val !== "number") {
|
|
6591
|
-
var vect_3 = val;
|
|
6592
|
-
var f = Chalkboard.real.parse("(x, y) => " + func.definition);
|
|
6593
|
-
return f(vect_3.x, vect_3.y);
|
|
6594
|
-
}
|
|
6595
|
-
else {
|
|
6596
|
-
throw new TypeError('Parameter "func" must be of type "ChalkboardFunction" with a "type" property of "expl", "pola", "curv", "surf", or "mult".');
|
|
6597
|
-
}
|
|
6598
|
-
};
|
|
6599
|
-
})(real = Chalkboard.real || (Chalkboard.real = {}));
|
|
6600
|
-
})(Chalkboard || (Chalkboard = {}));
|
|
6601
|
-
var Chalkboard;
|
|
6602
|
-
(function (Chalkboard) {
|
|
6603
|
-
var plot;
|
|
6604
|
-
(function (plot) {
|
|
6605
|
-
var PARSED_CONTEXT = Chalkboard.real.parse(Chalkboard.CONTEXT);
|
|
6606
|
-
plot.autocorrelation = function (func, config) {
|
|
6607
|
-
(config = {
|
|
6608
|
-
x: (config = config || {}).x || PARSED_CONTEXT.canvas.width / 2,
|
|
6609
|
-
y: config.y || PARSED_CONTEXT.canvas.height / 2,
|
|
6610
|
-
size: config.size || 1,
|
|
6611
|
-
strokeStyle: config.strokeStyle || "black",
|
|
6612
|
-
lineWidth: config.lineWidth || 2,
|
|
6613
|
-
domain: config.domain || [-10, 10],
|
|
6614
|
-
res: config.res || 25,
|
|
6615
|
-
context: config.context || PARSED_CONTEXT
|
|
6616
|
-
}).size /= 100;
|
|
6617
|
-
var data = [];
|
|
6618
|
-
config.context.save();
|
|
6619
|
-
config.context.translate(config.x, config.y);
|
|
6620
|
-
config.context.lineWidth = config.lineWidth;
|
|
6621
|
-
config.context.strokeStyle = config.strokeStyle;
|
|
6622
|
-
config.context.beginPath();
|
|
6623
|
-
for (var i = config.domain[0] / config.size; i <= config.domain[1] / config.size; i += config.res) {
|
|
6624
|
-
config.context.lineTo(i, -Chalkboard.calc.autocorrelation(func, i * config.size) / config.size);
|
|
6625
|
-
data.push([i, Chalkboard.calc.autocorrelation(func, i)]);
|
|
6626
|
-
}
|
|
6627
|
-
config.context.stroke();
|
|
6628
|
-
config.context.restore();
|
|
6629
|
-
return data;
|
|
6630
|
-
};
|
|
6631
|
-
plot.barplot = function (arr, bins, config) {
|
|
6632
|
-
(config = {
|
|
6633
|
-
x: (config = config || {}).x || PARSED_CONTEXT.canvas.width / 2,
|
|
6634
|
-
y: config.y || PARSED_CONTEXT.canvas.height / 2,
|
|
6635
|
-
size: config.size || 1,
|
|
6636
|
-
fillStyle: config.fillStyle || "white",
|
|
6637
|
-
strokeStyle: config.strokeStyle || "black",
|
|
6638
|
-
lineWidth: config.lineWidth || 2,
|
|
6639
|
-
context: config.context || PARSED_CONTEXT
|
|
6640
|
-
}).size /= 100;
|
|
6641
|
-
config.context.save();
|
|
6642
|
-
config.context.translate(config.x, config.y);
|
|
6643
|
-
config.context.lineWidth = config.lineWidth;
|
|
6644
|
-
config.context.strokeStyle = config.strokeStyle;
|
|
6645
|
-
config.context.fillStyle = config.fillStyle;
|
|
6646
|
-
var bars = [];
|
|
6647
|
-
for (var i = 0; i < bins.length; i++) {
|
|
6648
|
-
if (i === 0) {
|
|
6649
|
-
bars.push(Chalkboard.stat.lt(arr, bins[0], true));
|
|
6650
|
-
}
|
|
6651
|
-
else if (i === bins.length) {
|
|
6652
|
-
bars.push(Chalkboard.stat.gt(arr, bins[bins.length - 1], true));
|
|
6653
|
-
}
|
|
6654
|
-
else {
|
|
6655
|
-
bars.push(Chalkboard.stat.ineq(arr, bins[i - 1], bins[i], false, true));
|
|
6656
|
-
}
|
|
6657
|
-
}
|
|
6658
|
-
var counts = [];
|
|
6659
|
-
for (var i = 0; i < bars.length; i++) {
|
|
6660
|
-
counts.push(bars[i].length);
|
|
6661
|
-
}
|
|
6662
|
-
var x = 0;
|
|
6663
|
-
var width = counts.length / (2 * config.size);
|
|
6664
|
-
for (var i = 0; i < counts.length; i++) {
|
|
6665
|
-
config.context.fillRect(x - width, 0, 1 / config.size, -counts[i] / config.size);
|
|
6666
|
-
config.context.strokeRect(x - width, 0, 1 / config.size, -counts[i] / config.size);
|
|
6667
|
-
x += 1 / config.size;
|
|
6668
|
-
}
|
|
6669
|
-
config.context.restore();
|
|
6670
|
-
return bars;
|
|
6671
|
-
};
|
|
6672
|
-
plot.comp = function (comp, config) {
|
|
6673
|
-
(config = {
|
|
6674
|
-
x: (config = config || {}).x || PARSED_CONTEXT.canvas.width / 2,
|
|
6675
|
-
y: config.y || PARSED_CONTEXT.canvas.height / 2,
|
|
6676
|
-
size: config.size || 1,
|
|
6677
|
-
fillStyle: config.fillStyle || "black",
|
|
6678
|
-
lineWidth: config.lineWidth || 5,
|
|
6679
|
-
context: config.context || PARSED_CONTEXT
|
|
6680
|
-
}).size /= 100;
|
|
6681
|
-
config.context.fillStyle = config.fillStyle;
|
|
6682
|
-
config.context.save();
|
|
6683
|
-
config.context.translate(config.x, config.y);
|
|
6684
|
-
config.context.beginPath();
|
|
6685
|
-
config.context.ellipse(comp.a / config.size, -comp.b / config.size, config.lineWidth, config.lineWidth, 0, 0, Chalkboard.PI(2));
|
|
6686
|
-
config.context.fill();
|
|
6687
|
-
config.context.restore();
|
|
6688
|
-
return [[comp.a], [comp.b]];
|
|
6689
|
-
};
|
|
6690
|
-
plot.convolution = function (func1, func2, config) {
|
|
6691
|
-
(config = {
|
|
6692
|
-
x: (config = config || {}).x || PARSED_CONTEXT.canvas.width / 2,
|
|
6693
|
-
y: config.y || PARSED_CONTEXT.canvas.height / 2,
|
|
6694
|
-
size: config.size || 1,
|
|
6695
|
-
strokeStyle: config.strokeStyle || "black",
|
|
6696
|
-
lineWidth: config.lineWidth || 2,
|
|
6697
|
-
domain: config.domain || [-10, 10],
|
|
6698
|
-
res: config.res || 25,
|
|
6699
|
-
context: config.context || PARSED_CONTEXT
|
|
6700
|
-
}).size /= 100;
|
|
6701
|
-
var data = [];
|
|
6702
|
-
config.context.save();
|
|
6703
|
-
config.context.translate(config.x, config.y);
|
|
6704
|
-
config.context.lineWidth = config.lineWidth;
|
|
6705
|
-
config.context.strokeStyle = config.strokeStyle;
|
|
6706
|
-
config.context.beginPath();
|
|
6707
|
-
for (var i = config.domain[0] / config.size; i <= config.domain[1] / config.size; i += config.res) {
|
|
6708
|
-
config.context.lineTo(i, -Chalkboard.calc.convolution(func1, func2, i * config.size) / config.size);
|
|
6709
|
-
data.push([i, Chalkboard.calc.convolution(func1, func2, i)]);
|
|
6710
|
-
}
|
|
6711
|
-
config.context.stroke();
|
|
6712
|
-
config.context.restore();
|
|
6713
|
-
return data;
|
|
6714
|
-
};
|
|
6715
|
-
plot.correlation = function (func1, func2, config) {
|
|
6878
|
+
plot.matr = function (matr, config) {
|
|
6716
6879
|
(config = {
|
|
6717
|
-
x: (config = config || {}).x ||
|
|
6718
|
-
y: config.y ||
|
|
6880
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6881
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6719
6882
|
size: config.size || 1,
|
|
6720
6883
|
strokeStyle: config.strokeStyle || "black",
|
|
6721
6884
|
lineWidth: config.lineWidth || 2,
|
|
6722
6885
|
domain: config.domain || [-10, 10],
|
|
6723
|
-
|
|
6724
|
-
context: config.context || PARSED_CONTEXT
|
|
6886
|
+
context: config.context || getContext()
|
|
6725
6887
|
}).size /= 100;
|
|
6726
|
-
var
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6888
|
+
for (var i = config.domain[0]; i <= config.domain[1]; i++) {
|
|
6889
|
+
Chalkboard.plot.vect(Chalkboard.vect.init(matr[0][0], matr[1][0]), {
|
|
6890
|
+
x: config.x,
|
|
6891
|
+
y: config.y + (i / config.size) * matr[1][1],
|
|
6892
|
+
size: config.size,
|
|
6893
|
+
strokeStyle: config.strokeStyle,
|
|
6894
|
+
lineWidth: config.lineWidth / 4,
|
|
6895
|
+
context: config.context
|
|
6896
|
+
});
|
|
6897
|
+
Chalkboard.plot.vect(Chalkboard.vect.init(-matr[0][0], -matr[1][0]), {
|
|
6898
|
+
x: config.x,
|
|
6899
|
+
y: config.y + (i / config.size) * matr[1][1],
|
|
6900
|
+
size: config.size,
|
|
6901
|
+
strokeStyle: config.strokeStyle,
|
|
6902
|
+
lineWidth: config.lineWidth / 4,
|
|
6903
|
+
context: config.context
|
|
6904
|
+
});
|
|
6905
|
+
Chalkboard.plot.vect(Chalkboard.vect.init(matr[0][1], matr[1][1]), {
|
|
6906
|
+
x: config.x + (i / config.size) * matr[0][0],
|
|
6907
|
+
y: config.y,
|
|
6908
|
+
size: config.size,
|
|
6909
|
+
strokeStyle: config.strokeStyle,
|
|
6910
|
+
lineWidth: config.lineWidth / 4,
|
|
6911
|
+
context: config.context
|
|
6912
|
+
});
|
|
6913
|
+
Chalkboard.plot.vect(Chalkboard.vect.init(-matr[0][1], -matr[1][1]), {
|
|
6914
|
+
x: config.x + (i / config.size) * matr[0][0],
|
|
6915
|
+
y: config.y,
|
|
6916
|
+
size: config.size,
|
|
6917
|
+
strokeStyle: config.strokeStyle,
|
|
6918
|
+
lineWidth: config.lineWidth / 4,
|
|
6919
|
+
context: config.context
|
|
6920
|
+
});
|
|
6735
6921
|
}
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
6922
|
+
Chalkboard.plot.vect(Chalkboard.vect.init(matr[0][0], matr[1][0]), config);
|
|
6923
|
+
Chalkboard.plot.vect(Chalkboard.vect.init(-matr[0][0], -matr[1][0]), config);
|
|
6924
|
+
Chalkboard.plot.vect(Chalkboard.vect.init(matr[0][1], matr[1][1]), config);
|
|
6925
|
+
Chalkboard.plot.vect(Chalkboard.vect.init(-matr[0][1], -matr[1][1]), config);
|
|
6926
|
+
return matr;
|
|
6739
6927
|
};
|
|
6740
|
-
plot.
|
|
6928
|
+
plot.rOplane = function (config) {
|
|
6741
6929
|
(config = {
|
|
6742
|
-
x: (config = config || {}).x ||
|
|
6743
|
-
y: config.y ||
|
|
6930
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6931
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6744
6932
|
size: config.size || 1,
|
|
6745
6933
|
strokeStyle: config.strokeStyle || "black",
|
|
6746
6934
|
lineWidth: config.lineWidth || 2,
|
|
6747
|
-
|
|
6748
|
-
(func.type === "comp"
|
|
6749
|
-
? [
|
|
6750
|
-
[-10, 10],
|
|
6751
|
-
[-10, 10]
|
|
6752
|
-
]
|
|
6753
|
-
: [-10, 10]),
|
|
6754
|
-
context: config.context || PARSED_CONTEXT
|
|
6935
|
+
context: config.context || getContext()
|
|
6755
6936
|
}).size /= 100;
|
|
6756
|
-
var
|
|
6757
|
-
var xydomain = config.domain;
|
|
6758
|
-
var data = [];
|
|
6937
|
+
var cw = getContext().canvas.width;
|
|
6759
6938
|
config.context.save();
|
|
6760
6939
|
config.context.translate(config.x, config.y);
|
|
6761
|
-
config.context.lineWidth = config.lineWidth;
|
|
6762
6940
|
config.context.strokeStyle = config.strokeStyle;
|
|
6941
|
+
config.context.lineWidth = config.lineWidth / 4;
|
|
6763
6942
|
config.context.beginPath();
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
for (var i = xdomain[0] / config.size; i <= xdomain[1] / config.size; i++) {
|
|
6767
|
-
config.context.lineTo(i, -f(i * config.size) / config.size);
|
|
6768
|
-
data.push([i, f(i)]);
|
|
6769
|
-
}
|
|
6770
|
-
}
|
|
6771
|
-
else if (func.type === "inve") {
|
|
6772
|
-
var f = Chalkboard.real.parse("y => " + func.definition);
|
|
6773
|
-
for (var i = xdomain[0] / config.size; i <= xdomain[1] / config.size; i++) {
|
|
6774
|
-
config.context.lineTo(f(i * config.size) / config.size, -i);
|
|
6775
|
-
data.push([f(i), i]);
|
|
6776
|
-
}
|
|
6777
|
-
}
|
|
6778
|
-
else if (func.type === "pola") {
|
|
6779
|
-
var r = Chalkboard.real.parse("O => " + func.definition);
|
|
6780
|
-
for (var i = xdomain[0] / config.size; i <= xdomain[1] / config.size; i++) {
|
|
6781
|
-
config.context.lineTo((r(i * config.size) / config.size) * Chalkboard.trig.cos(i * config.size), (-r(i * config.size) / config.size) * Chalkboard.trig.sin(i * config.size));
|
|
6782
|
-
data.push([i, r(i)]);
|
|
6783
|
-
}
|
|
6784
|
-
}
|
|
6785
|
-
else if (func.type === "curv") {
|
|
6786
|
-
var x = Chalkboard.real.parse("t => " + func.definition[0]), y = Chalkboard.real.parse("t => " + func.definition[1]);
|
|
6787
|
-
for (var i = xdomain[0] / config.size; i <= xdomain[1] / config.size; i++) {
|
|
6788
|
-
config.context.lineTo(x(i * config.size) / config.size, -y(i * config.size) / config.size);
|
|
6789
|
-
data.push([x(i), y(i)]);
|
|
6790
|
-
}
|
|
6791
|
-
}
|
|
6792
|
-
else if (func.type === "comp") {
|
|
6793
|
-
var u = Chalkboard.comp.parse("(a, b) => " + func.definition[0]), v = Chalkboard.comp.parse("(a, b) => " + func.definition[1]);
|
|
6794
|
-
for (var i = xydomain[0][0] / config.size; i <= xydomain[0][1] / config.size; i += 5) {
|
|
6795
|
-
for (var j = xydomain[1][0] / config.size; j <= xydomain[1][1] / config.size; j += 5) {
|
|
6796
|
-
var z = Chalkboard.comp.init(u(i * config.size, j * config.size) / config.size, v(i * config.size, j * config.size) / config.size);
|
|
6797
|
-
if (z.a === 0 && z.b === 0) {
|
|
6798
|
-
config.context.fillStyle = "rgb(0, 0, 0)";
|
|
6799
|
-
}
|
|
6800
|
-
else if (z.a === Infinity && z.b === Infinity) {
|
|
6801
|
-
config.context.fillStyle = "rgb(255, 255, 255)";
|
|
6802
|
-
}
|
|
6803
|
-
else {
|
|
6804
|
-
config.context.fillStyle =
|
|
6805
|
-
"hsl(" + Chalkboard.trig.toDeg(Chalkboard.comp.arg(z)) + ", 100%, " + (Chalkboard.trig.tanh(Chalkboard.comp.mag(z) / Chalkboard.real.pow(10, 20)) + 0.5) * 100 + "%)";
|
|
6806
|
-
}
|
|
6807
|
-
config.context.fillRect(i, j, 5, 5);
|
|
6808
|
-
data.push([u(i, j), v(i, j)]);
|
|
6809
|
-
}
|
|
6810
|
-
}
|
|
6811
|
-
}
|
|
6812
|
-
else {
|
|
6813
|
-
throw new TypeError('Parameter "func" must be of type "ChalkboardFunction" with a property "type" of "expl", "inve", "pola", "curv", or "comp".');
|
|
6943
|
+
for (var i = 0; i <= (config.size * cw) / 2; i++) {
|
|
6944
|
+
config.context.ellipse(0, 0, i / config.size, i / config.size, 0, 0, Chalkboard.PI(2));
|
|
6814
6945
|
}
|
|
6815
6946
|
config.context.stroke();
|
|
6816
|
-
config.context.restore();
|
|
6817
|
-
return data;
|
|
6818
|
-
};
|
|
6819
|
-
plot.dfdx = function (func, config) {
|
|
6820
|
-
(config = {
|
|
6821
|
-
x: (config = config || {}).x || PARSED_CONTEXT.canvas.width / 2,
|
|
6822
|
-
y: config.y || PARSED_CONTEXT.canvas.height / 2,
|
|
6823
|
-
size: config.size || 1,
|
|
6824
|
-
strokeStyle: config.strokeStyle || "black",
|
|
6825
|
-
lineWidth: config.lineWidth || 2,
|
|
6826
|
-
domain: config.domain || [-10, 10],
|
|
6827
|
-
res: config.res || 25,
|
|
6828
|
-
context: config.context || PARSED_CONTEXT
|
|
6829
|
-
}).size /= 100;
|
|
6830
|
-
var data = [];
|
|
6831
|
-
config.context.save();
|
|
6832
|
-
config.context.translate(config.x, config.y);
|
|
6833
6947
|
config.context.lineWidth = config.lineWidth;
|
|
6834
|
-
config.context.strokeStyle = config.strokeStyle;
|
|
6835
6948
|
config.context.beginPath();
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
config.context.lineTo(i, -Chalkboard.calc.dfdx(func, i * config.size) / config.size);
|
|
6839
|
-
data.push([i, Chalkboard.calc.dfdx(func, i)]);
|
|
6840
|
-
}
|
|
6841
|
-
else if (func.type === "inve") {
|
|
6842
|
-
config.context.lineTo(Chalkboard.calc.dfdx(func, i * config.size) / config.size, -i);
|
|
6843
|
-
data.push([Chalkboard.calc.dfdx(func, i), i]);
|
|
6844
|
-
}
|
|
6845
|
-
}
|
|
6949
|
+
config.context.moveTo(-config.x, 0);
|
|
6950
|
+
config.context.lineTo(cw - config.x, 0);
|
|
6846
6951
|
config.context.stroke();
|
|
6847
|
-
config.context.restore();
|
|
6848
|
-
return data;
|
|
6849
|
-
};
|
|
6850
|
-
plot.d2fdx2 = function (func, config) {
|
|
6851
|
-
(config = {
|
|
6852
|
-
x: (config = config || {}).x || PARSED_CONTEXT.canvas.width / 2,
|
|
6853
|
-
y: config.y || PARSED_CONTEXT.canvas.height / 2,
|
|
6854
|
-
size: config.size || 1,
|
|
6855
|
-
strokeStyle: config.strokeStyle || "black",
|
|
6856
|
-
lineWidth: config.lineWidth || 2,
|
|
6857
|
-
domain: config.domain || [-10, 10],
|
|
6858
|
-
res: config.res || 25,
|
|
6859
|
-
context: config.context || PARSED_CONTEXT
|
|
6860
|
-
}).size /= 100;
|
|
6861
|
-
var data = [];
|
|
6862
|
-
config.context.save();
|
|
6863
|
-
config.context.translate(config.x, config.y);
|
|
6864
|
-
config.context.lineWidth = config.lineWidth;
|
|
6865
|
-
config.context.strokeStyle = config.strokeStyle;
|
|
6866
6952
|
config.context.beginPath();
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
config.context.lineTo(i, -Chalkboard.calc.d2fdx2(func, i * config.size) / config.size);
|
|
6870
|
-
data.push([i, Chalkboard.calc.d2fdx2(func, i)]);
|
|
6871
|
-
}
|
|
6872
|
-
else if (func.type === "inve") {
|
|
6873
|
-
config.context.lineTo(Chalkboard.calc.d2fdx2(func, i * config.size) / config.size, -i);
|
|
6874
|
-
data.push([Chalkboard.calc.d2fdx2(func, i), i]);
|
|
6875
|
-
}
|
|
6876
|
-
}
|
|
6953
|
+
config.context.moveTo(0, -config.y);
|
|
6954
|
+
config.context.lineTo(0, cw - config.y);
|
|
6877
6955
|
config.context.stroke();
|
|
6878
6956
|
config.context.restore();
|
|
6879
|
-
return data;
|
|
6880
6957
|
};
|
|
6881
|
-
plot.
|
|
6958
|
+
plot.scatterplot = function (arr1, arr2, config) {
|
|
6882
6959
|
(config = {
|
|
6883
|
-
x: (config = config || {}).x ||
|
|
6884
|
-
y: config.y ||
|
|
6960
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6961
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6885
6962
|
size: config.size || 1,
|
|
6886
|
-
|
|
6887
|
-
lineWidth: config.lineWidth ||
|
|
6888
|
-
|
|
6889
|
-
[-10, 10],
|
|
6890
|
-
[-10, 10]
|
|
6891
|
-
],
|
|
6892
|
-
res: config.res || 25,
|
|
6893
|
-
context: config.context || PARSED_CONTEXT
|
|
6963
|
+
fillStyle: config.fillStyle || "black",
|
|
6964
|
+
lineWidth: config.lineWidth || 5,
|
|
6965
|
+
context: config.context || getContext()
|
|
6894
6966
|
}).size /= 100;
|
|
6895
6967
|
var data = [];
|
|
6896
|
-
config.context.strokeStyle = config.strokeStyle;
|
|
6897
|
-
config.context.lineWidth = config.lineWidth;
|
|
6898
6968
|
config.context.save();
|
|
6899
6969
|
config.context.translate(config.x, config.y);
|
|
6900
|
-
|
|
6901
|
-
|
|
6902
|
-
|
|
6970
|
+
config.context.fillStyle = config.fillStyle;
|
|
6971
|
+
if (arr1.length === arr2.length) {
|
|
6972
|
+
for (var i = 0; i < arr1.length; i++) {
|
|
6903
6973
|
config.context.beginPath();
|
|
6904
|
-
config.context.
|
|
6905
|
-
config.context.
|
|
6906
|
-
|
|
6907
|
-
data.push([i + v.x, j + v.y]);
|
|
6974
|
+
config.context.ellipse(arr1[i] / config.size - arr1.length / (2 * config.size), -arr2[i] / config.size + arr1.length / (2 * config.size), config.lineWidth, config.lineWidth, 0, 0, Chalkboard.PI(2));
|
|
6975
|
+
config.context.fill();
|
|
6976
|
+
data.push([arr1[i], arr2[i]]);
|
|
6908
6977
|
}
|
|
6909
6978
|
}
|
|
6910
6979
|
config.context.restore();
|
|
6911
6980
|
return data;
|
|
6912
6981
|
};
|
|
6913
|
-
plot.
|
|
6982
|
+
plot.Taylor = function (func, n, a, config) {
|
|
6914
6983
|
(config = {
|
|
6915
|
-
x: (config = config || {}).x ||
|
|
6916
|
-
y: config.y ||
|
|
6984
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
6985
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6917
6986
|
size: config.size || 1,
|
|
6918
6987
|
strokeStyle: config.strokeStyle || "black",
|
|
6919
6988
|
lineWidth: config.lineWidth || 2,
|
|
6920
6989
|
domain: config.domain || [-10, 10],
|
|
6921
6990
|
res: config.res || 25,
|
|
6922
|
-
context: config.context ||
|
|
6991
|
+
context: config.context || getContext()
|
|
6923
6992
|
}).size /= 100;
|
|
6924
6993
|
var data = [];
|
|
6925
6994
|
config.context.save();
|
|
@@ -6928,453 +6997,703 @@ var Chalkboard;
|
|
|
6928
6997
|
config.context.strokeStyle = config.strokeStyle;
|
|
6929
6998
|
config.context.beginPath();
|
|
6930
6999
|
for (var i = config.domain[0] / config.size; i <= config.domain[1] / config.size; i += config.res) {
|
|
6931
|
-
config.context.lineTo(i, -Chalkboard.calc.
|
|
6932
|
-
data.push([i, Chalkboard.calc.
|
|
7000
|
+
config.context.lineTo(i, -Chalkboard.calc.Taylor(func, i * config.size, n, a) / config.size);
|
|
7001
|
+
data.push([i, Chalkboard.calc.Taylor(func, i, n, a)]);
|
|
6933
7002
|
}
|
|
6934
7003
|
config.context.stroke();
|
|
6935
7004
|
config.context.restore();
|
|
6936
7005
|
return data;
|
|
6937
7006
|
};
|
|
6938
|
-
plot.
|
|
7007
|
+
plot.vect = function (vect, config) {
|
|
6939
7008
|
(config = {
|
|
6940
|
-
x: (config = config || {}).x ||
|
|
6941
|
-
y: config.y ||
|
|
7009
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
7010
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6942
7011
|
size: config.size || 1,
|
|
6943
7012
|
strokeStyle: config.strokeStyle || "black",
|
|
6944
|
-
lineWidth: config.lineWidth ||
|
|
6945
|
-
|
|
6946
|
-
res: config.res || 25,
|
|
6947
|
-
context: config.context || PARSED_CONTEXT
|
|
7013
|
+
lineWidth: config.lineWidth || 5,
|
|
7014
|
+
context: config.context || getContext()
|
|
6948
7015
|
}).size /= 100;
|
|
6949
|
-
|
|
7016
|
+
vect = vect;
|
|
7017
|
+
config.context.strokeStyle = config.strokeStyle;
|
|
7018
|
+
config.context.lineWidth = config.lineWidth;
|
|
6950
7019
|
config.context.save();
|
|
6951
7020
|
config.context.translate(config.x, config.y);
|
|
6952
|
-
config.context.lineWidth = config.lineWidth;
|
|
6953
|
-
config.context.strokeStyle = config.strokeStyle;
|
|
6954
7021
|
config.context.beginPath();
|
|
6955
|
-
|
|
6956
|
-
|
|
6957
|
-
config.context.lineTo(i, -Chalkboard.calc.fxdx(func, 0, i * config.size) / config.size);
|
|
6958
|
-
data.push([i, Chalkboard.calc.fxdx(func, 0, i)]);
|
|
6959
|
-
}
|
|
6960
|
-
else if (func.type === "inve") {
|
|
6961
|
-
config.context.lineTo(Chalkboard.calc.fxdx(func, 0, i * config.size) / config.size, -i);
|
|
6962
|
-
data.push([Chalkboard.calc.fxdx(func, 0, i), i]);
|
|
6963
|
-
}
|
|
6964
|
-
}
|
|
7022
|
+
config.context.moveTo(0, 0);
|
|
7023
|
+
config.context.lineTo(vect.x / config.size, -vect.y / config.size);
|
|
6965
7024
|
config.context.stroke();
|
|
6966
7025
|
config.context.restore();
|
|
6967
|
-
return
|
|
7026
|
+
return [[vect.x], [vect.y]];
|
|
6968
7027
|
};
|
|
6969
|
-
plot.
|
|
7028
|
+
plot.xyplane = function (config) {
|
|
6970
7029
|
(config = {
|
|
6971
|
-
x: (config = config || {}).x ||
|
|
6972
|
-
y: config.y ||
|
|
7030
|
+
x: (config = config || {}).x || getContext().canvas.width / 2,
|
|
7031
|
+
y: config.y || getContext().canvas.height / 2,
|
|
6973
7032
|
size: config.size || 1,
|
|
6974
7033
|
strokeStyle: config.strokeStyle || "black",
|
|
6975
7034
|
lineWidth: config.lineWidth || 2,
|
|
6976
|
-
|
|
6977
|
-
res: config.res || 25,
|
|
6978
|
-
context: config.context || PARSED_CONTEXT
|
|
7035
|
+
context: config.context || getContext()
|
|
6979
7036
|
}).size /= 100;
|
|
6980
|
-
var
|
|
7037
|
+
var cw = getContext().canvas.width;
|
|
6981
7038
|
config.context.save();
|
|
6982
7039
|
config.context.translate(config.x, config.y);
|
|
6983
|
-
config.context.lineWidth = config.lineWidth;
|
|
6984
7040
|
config.context.strokeStyle = config.strokeStyle;
|
|
7041
|
+
config.context.lineWidth = config.lineWidth / 4;
|
|
6985
7042
|
config.context.beginPath();
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
|
|
6989
|
-
|
|
7043
|
+
for (var i = Math.floor(-config.x / config.size); i <= (cw - config.x) / config.size; i++) {
|
|
7044
|
+
config.context.moveTo(i / config.size, -config.y);
|
|
7045
|
+
config.context.lineTo(i / config.size, cw - config.y);
|
|
7046
|
+
}
|
|
7047
|
+
config.context.stroke();
|
|
7048
|
+
config.context.beginPath();
|
|
7049
|
+
for (var i = Math.floor(-config.y / config.size); i <= (cw - config.y) / config.size; i++) {
|
|
7050
|
+
config.context.moveTo(-config.x, i / config.size);
|
|
7051
|
+
config.context.lineTo(cw - config.x, i / config.size);
|
|
7052
|
+
}
|
|
7053
|
+
config.context.stroke();
|
|
7054
|
+
config.context.lineWidth = config.lineWidth;
|
|
7055
|
+
config.context.beginPath();
|
|
7056
|
+
config.context.moveTo(-config.x, 0);
|
|
7057
|
+
config.context.lineTo(cw - config.x, 0);
|
|
7058
|
+
config.context.stroke();
|
|
7059
|
+
config.context.beginPath();
|
|
7060
|
+
config.context.moveTo(0, -config.y);
|
|
7061
|
+
config.context.lineTo(0, cw - config.y);
|
|
7062
|
+
config.context.stroke();
|
|
7063
|
+
config.context.restore();
|
|
7064
|
+
};
|
|
7065
|
+
})(plot = Chalkboard.plot || (Chalkboard.plot = {}));
|
|
7066
|
+
})(Chalkboard || (Chalkboard = {}));
|
|
7067
|
+
var Chalkboard;
|
|
7068
|
+
(function (Chalkboard) {
|
|
7069
|
+
var quat;
|
|
7070
|
+
(function (quat_2) {
|
|
7071
|
+
quat_2.absolute = function (quat) {
|
|
7072
|
+
return Chalkboard.quat.init(Math.abs(quat.a), Math.abs(quat.b), Math.abs(quat.c), Math.abs(quat.d));
|
|
7073
|
+
};
|
|
7074
|
+
quat_2.add = function (quat1, quat2) {
|
|
7075
|
+
if (typeof quat1 === "number")
|
|
7076
|
+
quat1 = Chalkboard.quat.init(quat1, 0, 0, 0);
|
|
7077
|
+
if (typeof quat2 === "number")
|
|
7078
|
+
quat2 = Chalkboard.quat.init(quat2, 0, 0, 0);
|
|
7079
|
+
return Chalkboard.quat.init(quat1.a + quat2.a, quat1.b + quat2.b, quat1.c + quat2.c, quat1.d + quat2.d);
|
|
7080
|
+
};
|
|
7081
|
+
quat_2.conjugate = function (quat) {
|
|
7082
|
+
return Chalkboard.quat.init(quat.a, -quat.b, -quat.c, -quat.d);
|
|
7083
|
+
};
|
|
7084
|
+
quat_2.constrain = function (quat, range) {
|
|
7085
|
+
if (range === void 0) { range = [0, 1]; }
|
|
7086
|
+
return Chalkboard.quat.init(Chalkboard.numb.constrain(quat.a, range), Chalkboard.numb.constrain(quat.b, range), Chalkboard.numb.constrain(quat.c, range), Chalkboard.numb.constrain(quat.d, range));
|
|
7087
|
+
};
|
|
7088
|
+
quat_2.copy = function (quat) {
|
|
7089
|
+
return Object.create(Object.getPrototypeOf(quat), Object.getOwnPropertyDescriptors(quat));
|
|
7090
|
+
};
|
|
7091
|
+
quat_2.dist = function (quat1, quat2) {
|
|
7092
|
+
if (typeof quat1 === "number")
|
|
7093
|
+
quat1 = Chalkboard.quat.init(quat1, 0, 0, 0);
|
|
7094
|
+
if (typeof quat2 === "number")
|
|
7095
|
+
quat2 = Chalkboard.quat.init(quat2, 0, 0, 0);
|
|
7096
|
+
return Chalkboard.real.sqrt((quat2.a - quat1.a) * (quat2.a - quat1.a) + (quat2.b - quat1.b) * (quat2.b - quat1.b) + (quat2.c - quat1.c) * (quat2.c - quat1.c) + (quat2.d - quat1.d) * (quat2.d - quat1.d));
|
|
7097
|
+
};
|
|
7098
|
+
quat_2.distsq = function (quat1, quat2) {
|
|
7099
|
+
if (typeof quat1 === "number")
|
|
7100
|
+
quat1 = Chalkboard.quat.init(quat1, 0, 0, 0);
|
|
7101
|
+
if (typeof quat2 === "number")
|
|
7102
|
+
quat2 = Chalkboard.quat.init(quat2, 0, 0, 0);
|
|
7103
|
+
return (quat2.a - quat1.a) * (quat2.a - quat1.a) + (quat2.b - quat1.b) * (quat2.b - quat1.b) + (quat2.c - quat1.c) * (quat2.c - quat1.c) + (quat2.d - quat1.d) * (quat2.d - quat1.d);
|
|
7104
|
+
};
|
|
7105
|
+
quat_2.div = function (quat1, quat2) {
|
|
7106
|
+
if (typeof quat1 === "number")
|
|
7107
|
+
quat1 = Chalkboard.quat.init(quat1, 0, 0, 0);
|
|
7108
|
+
if (typeof quat2 === "number")
|
|
7109
|
+
quat2 = Chalkboard.quat.init(quat2, 0, 0, 0);
|
|
7110
|
+
return Chalkboard.quat.init((quat1.a * quat2.a + quat1.b * quat2.b + quat1.c * quat2.c + quat1.d * quat2.d) / Chalkboard.quat.magsq(quat2), (quat1.b * quat2.a - quat1.a * quat2.b - quat1.d * quat2.c + quat1.c * quat2.d) / Chalkboard.quat.magsq(quat2), (quat1.c * quat2.a + quat1.d * quat2.b - quat1.a * quat2.c - quat1.b * quat2.d) / Chalkboard.quat.magsq(quat2), (quat1.d * quat2.a - quat1.c * quat2.b + quat1.b * quat2.c - quat1.a * quat2.d) / Chalkboard.quat.magsq(quat2));
|
|
7111
|
+
};
|
|
7112
|
+
quat_2.fromAxis = function (vect, rad) {
|
|
7113
|
+
vect = vect;
|
|
7114
|
+
if (typeof vect.z !== "undefined") {
|
|
7115
|
+
return Chalkboard.quat.init(Chalkboard.trig.cos(rad / 2), vect.x * Chalkboard.trig.sin(rad / 2), vect.y * Chalkboard.trig.sin(rad / 2), vect.z * Chalkboard.trig.sin(rad / 2));
|
|
7116
|
+
}
|
|
7117
|
+
else {
|
|
7118
|
+
throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 3 dimensions.');
|
|
7119
|
+
}
|
|
7120
|
+
};
|
|
7121
|
+
quat_2.init = function (a, b, c, d) {
|
|
7122
|
+
if (b === void 0) { b = 0; }
|
|
7123
|
+
if (c === void 0) { c = 0; }
|
|
7124
|
+
if (d === void 0) { d = 0; }
|
|
7125
|
+
return { a: a, b: b, c: c, d: d };
|
|
7126
|
+
};
|
|
7127
|
+
quat_2.invert = function (quat) {
|
|
7128
|
+
return Chalkboard.quat.init(quat.a / Chalkboard.quat.magsq(quat), -quat.b / Chalkboard.quat.magsq(quat), -quat.c / Chalkboard.quat.magsq(quat), -quat.d / Chalkboard.quat.magsq(quat));
|
|
7129
|
+
};
|
|
7130
|
+
quat_2.mag = function (quat) {
|
|
7131
|
+
return Chalkboard.real.sqrt(quat.a * quat.a + quat.b * quat.b + quat.c * quat.c + quat.d * quat.d);
|
|
7132
|
+
};
|
|
7133
|
+
quat_2.magset = function (quat, num) {
|
|
7134
|
+
return Chalkboard.quat.scl(Chalkboard.quat.normalize(quat), num);
|
|
7135
|
+
};
|
|
7136
|
+
quat_2.magsq = function (quat) {
|
|
7137
|
+
return quat.a * quat.a + quat.b * quat.b + quat.c * quat.c + quat.d * quat.d;
|
|
7138
|
+
};
|
|
7139
|
+
quat_2.mul = function (quat1, quat2) {
|
|
7140
|
+
if (typeof quat1 === "number")
|
|
7141
|
+
quat1 = Chalkboard.quat.init(quat1, 0, 0, 0);
|
|
7142
|
+
if (typeof quat2 === "number")
|
|
7143
|
+
quat2 = Chalkboard.quat.init(quat2, 0, 0, 0);
|
|
7144
|
+
return Chalkboard.quat.init(quat1.a * quat2.a - quat1.b * quat2.b - quat1.c * quat2.c - quat1.d * quat2.d, quat1.a * quat2.b + quat1.b * quat2.a + quat1.c * quat2.d - quat1.d * quat2.c, quat1.a * quat2.c - quat1.b * quat2.d + quat1.c * quat2.a + quat1.d * quat2.b, quat1.a * quat2.d + quat1.b * quat2.c - quat1.c * quat2.b + quat1.d * quat2.a);
|
|
7145
|
+
};
|
|
7146
|
+
quat_2.negate = function (quat) {
|
|
7147
|
+
return Chalkboard.quat.init(-quat.a, -quat.b, -quat.c, -quat.d);
|
|
7148
|
+
};
|
|
7149
|
+
quat_2.normalize = function (quat) {
|
|
7150
|
+
return Chalkboard.quat.init(quat.a / Chalkboard.quat.mag(quat), quat.b / Chalkboard.quat.mag(quat), quat.c / Chalkboard.quat.mag(quat), quat.d / Chalkboard.quat.mag(quat));
|
|
7151
|
+
};
|
|
7152
|
+
quat_2.print = function (quat) {
|
|
7153
|
+
console.log(Chalkboard.quat.toString(quat));
|
|
7154
|
+
};
|
|
7155
|
+
quat_2.random = function (inf, sup) {
|
|
7156
|
+
if (inf === void 0) { inf = 0; }
|
|
7157
|
+
if (sup === void 0) { sup = 1; }
|
|
7158
|
+
return Chalkboard.quat.init(Chalkboard.numb.random(inf, sup), Chalkboard.numb.random(inf, sup), Chalkboard.numb.random(inf, sup), Chalkboard.numb.random(inf, sup));
|
|
7159
|
+
};
|
|
7160
|
+
quat_2.reciprocate = function (quat) {
|
|
7161
|
+
return Chalkboard.quat.init(1 / quat.a, 1 / quat.b, 1 / quat.c, 1 / quat.d);
|
|
7162
|
+
};
|
|
7163
|
+
quat_2.round = function (quat) {
|
|
7164
|
+
return Chalkboard.quat.init(Math.round(quat.a), Math.round(quat.b), Math.round(quat.c), Math.round(quat.d));
|
|
7165
|
+
};
|
|
7166
|
+
quat_2.scl = function (quat, num) {
|
|
7167
|
+
return Chalkboard.quat.init(quat.a * num, quat.b * num, quat.c * num, quat.d * num);
|
|
7168
|
+
};
|
|
7169
|
+
quat_2.sub = function (quat1, quat2) {
|
|
7170
|
+
if (typeof quat1 === "number")
|
|
7171
|
+
quat1 = Chalkboard.quat.init(quat1, 0, 0, 0);
|
|
7172
|
+
if (typeof quat2 === "number")
|
|
7173
|
+
quat2 = Chalkboard.quat.init(quat2, 0, 0, 0);
|
|
7174
|
+
return Chalkboard.quat.init(quat1.a - quat2.a, quat1.b - quat2.b, quat1.c - quat2.c, quat1.d - quat2.d);
|
|
7175
|
+
};
|
|
7176
|
+
quat_2.toArray = function (quat) {
|
|
7177
|
+
return [quat.a, quat.b, quat.c, quat.d];
|
|
7178
|
+
};
|
|
7179
|
+
quat_2.toMatrix = function (quat) {
|
|
7180
|
+
return Chalkboard.matr.init([quat.a, -quat.b, -quat.c, -quat.d], [quat.b, quat.a, -quat.d, quat.c], [quat.c, quat.d, quat.a, -quat.b], [quat.d, -quat.c, quat.b, quat.a]);
|
|
7181
|
+
};
|
|
7182
|
+
quat_2.toRotation = function (quat, vect) {
|
|
7183
|
+
var vector = Chalkboard.vect.toQuaternion(vect);
|
|
7184
|
+
var inverse = Chalkboard.quat.invert(quat);
|
|
7185
|
+
var quat_vector_inverse = Chalkboard.quat.mul(quat, Chalkboard.quat.mul(vector, inverse));
|
|
7186
|
+
return Chalkboard.vect.init(quat_vector_inverse.b, quat_vector_inverse.c, quat_vector_inverse.d);
|
|
7187
|
+
};
|
|
7188
|
+
quat_2.toString = function (quat) {
|
|
7189
|
+
var quat_b = "";
|
|
7190
|
+
var quat_c = "";
|
|
7191
|
+
var quat_d = "";
|
|
7192
|
+
if (quat.b >= 0) {
|
|
7193
|
+
quat_b = " + " + quat.b.toString() + "i ";
|
|
7194
|
+
}
|
|
7195
|
+
else if (quat.b < 0) {
|
|
7196
|
+
quat_b = " - " + Math.abs(quat.b).toString() + "i ";
|
|
7197
|
+
}
|
|
7198
|
+
if (quat.c >= 0) {
|
|
7199
|
+
quat_c = "+ " + quat.c.toString() + "j ";
|
|
7200
|
+
}
|
|
7201
|
+
else if (quat.c < 0) {
|
|
7202
|
+
quat_c = "- " + Math.abs(quat.c).toString() + "j ";
|
|
7203
|
+
}
|
|
7204
|
+
if (quat.d >= 0) {
|
|
7205
|
+
quat_d = "+ " + quat.d.toString() + "k ";
|
|
7206
|
+
}
|
|
7207
|
+
else if (quat.d < 0) {
|
|
7208
|
+
quat_d = "- " + Math.abs(quat.d).toString() + "k ";
|
|
7209
|
+
}
|
|
7210
|
+
return quat.a.toString() + quat_b + quat_c + quat_d;
|
|
7211
|
+
};
|
|
7212
|
+
quat_2.toTypedArray = function (quat, type) {
|
|
7213
|
+
if (type === void 0) { type = "float32"; }
|
|
7214
|
+
var arr = Chalkboard.quat.toArray(quat);
|
|
7215
|
+
if (type === "int8") {
|
|
7216
|
+
return new Int8Array(arr);
|
|
7217
|
+
}
|
|
7218
|
+
else if (type === "int16") {
|
|
7219
|
+
return new Int16Array(arr);
|
|
7220
|
+
}
|
|
7221
|
+
else if (type === "int32") {
|
|
7222
|
+
return new Int32Array(arr);
|
|
7223
|
+
}
|
|
7224
|
+
else if (type === "float32") {
|
|
7225
|
+
return new Float32Array(arr);
|
|
7226
|
+
}
|
|
7227
|
+
else if (type === "float64") {
|
|
7228
|
+
return new Float64Array(arr);
|
|
7229
|
+
}
|
|
7230
|
+
else if (type === "bigint64") {
|
|
7231
|
+
return new BigInt64Array(arr.map(function (n) { return BigInt(Math.floor(n)); }));
|
|
7232
|
+
}
|
|
7233
|
+
throw new TypeError('Parameter "type" must be "int8", "int16", "int32", "float32", "float64", or "bigint64".');
|
|
7234
|
+
};
|
|
7235
|
+
quat_2.toVector = function (quat) {
|
|
7236
|
+
return Chalkboard.vect.init(quat.a, quat.b, quat.c, quat.d);
|
|
7237
|
+
};
|
|
7238
|
+
})(quat = Chalkboard.quat || (Chalkboard.quat = {}));
|
|
7239
|
+
})(Chalkboard || (Chalkboard = {}));
|
|
7240
|
+
var Chalkboard;
|
|
7241
|
+
(function (Chalkboard) {
|
|
7242
|
+
var real;
|
|
7243
|
+
(function (real) {
|
|
7244
|
+
real.absolute = function (func) {
|
|
7245
|
+
if (func.type === "expl" || func.type === "inve" || func.type === "pola" || func.type === "mult") {
|
|
7246
|
+
return Chalkboard.real.define("Math.abs(".concat(func.definition, ")"), func.type);
|
|
7247
|
+
}
|
|
7248
|
+
else if (func.type === "curv" && Array.isArray(func.definition)) {
|
|
7249
|
+
if (func.definition.length === 2) {
|
|
7250
|
+
return Chalkboard.real.define(["Math.abs(".concat(func.definition[0], ")"), "Math.abs(".concat(func.definition[1], ")")], "curv");
|
|
7251
|
+
}
|
|
7252
|
+
else if (func.definition.length === 3) {
|
|
7253
|
+
return Chalkboard.real.define(["Math.abs(".concat(func.definition[0], ")"), "Math.abs(".concat(func.definition[1], ")"), "Math.abs(".concat(func.definition[2], ")")], "curv");
|
|
7254
|
+
}
|
|
7255
|
+
}
|
|
7256
|
+
else if (func.type === "surf" && Array.isArray(func.definition)) {
|
|
7257
|
+
return Chalkboard.real.define(["Math.abs(".concat(func.definition[0], ")"), "Math.abs(".concat(func.definition[1], ")"), "Math.abs(".concat(func.definition[2], ")")], "surf");
|
|
7258
|
+
}
|
|
7259
|
+
throw new TypeError('Property "type" of "func" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
7260
|
+
};
|
|
7261
|
+
real.add = function (func1, func2) {
|
|
7262
|
+
if ((func1.type === "expl" && func2.type === "expl") || (func1.type === "inve" && func2.type === "inve") || (func1.type === "pola" && func2.type === "pola") || (func1.type === "mult" && func2.type === "mult")) {
|
|
7263
|
+
return Chalkboard.real.define("(".concat(func1.definition, ") + (").concat(func2.definition, ")"), func1.type);
|
|
7264
|
+
}
|
|
7265
|
+
else if (func1.type === "curv" && func2.type === "curv" && Array.isArray(func1.definition) && Array.isArray(func2.definition)) {
|
|
7266
|
+
if (func1.definition.length === 2 && func2.definition.length === 2) {
|
|
7267
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0], ") + (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") + (").concat(func2.definition[1], ")")], "curv");
|
|
6990
7268
|
}
|
|
6991
|
-
|
|
6992
|
-
|
|
6993
|
-
for (var i = 0; i <= config.domain[1] / config.size; i += config.res) {
|
|
6994
|
-
config.context.lineTo(i, -Chalkboard.calc.Laplace(func, i * config.size) / config.size);
|
|
6995
|
-
data.push([i, Chalkboard.calc.Laplace(func, i)]);
|
|
7269
|
+
else if (func1.definition.length === 3 && func2.definition.length === 3) {
|
|
7270
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0], ") + (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") + (").concat(func2.definition[1], ")"), "(".concat(func1.definition[2], ") + (").concat(func2.definition[2], ")")], "curv");
|
|
6996
7271
|
}
|
|
6997
7272
|
}
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7273
|
+
else if (func1.type === "surf" && func2.type === "surf" && Array.isArray(func1.definition) && Array.isArray(func2.definition)) {
|
|
7274
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0], ") + (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") + (").concat(func2.definition[1], ")"), "(".concat(func1.definition[2], ") + (").concat(func2.definition[2], ")")], "surf");
|
|
7275
|
+
}
|
|
7276
|
+
throw new TypeError('Property "type" of "func1" and "func2" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
7001
7277
|
};
|
|
7002
|
-
|
|
7003
|
-
(
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
var verts = [];
|
|
7016
|
-
for (var i = 0; i < bins.length; i++) {
|
|
7017
|
-
if (i === 0) {
|
|
7018
|
-
verts.push(Chalkboard.stat.lt(arr, bins[0], true));
|
|
7019
|
-
}
|
|
7020
|
-
else if (i === bins.length) {
|
|
7021
|
-
verts.push(Chalkboard.stat.gt(arr, bins[bins.length - 1], true));
|
|
7278
|
+
real.compose = function (func1, func2) {
|
|
7279
|
+
if (func1.type === "expl" && func2.type === "expl") {
|
|
7280
|
+
return Chalkboard.real.define("(".concat(func1.definition.toString().replace(/x/g, "(".concat(func2.definition, ")")), ")"), "expl");
|
|
7281
|
+
}
|
|
7282
|
+
else if (func1.type === "inve" && func2.type === "inve") {
|
|
7283
|
+
return Chalkboard.real.define("(".concat(func1.definition.toString().replace(/y/g, "(".concat(func2.definition, ")")), ")"), "inve");
|
|
7284
|
+
}
|
|
7285
|
+
else if (func1.type === "pola" && func2.type === "pola") {
|
|
7286
|
+
return Chalkboard.real.define("(".concat(func1.definition.toString().replace(/O/g, "(".concat(func2.definition, ")")), ")"), "pola");
|
|
7287
|
+
}
|
|
7288
|
+
else if (func1.type === "curv" && func2.type === "curv" && Array.isArray(func1.definition) && Array.isArray(func2.definition)) {
|
|
7289
|
+
if (func1.definition.length === 2 && func2.definition.length === 2) {
|
|
7290
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0].toString().replace(/x/g, "(".concat(func2.definition[0], ")")), ")"), "(".concat(func1.definition[1].toString().replace(/y/g, "(".concat(func2.definition[1], ")")), ")")], "curv");
|
|
7022
7291
|
}
|
|
7023
|
-
else {
|
|
7024
|
-
|
|
7292
|
+
else if (func1.definition.length === 3 && func2.definition.length === 3) {
|
|
7293
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0].toString().replace(/x/g, "(".concat(func2.definition[0], ")")), ")"), "(".concat(func1.definition[1].toString().replace(/y/g, "(".concat(func2.definition[1], ")")), ")"), "(".concat(func1.definition[2].toString().replace(/z/g, "(".concat(func2.definition[2], ")")), ")")], "curv");
|
|
7025
7294
|
}
|
|
7026
7295
|
}
|
|
7027
|
-
|
|
7028
|
-
|
|
7029
|
-
counts.push(verts[i].length);
|
|
7296
|
+
else if (func1.type === "surf" && func2.type === "surf" && Array.isArray(func1.definition) && Array.isArray(func2.definition)) {
|
|
7297
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0].toString().replace(/x/g, "(".concat(func2.definition[0], ")")), ")"), "(".concat(func1.definition[1].toString().replace(/y/g, "(".concat(func2.definition[1], ")")), ")"), "(".concat(func1.definition[2].toString().replace(/z/g, "(".concat(func2.definition[2], ")")), ")")], "surf");
|
|
7030
7298
|
}
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7299
|
+
throw new TypeError('Property "type" of "func1" and "func2" must be either "expl", "inve", "pola", "curv", or "surf".');
|
|
7300
|
+
};
|
|
7301
|
+
real.define = function (definition, type) {
|
|
7302
|
+
if (type === void 0) { type = "expl"; }
|
|
7303
|
+
if (type === "expl" || type === "inve" || type === "pola" || type === "mult") {
|
|
7304
|
+
return { definition: definition, type: type };
|
|
7034
7305
|
}
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
|
|
7306
|
+
else if (type === "curv" && Array.isArray(definition)) {
|
|
7307
|
+
var _definition = definition.length === 2 ? [definition[0], definition[1]] : [definition[0], definition[1], definition[2]];
|
|
7308
|
+
return { definition: _definition, type: type };
|
|
7309
|
+
}
|
|
7310
|
+
else if (type === "surf" && Array.isArray(definition)) {
|
|
7311
|
+
return { definition: [definition[0], definition[1], definition[2]], type: type };
|
|
7312
|
+
}
|
|
7313
|
+
throw new TypeError('Parameter "type" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
7038
7314
|
};
|
|
7039
|
-
|
|
7040
|
-
(
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
|
|
7044
|
-
|
|
7045
|
-
|
|
7046
|
-
|
|
7047
|
-
context: config.context || PARSED_CONTEXT
|
|
7048
|
-
}).size /= 100;
|
|
7049
|
-
for (var i = config.domain[0]; i <= config.domain[1]; i++) {
|
|
7050
|
-
Chalkboard.plot.vect(Chalkboard.vect.init(matr[0][0], matr[1][0]), {
|
|
7051
|
-
x: config.x,
|
|
7052
|
-
y: config.y + (i / config.size) * matr[1][1],
|
|
7053
|
-
size: config.size,
|
|
7054
|
-
strokeStyle: config.strokeStyle,
|
|
7055
|
-
lineWidth: config.lineWidth / 4,
|
|
7056
|
-
context: config.context
|
|
7057
|
-
});
|
|
7058
|
-
Chalkboard.plot.vect(Chalkboard.vect.init(-matr[0][0], -matr[1][0]), {
|
|
7059
|
-
x: config.x,
|
|
7060
|
-
y: config.y + (i / config.size) * matr[1][1],
|
|
7061
|
-
size: config.size,
|
|
7062
|
-
strokeStyle: config.strokeStyle,
|
|
7063
|
-
lineWidth: config.lineWidth / 4,
|
|
7064
|
-
context: config.context
|
|
7065
|
-
});
|
|
7066
|
-
Chalkboard.plot.vect(Chalkboard.vect.init(matr[0][1], matr[1][1]), {
|
|
7067
|
-
x: config.x + (i / config.size) * matr[0][0],
|
|
7068
|
-
y: config.y,
|
|
7069
|
-
size: config.size,
|
|
7070
|
-
strokeStyle: config.strokeStyle,
|
|
7071
|
-
lineWidth: config.lineWidth / 4,
|
|
7072
|
-
context: config.context
|
|
7073
|
-
});
|
|
7074
|
-
Chalkboard.plot.vect(Chalkboard.vect.init(-matr[0][1], -matr[1][1]), {
|
|
7075
|
-
x: config.x + (i / config.size) * matr[0][0],
|
|
7076
|
-
y: config.y,
|
|
7077
|
-
size: config.size,
|
|
7078
|
-
strokeStyle: config.strokeStyle,
|
|
7079
|
-
lineWidth: config.lineWidth / 4,
|
|
7080
|
-
context: config.context
|
|
7081
|
-
});
|
|
7315
|
+
real.Dirac = function (num, edge, scl) {
|
|
7316
|
+
if (edge === void 0) { edge = 0; }
|
|
7317
|
+
if (scl === void 0) { scl = 1; }
|
|
7318
|
+
if (num === edge) {
|
|
7319
|
+
return scl;
|
|
7320
|
+
}
|
|
7321
|
+
else {
|
|
7322
|
+
return 0;
|
|
7082
7323
|
}
|
|
7083
|
-
Chalkboard.plot.vect(Chalkboard.vect.init(matr[0][0], matr[1][0]), config);
|
|
7084
|
-
Chalkboard.plot.vect(Chalkboard.vect.init(-matr[0][0], -matr[1][0]), config);
|
|
7085
|
-
Chalkboard.plot.vect(Chalkboard.vect.init(matr[0][1], matr[1][1]), config);
|
|
7086
|
-
Chalkboard.plot.vect(Chalkboard.vect.init(-matr[0][1], -matr[1][1]), config);
|
|
7087
|
-
return matr;
|
|
7088
7324
|
};
|
|
7089
|
-
|
|
7090
|
-
(
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
config.context.save();
|
|
7100
|
-
config.context.translate(config.x, config.y);
|
|
7101
|
-
config.context.strokeStyle = config.strokeStyle;
|
|
7102
|
-
config.context.lineWidth = config.lineWidth / 4;
|
|
7103
|
-
config.context.beginPath();
|
|
7104
|
-
for (var i = 0; i <= (config.size * cw) / 2; i++) {
|
|
7105
|
-
config.context.ellipse(0, 0, i / config.size, i / config.size, 0, 0, Chalkboard.PI(2));
|
|
7325
|
+
real.discriminant = function (a, b, c, form) {
|
|
7326
|
+
if (form === void 0) { form = "stan"; }
|
|
7327
|
+
if (form === "stan") {
|
|
7328
|
+
return b * b - 4 * a * c;
|
|
7329
|
+
}
|
|
7330
|
+
else if (form === "vert") {
|
|
7331
|
+
return 2 * a * b * (2 * a * b) - 4 * a * c;
|
|
7332
|
+
}
|
|
7333
|
+
else {
|
|
7334
|
+
throw new TypeError('Parameter "form" must be "stan" or "vert".');
|
|
7106
7335
|
}
|
|
7107
|
-
config.context.stroke();
|
|
7108
|
-
config.context.lineWidth = config.lineWidth;
|
|
7109
|
-
config.context.beginPath();
|
|
7110
|
-
config.context.moveTo(-config.x, 0);
|
|
7111
|
-
config.context.lineTo(cw - config.x, 0);
|
|
7112
|
-
config.context.stroke();
|
|
7113
|
-
config.context.beginPath();
|
|
7114
|
-
config.context.moveTo(0, -config.y);
|
|
7115
|
-
config.context.lineTo(0, cw - config.y);
|
|
7116
|
-
config.context.stroke();
|
|
7117
|
-
config.context.restore();
|
|
7118
7336
|
};
|
|
7119
|
-
|
|
7120
|
-
(
|
|
7121
|
-
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
config.context.save();
|
|
7130
|
-
config.context.translate(config.x, config.y);
|
|
7131
|
-
config.context.fillStyle = config.fillStyle;
|
|
7132
|
-
if (arr1.length === arr2.length) {
|
|
7133
|
-
for (var i = 0; i < arr1.length; i++) {
|
|
7134
|
-
config.context.beginPath();
|
|
7135
|
-
config.context.ellipse(arr1[i] / config.size - arr1.length / (2 * config.size), -arr2[i] / config.size + arr1.length / (2 * config.size), config.lineWidth, config.lineWidth, 0, 0, Chalkboard.PI(2));
|
|
7136
|
-
config.context.fill();
|
|
7137
|
-
data.push([arr1[i], arr2[i]]);
|
|
7337
|
+
real.div = function (func1, func2) {
|
|
7338
|
+
if ((func1.type === "expl" && func2.type === "expl") || (func1.type === "inve" && func2.type === "inve") || (func1.type === "pola" && func2.type === "pola") || (func1.type === "mult" && func2.type === "mult")) {
|
|
7339
|
+
return Chalkboard.real.define("(".concat(func1.definition, ") / (").concat(func2.definition, ")"), func1.type);
|
|
7340
|
+
}
|
|
7341
|
+
else if (func1.type === "curv" && func2.type === "curv" && Array.isArray(func1.definition) && Array.isArray(func2.definition)) {
|
|
7342
|
+
if (func1.definition.length === 2) {
|
|
7343
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0], ") / (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") / (").concat(func2.definition[1], ")")], "curv");
|
|
7344
|
+
}
|
|
7345
|
+
else if (func1.definition.length === 3) {
|
|
7346
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0], ") / (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") / (").concat(func2.definition[1], ")"), "(".concat(func1.definition[2], ") / (").concat(func2.definition[2], ")")], "curv");
|
|
7138
7347
|
}
|
|
7139
7348
|
}
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
};
|
|
7143
|
-
plot.Taylor = function (func, n, a, config) {
|
|
7144
|
-
(config = {
|
|
7145
|
-
x: (config = config || {}).x || PARSED_CONTEXT.canvas.width / 2,
|
|
7146
|
-
y: config.y || PARSED_CONTEXT.canvas.height / 2,
|
|
7147
|
-
size: config.size || 1,
|
|
7148
|
-
strokeStyle: config.strokeStyle || "black",
|
|
7149
|
-
lineWidth: config.lineWidth || 2,
|
|
7150
|
-
domain: config.domain || [-10, 10],
|
|
7151
|
-
res: config.res || 25,
|
|
7152
|
-
context: config.context || PARSED_CONTEXT
|
|
7153
|
-
}).size /= 100;
|
|
7154
|
-
var data = [];
|
|
7155
|
-
config.context.save();
|
|
7156
|
-
config.context.translate(config.x, config.y);
|
|
7157
|
-
config.context.lineWidth = config.lineWidth;
|
|
7158
|
-
config.context.strokeStyle = config.strokeStyle;
|
|
7159
|
-
config.context.beginPath();
|
|
7160
|
-
for (var i = config.domain[0] / config.size; i <= config.domain[1] / config.size; i += config.res) {
|
|
7161
|
-
config.context.lineTo(i, -Chalkboard.calc.Taylor(func, i * config.size, n, a) / config.size);
|
|
7162
|
-
data.push([i, Chalkboard.calc.Taylor(func, i, n, a)]);
|
|
7349
|
+
else if (func1.type === "surf" && func2.type === "surf" && Array.isArray(func1.definition) && Array.isArray(func2.definition)) {
|
|
7350
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0], ") / (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") / (").concat(func2.definition[1], ")"), "(".concat(func1.definition[2], ") / (").concat(func2.definition[2], ")")], "surf");
|
|
7163
7351
|
}
|
|
7164
|
-
|
|
7165
|
-
config.context.restore();
|
|
7166
|
-
return data;
|
|
7167
|
-
};
|
|
7168
|
-
plot.vect = function (vect, config) {
|
|
7169
|
-
(config = {
|
|
7170
|
-
x: (config = config || {}).x || PARSED_CONTEXT.canvas.width / 2,
|
|
7171
|
-
y: config.y || PARSED_CONTEXT.canvas.height / 2,
|
|
7172
|
-
size: config.size || 1,
|
|
7173
|
-
strokeStyle: config.strokeStyle || "black",
|
|
7174
|
-
lineWidth: config.lineWidth || 5,
|
|
7175
|
-
context: config.context || PARSED_CONTEXT
|
|
7176
|
-
}).size /= 100;
|
|
7177
|
-
config.context.strokeStyle = config.strokeStyle;
|
|
7178
|
-
config.context.lineWidth = config.lineWidth;
|
|
7179
|
-
config.context.save();
|
|
7180
|
-
config.context.translate(config.x, config.y);
|
|
7181
|
-
config.context.beginPath();
|
|
7182
|
-
config.context.moveTo(0, 0);
|
|
7183
|
-
config.context.lineTo(vect.x / config.size, -vect.y / config.size);
|
|
7184
|
-
config.context.stroke();
|
|
7185
|
-
config.context.restore();
|
|
7186
|
-
return [[vect.x], [vect.y]];
|
|
7352
|
+
throw new TypeError('Property "type" of "func1" and "func2" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
7187
7353
|
};
|
|
7188
|
-
|
|
7189
|
-
(
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
}).size /= 100;
|
|
7197
|
-
var cw = PARSED_CONTEXT.canvas.width;
|
|
7198
|
-
config.context.save();
|
|
7199
|
-
config.context.translate(config.x, config.y);
|
|
7200
|
-
config.context.strokeStyle = config.strokeStyle;
|
|
7201
|
-
config.context.lineWidth = config.lineWidth / 4;
|
|
7202
|
-
config.context.beginPath();
|
|
7203
|
-
for (var i = Math.floor(-config.x / config.size); i <= (cw - config.x) / config.size; i++) {
|
|
7204
|
-
config.context.moveTo(i / config.size, -config.y);
|
|
7205
|
-
config.context.lineTo(i / config.size, cw - config.y);
|
|
7206
|
-
}
|
|
7207
|
-
config.context.stroke();
|
|
7208
|
-
config.context.beginPath();
|
|
7209
|
-
for (var i = Math.floor(-config.y / config.size); i <= (cw - config.y) / config.size; i++) {
|
|
7210
|
-
config.context.moveTo(-config.x, i / config.size);
|
|
7211
|
-
config.context.lineTo(cw - config.x, i / config.size);
|
|
7354
|
+
real.Heaviside = function (num, edge, scl) {
|
|
7355
|
+
if (edge === void 0) { edge = 0; }
|
|
7356
|
+
if (scl === void 0) { scl = 1; }
|
|
7357
|
+
if (num >= edge) {
|
|
7358
|
+
return scl;
|
|
7359
|
+
}
|
|
7360
|
+
else {
|
|
7361
|
+
return 0;
|
|
7212
7362
|
}
|
|
7213
|
-
config.context.stroke();
|
|
7214
|
-
config.context.lineWidth = config.lineWidth;
|
|
7215
|
-
config.context.beginPath();
|
|
7216
|
-
config.context.moveTo(-config.x, 0);
|
|
7217
|
-
config.context.lineTo(cw - config.x, 0);
|
|
7218
|
-
config.context.stroke();
|
|
7219
|
-
config.context.beginPath();
|
|
7220
|
-
config.context.moveTo(0, -config.y);
|
|
7221
|
-
config.context.lineTo(0, cw - config.y);
|
|
7222
|
-
config.context.stroke();
|
|
7223
|
-
config.context.restore();
|
|
7224
7363
|
};
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
var Chalkboard;
|
|
7228
|
-
(function (Chalkboard) {
|
|
7229
|
-
var quat;
|
|
7230
|
-
(function (quat_2) {
|
|
7231
|
-
quat_2.absolute = function (quat) {
|
|
7232
|
-
return Chalkboard.quat.init(Math.abs(quat.a), Math.abs(quat.b), Math.abs(quat.c), Math.abs(quat.d));
|
|
7364
|
+
real.lerp = function (p, t) {
|
|
7365
|
+
return (p[1] - p[0]) * t + p[0];
|
|
7233
7366
|
};
|
|
7234
|
-
|
|
7235
|
-
|
|
7236
|
-
quat1 = Chalkboard.quat.init(quat1, 0, 0, 0);
|
|
7237
|
-
if (typeof quat2 === "number")
|
|
7238
|
-
quat2 = Chalkboard.quat.init(quat2, 0, 0, 0);
|
|
7239
|
-
return Chalkboard.quat.init(quat1.a + quat2.a, quat1.b + quat2.b, quat1.c + quat2.c, quat1.d + quat2.d);
|
|
7367
|
+
real.linear = function (x1, y1, x2, y2) {
|
|
7368
|
+
return Chalkboard.real.define(Chalkboard.real.slope(x1, y1, x2, y2).toString() + " * (x - " + x2.toString() + ") + " + y2.toString());
|
|
7240
7369
|
};
|
|
7241
|
-
|
|
7242
|
-
|
|
7370
|
+
real.linearFormula = function (a, b, c, d) {
|
|
7371
|
+
if (typeof c === "undefined" && typeof d === "undefined") {
|
|
7372
|
+
return -b / a;
|
|
7373
|
+
}
|
|
7374
|
+
else if (typeof c === "number" && typeof d === "undefined") {
|
|
7375
|
+
return c / a;
|
|
7376
|
+
}
|
|
7377
|
+
else {
|
|
7378
|
+
return -b / Chalkboard.real.slope(a, b, c, d) + a;
|
|
7379
|
+
}
|
|
7243
7380
|
};
|
|
7244
|
-
|
|
7245
|
-
|
|
7246
|
-
return Chalkboard.quat.init(Chalkboard.numb.constrain(quat.a, range), Chalkboard.numb.constrain(quat.b, range), Chalkboard.numb.constrain(quat.c, range), Chalkboard.numb.constrain(quat.d, range));
|
|
7381
|
+
real.ln = function (num) {
|
|
7382
|
+
return Chalkboard.calc.fxdx(Chalkboard.real.define("1 / x"), 1, num);
|
|
7247
7383
|
};
|
|
7248
|
-
|
|
7249
|
-
return
|
|
7384
|
+
real.log = function (base, num) {
|
|
7385
|
+
return Chalkboard.real.ln(num) / Chalkboard.real.ln(base);
|
|
7250
7386
|
};
|
|
7251
|
-
|
|
7252
|
-
|
|
7253
|
-
quat1 = Chalkboard.quat.init(quat1, 0, 0, 0);
|
|
7254
|
-
if (typeof quat2 === "number")
|
|
7255
|
-
quat2 = Chalkboard.quat.init(quat2, 0, 0, 0);
|
|
7256
|
-
return Chalkboard.real.sqrt((quat2.a - quat1.a) * (quat2.a - quat1.a) + (quat2.b - quat1.b) * (quat2.b - quat1.b) + (quat2.c - quat1.c) * (quat2.c - quat1.c) + (quat2.d - quat1.d) * (quat2.d - quat1.d));
|
|
7387
|
+
real.log10 = function (num) {
|
|
7388
|
+
return Chalkboard.real.log(10, num);
|
|
7257
7389
|
};
|
|
7258
|
-
|
|
7259
|
-
if (
|
|
7260
|
-
|
|
7261
|
-
|
|
7262
|
-
|
|
7263
|
-
|
|
7390
|
+
real.mul = function (func1, func2) {
|
|
7391
|
+
if ((func1.type === "expl" && func2.type === "expl") || (func1.type === "inve" && func2.type === "inve") || (func1.type === "pola" && func2.type === "pola") || (func1.type === "mult" && func2.type === "mult")) {
|
|
7392
|
+
return Chalkboard.real.define("(".concat(func1.definition, ") * (").concat(func2.definition, ")"), func1.type);
|
|
7393
|
+
}
|
|
7394
|
+
else if (func1.type === "curv" && func2.type === "curv" && Array.isArray(func1.definition) && Array.isArray(func2.definition)) {
|
|
7395
|
+
if (func1.definition.length === 2) {
|
|
7396
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0], ") * (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") * (").concat(func2.definition[1], ")")], "curv");
|
|
7397
|
+
}
|
|
7398
|
+
else if (func1.definition.length === 3) {
|
|
7399
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0], ") * (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") * (").concat(func2.definition[1], ")"), "(".concat(func1.definition[2], ") * (").concat(func2.definition[2], ")")], "curv");
|
|
7400
|
+
}
|
|
7401
|
+
}
|
|
7402
|
+
else if (func1.type === "surf" && func2.type === "surf" && Array.isArray(func1.definition) && Array.isArray(func2.definition)) {
|
|
7403
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0], ") * (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") * (").concat(func2.definition[1], ")"), "(".concat(func1.definition[2], ") * (").concat(func2.definition[2], ")")], "surf");
|
|
7404
|
+
}
|
|
7405
|
+
throw new TypeError('Property "type" of "func1" and "func2" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
7264
7406
|
};
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
quat1 = Chalkboard.quat.init(quat1, 0, 0, 0);
|
|
7268
|
-
if (typeof quat2 === "number")
|
|
7269
|
-
quat2 = Chalkboard.quat.init(quat2, 0, 0, 0);
|
|
7270
|
-
return Chalkboard.quat.init((quat1.a * quat2.a + quat1.b * quat2.b + quat1.c * quat2.c + quat1.d * quat2.d) / Chalkboard.quat.magsq(quat2), (quat1.b * quat2.a - quat1.a * quat2.b - quat1.d * quat2.c + quat1.c * quat2.d) / Chalkboard.quat.magsq(quat2), (quat1.c * quat2.a + quat1.d * quat2.b - quat1.a * quat2.c - quat1.b * quat2.d) / Chalkboard.quat.magsq(quat2), (quat1.d * quat2.a - quat1.c * quat2.b + quat1.b * quat2.c - quat1.a * quat2.d) / Chalkboard.quat.magsq(quat2));
|
|
7407
|
+
real.negate = function (func) {
|
|
7408
|
+
return Chalkboard.real.scl(func, -1);
|
|
7271
7409
|
};
|
|
7272
|
-
|
|
7273
|
-
|
|
7274
|
-
|
|
7410
|
+
real.parse = function (str) {
|
|
7411
|
+
return Function('"use strict"; ' + Chalkboard.PARSEPREFIX + " return (" + str + ")")();
|
|
7412
|
+
};
|
|
7413
|
+
real.pingpong = function (num, edge, scl) {
|
|
7414
|
+
if (edge === void 0) { edge = 0; }
|
|
7415
|
+
if (scl === void 0) { scl = 1; }
|
|
7416
|
+
if ((num + edge) % (2 * scl) < scl) {
|
|
7417
|
+
return (num + edge) % scl;
|
|
7275
7418
|
}
|
|
7276
7419
|
else {
|
|
7277
|
-
|
|
7420
|
+
return scl - ((num + edge) % scl);
|
|
7278
7421
|
}
|
|
7279
7422
|
};
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7423
|
+
real.polynomial = function () {
|
|
7424
|
+
var coeffs = [];
|
|
7425
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
7426
|
+
coeffs[_i] = arguments[_i];
|
|
7427
|
+
}
|
|
7428
|
+
var arr;
|
|
7429
|
+
if (coeffs.length === 1 && Array.isArray(coeffs[0])) {
|
|
7430
|
+
arr = coeffs[0];
|
|
7431
|
+
}
|
|
7432
|
+
else {
|
|
7433
|
+
arr = coeffs;
|
|
7434
|
+
}
|
|
7435
|
+
var result = "";
|
|
7436
|
+
for (var i = 0; i < arr.length; i++) {
|
|
7437
|
+
var coeff = arr[i];
|
|
7438
|
+
var exponent = arr.length - i - 1;
|
|
7439
|
+
if (coeff === 0 && exponent !== 0)
|
|
7440
|
+
continue;
|
|
7441
|
+
if (result !== "") {
|
|
7442
|
+
result += coeff >= 0 ? " + " : " - ";
|
|
7443
|
+
}
|
|
7444
|
+
else if (coeff < 0) {
|
|
7445
|
+
result += "-";
|
|
7446
|
+
}
|
|
7447
|
+
var abscoeff = Math.abs(coeff);
|
|
7448
|
+
var term = "";
|
|
7449
|
+
if (exponent === 0) {
|
|
7450
|
+
term = abscoeff.toString();
|
|
7451
|
+
}
|
|
7452
|
+
else if (exponent === 1) {
|
|
7453
|
+
term = (abscoeff === 1 ? "" : abscoeff + " * ") + "x";
|
|
7454
|
+
}
|
|
7455
|
+
else {
|
|
7456
|
+
term = (abscoeff === 1 ? "" : abscoeff + " * ") + "x ** " + exponent;
|
|
7457
|
+
}
|
|
7458
|
+
result += "(" + term + ")";
|
|
7459
|
+
}
|
|
7460
|
+
if (result === "")
|
|
7461
|
+
result = "0";
|
|
7462
|
+
return Chalkboard.real.define(result, "expl");
|
|
7288
7463
|
};
|
|
7289
|
-
|
|
7290
|
-
|
|
7464
|
+
real.pow = function (base, num) {
|
|
7465
|
+
if (typeof base === "number") {
|
|
7466
|
+
if (base === 0 && num === 0) {
|
|
7467
|
+
return 1;
|
|
7468
|
+
}
|
|
7469
|
+
else {
|
|
7470
|
+
return Math.exp(num * Math.log(base));
|
|
7471
|
+
}
|
|
7472
|
+
}
|
|
7473
|
+
else {
|
|
7474
|
+
var func = base;
|
|
7475
|
+
if (func.type === "expl" || func.type === "inve" || func.type === "pola" || func.type === "mult") {
|
|
7476
|
+
return Chalkboard.real.define("(".concat(func.definition, ") ** ").concat(num), func.type);
|
|
7477
|
+
}
|
|
7478
|
+
else if (func.type === "curv" && Array.isArray(func.definition)) {
|
|
7479
|
+
if (func.definition.length === 2) {
|
|
7480
|
+
return Chalkboard.real.define(["(".concat(func.definition[0], ") ** ").concat(num), "(".concat(func.definition[1], ") ** ").concat(num)], "curv");
|
|
7481
|
+
}
|
|
7482
|
+
else if (func.definition.length === 3) {
|
|
7483
|
+
return Chalkboard.real.define(["(".concat(func.definition[0], ") ** ").concat(num), "(".concat(func.definition[1], ") ** ").concat(num), "(".concat(func.definition[2], ") ** ").concat(num)], "curv");
|
|
7484
|
+
}
|
|
7485
|
+
}
|
|
7486
|
+
else if (func.type === "surf" && Array.isArray(func.definition)) {
|
|
7487
|
+
return Chalkboard.real.define(["(".concat(func.definition[0], ") ** ").concat(num), "(".concat(func.definition[1], ") ** ").concat(num), "(".concat(func.definition[2], ") ** ").concat(num)], "surf");
|
|
7488
|
+
}
|
|
7489
|
+
throw new TypeError('Property "type" of "base" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
7490
|
+
}
|
|
7291
7491
|
};
|
|
7292
|
-
|
|
7293
|
-
|
|
7492
|
+
real.qerp = function (p1, p2, p3, t) {
|
|
7493
|
+
var a = p1[1] / ((p1[0] - p2[0]) * (p1[0] - p3[0])) + p2[1] / ((p2[0] - p1[0]) * (p2[0] - p3[0])) + p3[1] / ((p3[0] - p1[0]) * (p3[0] - p2[0]));
|
|
7494
|
+
var b = (-p1[1] * (p2[0] + p3[0])) / ((p1[0] - p2[0]) * (p1[0] - p3[0])) -
|
|
7495
|
+
(p2[1] * (p1[0] + p3[0])) / ((p2[0] - p1[0]) * (p2[0] - p3[0])) -
|
|
7496
|
+
(p3[1] * (p1[0] + p2[0])) / ((p3[0] - p1[0]) * (p3[0] - p2[0]));
|
|
7497
|
+
var c = (p1[1] * p2[0] * p3[0]) / ((p1[0] - p2[0]) * (p1[0] - p3[0])) +
|
|
7498
|
+
(p2[1] * p1[0] * p3[0]) / ((p2[0] - p1[0]) * (p2[0] - p3[0])) +
|
|
7499
|
+
(p3[1] * p1[0] * p2[0]) / ((p3[0] - p1[0]) * (p3[0] - p2[0]));
|
|
7500
|
+
return a * t * t + b * t + c;
|
|
7294
7501
|
};
|
|
7295
|
-
|
|
7296
|
-
|
|
7502
|
+
real.quadratic = function (a, b, c, form) {
|
|
7503
|
+
if (form === void 0) { form = "stan"; }
|
|
7504
|
+
if (form === "stan") {
|
|
7505
|
+
return Chalkboard.real.define(a.toString() + "* x * x + " + b.toString() + " * x +" + c.toString());
|
|
7506
|
+
}
|
|
7507
|
+
else if (form === "vert") {
|
|
7508
|
+
return Chalkboard.real.define(a.toString() + " * ((x - " + b.toString() + ") * (x - " + b.toString() + ")) +" + c.toString());
|
|
7509
|
+
}
|
|
7510
|
+
else {
|
|
7511
|
+
throw new TypeError('Parameter "form" must be "stan" or "vert".');
|
|
7512
|
+
}
|
|
7297
7513
|
};
|
|
7298
|
-
|
|
7299
|
-
if (
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
|
|
7303
|
-
|
|
7514
|
+
real.quadraticFormula = function (a, b, c, form) {
|
|
7515
|
+
if (form === void 0) { form = "stan"; }
|
|
7516
|
+
if (form === "stan") {
|
|
7517
|
+
return [(-b + Chalkboard.real.sqrt(Chalkboard.real.discriminant(a, b, c, "stan"))) / (2 * a), (-b - Math.sqrt(Chalkboard.real.discriminant(a, b, c, "stan"))) / (2 * a)];
|
|
7518
|
+
}
|
|
7519
|
+
else if (form === "vert") {
|
|
7520
|
+
return [b + Chalkboard.real.sqrt(-c / a), b - Chalkboard.real.sqrt(-c / a)];
|
|
7521
|
+
}
|
|
7522
|
+
else {
|
|
7523
|
+
throw new TypeError('Parameter "form" must be "stan" or "vert".');
|
|
7524
|
+
}
|
|
7304
7525
|
};
|
|
7305
|
-
|
|
7306
|
-
|
|
7526
|
+
real.ramp = function (num, edge, scl) {
|
|
7527
|
+
if (edge === void 0) { edge = 0; }
|
|
7528
|
+
if (scl === void 0) { scl = 1; }
|
|
7529
|
+
if (num >= edge) {
|
|
7530
|
+
return num * scl;
|
|
7531
|
+
}
|
|
7532
|
+
else {
|
|
7533
|
+
return 0;
|
|
7534
|
+
}
|
|
7307
7535
|
};
|
|
7308
|
-
|
|
7309
|
-
|
|
7536
|
+
real.randomPolynomial = function (degree, inf, sup) {
|
|
7537
|
+
var _a;
|
|
7538
|
+
if (inf === void 0) { inf = 0; }
|
|
7539
|
+
if (sup === void 0) { sup = 1; }
|
|
7540
|
+
return (_a = Chalkboard.real).polynomial.apply(_a, Chalkboard.stat.random(degree + 1, inf, sup));
|
|
7310
7541
|
};
|
|
7311
|
-
|
|
7312
|
-
|
|
7542
|
+
real.reciprocate = function (func) {
|
|
7543
|
+
if (func.type === "expl" || func.type === "inve" || func.type === "pola" || func.type === "mult") {
|
|
7544
|
+
return Chalkboard.real.define("1 / (".concat(func.definition, ")"), func.type);
|
|
7545
|
+
}
|
|
7546
|
+
else if (func.type === "curv" && Array.isArray(func.definition)) {
|
|
7547
|
+
if (func.definition.length === 2) {
|
|
7548
|
+
return Chalkboard.real.define(["1 / (".concat(func.definition[0], ")"), "1 / (".concat(func.definition[1], ")")], "curv");
|
|
7549
|
+
}
|
|
7550
|
+
else if (func.definition.length === 3) {
|
|
7551
|
+
return Chalkboard.real.define(["1 / (".concat(func.definition[0], ")"), "1 / (".concat(func.definition[1], ")"), "1 / (".concat(func.definition[2], ")")], "curv");
|
|
7552
|
+
}
|
|
7553
|
+
}
|
|
7554
|
+
else if (func.type === "surf" && Array.isArray(func.definition)) {
|
|
7555
|
+
return Chalkboard.real.define(["1 / (".concat(func.definition[0], ")"), "1 / (".concat(func.definition[1], ")"), "1 / (".concat(func.definition[2], ")")], "surf");
|
|
7556
|
+
}
|
|
7557
|
+
throw new TypeError('Property "type" of "func" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
7313
7558
|
};
|
|
7314
|
-
|
|
7315
|
-
if (
|
|
7316
|
-
if (
|
|
7317
|
-
|
|
7559
|
+
real.rect = function (num, center, width, scl) {
|
|
7560
|
+
if (center === void 0) { center = 0; }
|
|
7561
|
+
if (width === void 0) { width = 2; }
|
|
7562
|
+
if (scl === void 0) { scl = 1; }
|
|
7563
|
+
if (num > center + width / 2 || num < center - width / 2) {
|
|
7564
|
+
return 0;
|
|
7565
|
+
}
|
|
7566
|
+
else {
|
|
7567
|
+
return scl;
|
|
7568
|
+
}
|
|
7318
7569
|
};
|
|
7319
|
-
|
|
7320
|
-
|
|
7570
|
+
real.root = function (num, index) {
|
|
7571
|
+
if (index === void 0) { index = 3; }
|
|
7572
|
+
return Math.exp(Math.log(num) / index);
|
|
7321
7573
|
};
|
|
7322
|
-
|
|
7323
|
-
|
|
7574
|
+
real.scl = function (func, num) {
|
|
7575
|
+
if (func.type === "expl" || func.type === "inve" || func.type === "pola" || func.type === "mult") {
|
|
7576
|
+
return Chalkboard.real.define("".concat(num, " * (").concat(func.definition, ")"), func.type);
|
|
7577
|
+
}
|
|
7578
|
+
else if (func.type === "curv" && Array.isArray(func.definition)) {
|
|
7579
|
+
if (func.definition.length === 2) {
|
|
7580
|
+
return Chalkboard.real.define(["".concat(num, " * (").concat(func.definition[0], ")"), "".concat(num, " * (").concat(func.definition[1], ")")], "curv");
|
|
7581
|
+
}
|
|
7582
|
+
else if (func.definition.length === 3) {
|
|
7583
|
+
return Chalkboard.real.define(["".concat(num, " * (").concat(func.definition[0], ")"), "".concat(num, " * (").concat(func.definition[1], ")"), "".concat(num, " * (").concat(func.definition[2], ")")], "curv");
|
|
7584
|
+
}
|
|
7585
|
+
}
|
|
7586
|
+
else if (func.type === "surf" && Array.isArray(func.definition)) {
|
|
7587
|
+
return Chalkboard.real.define(["".concat(num, " * (").concat(func.definition[0], ")"), "".concat(num, " * (").concat(func.definition[1], ")"), "".concat(num, " * (").concat(func.definition[2], ")")], "surf");
|
|
7588
|
+
}
|
|
7589
|
+
throw new TypeError('Property "type" of "func" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
7324
7590
|
};
|
|
7325
|
-
|
|
7326
|
-
return
|
|
7591
|
+
real.slope = function (x1, y1, x2, y2) {
|
|
7592
|
+
return (y2 - y1) / (x2 - x1);
|
|
7327
7593
|
};
|
|
7328
|
-
|
|
7329
|
-
if (
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
|
|
7333
|
-
|
|
7594
|
+
real.sqrt = function (num) {
|
|
7595
|
+
if (num >= 0) {
|
|
7596
|
+
return Math.exp(Math.log(num) / 2);
|
|
7597
|
+
}
|
|
7598
|
+
else {
|
|
7599
|
+
return NaN;
|
|
7600
|
+
}
|
|
7334
7601
|
};
|
|
7335
|
-
|
|
7336
|
-
|
|
7602
|
+
real.sub = function (func1, func2) {
|
|
7603
|
+
if ((func1.type === "expl" && func2.type === "expl") || (func1.type === "inve" && func2.type === "inve") || (func1.type === "pola" && func2.type === "pola") || (func1.type === "mult" && func2.type === "mult")) {
|
|
7604
|
+
return Chalkboard.real.define("(".concat(func1.definition, ") - (").concat(func2.definition, ")"), func1.type);
|
|
7605
|
+
}
|
|
7606
|
+
else if (func1.type === "curv" && func2.type === "curv" && Array.isArray(func1.definition) && Array.isArray(func2.definition)) {
|
|
7607
|
+
if (func1.definition.length === 2 && func2.definition.length === 2) {
|
|
7608
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0], ") - (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") - (").concat(func2.definition[1], ")")], "curv");
|
|
7609
|
+
}
|
|
7610
|
+
else if (func1.definition.length === 3 && func2.definition.length === 3) {
|
|
7611
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0], ") - (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") - (").concat(func2.definition[1], ")"), "(".concat(func1.definition[2], ") - (").concat(func2.definition[2], ")")], "curv");
|
|
7612
|
+
}
|
|
7613
|
+
}
|
|
7614
|
+
else if (func1.type === "surf" && func2.type === "surf" && Array.isArray(func1.definition) && Array.isArray(func2.definition)) {
|
|
7615
|
+
return Chalkboard.real.define(["(".concat(func1.definition[0], ") - (").concat(func2.definition[0], ")"), "(".concat(func1.definition[1], ") - (").concat(func2.definition[1], ")"), "(".concat(func1.definition[2], ") - (").concat(func2.definition[2], ")")], "surf");
|
|
7616
|
+
}
|
|
7617
|
+
throw new TypeError('Property "type" of "func1" and "func2" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
7337
7618
|
};
|
|
7338
|
-
|
|
7339
|
-
|
|
7619
|
+
real.tetration = function (base, num) {
|
|
7620
|
+
if (num === 0) {
|
|
7621
|
+
return 1;
|
|
7622
|
+
}
|
|
7623
|
+
else if (num > 0) {
|
|
7624
|
+
return Math.pow(base, Chalkboard.real.tetration(base, num - 1));
|
|
7625
|
+
}
|
|
7340
7626
|
};
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7627
|
+
real.translate = function (func, h, v) {
|
|
7628
|
+
if (h === void 0) { h = 0; }
|
|
7629
|
+
if (v === void 0) { v = 0; }
|
|
7630
|
+
if (func.type === "expl") {
|
|
7631
|
+
if (h !== 0 && v !== 0) {
|
|
7632
|
+
return Chalkboard.real.define("(".concat(func.definition.toString().replace(/x/g, "(x - ".concat(h, ")")), ") + ").concat(v), "expl");
|
|
7633
|
+
}
|
|
7634
|
+
else if (h !== 0) {
|
|
7635
|
+
return Chalkboard.real.define("".concat(func.definition.toString().replace(/x/g, "(x - ".concat(h, ")"))), "expl");
|
|
7636
|
+
}
|
|
7637
|
+
else if (v !== 0) {
|
|
7638
|
+
return Chalkboard.real.define("(".concat(func.definition, ") + ").concat(v), "expl");
|
|
7639
|
+
}
|
|
7640
|
+
else {
|
|
7641
|
+
return func;
|
|
7642
|
+
}
|
|
7643
|
+
}
|
|
7644
|
+
throw new TypeError('Property "type" of "func" must be "expl".');
|
|
7346
7645
|
};
|
|
7347
|
-
|
|
7348
|
-
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
if (quat.b >= 0) {
|
|
7352
|
-
quat_b = " + " + quat.b.toString() + "i ";
|
|
7646
|
+
real.val = function (func, val) {
|
|
7647
|
+
if (func.type === "expl") {
|
|
7648
|
+
var f = Chalkboard.real.parse("x => " + func.definition);
|
|
7649
|
+
return f(val);
|
|
7353
7650
|
}
|
|
7354
|
-
else if (
|
|
7355
|
-
|
|
7651
|
+
else if (func.type === "inve") {
|
|
7652
|
+
var f = Chalkboard.real.parse("y => " + func.definition);
|
|
7653
|
+
return f(val);
|
|
7356
7654
|
}
|
|
7357
|
-
if (
|
|
7358
|
-
|
|
7655
|
+
else if (func.type === "pola") {
|
|
7656
|
+
var r = Chalkboard.real.parse("O => " + func.definition);
|
|
7657
|
+
return r(val);
|
|
7359
7658
|
}
|
|
7360
|
-
else if (
|
|
7361
|
-
|
|
7659
|
+
else if (func.type === "curv") {
|
|
7660
|
+
if (func.definition.length === 2) {
|
|
7661
|
+
var x = Chalkboard.real.parse("t => " + func.definition[0]), y = Chalkboard.real.parse("t => " + func.definition[1]);
|
|
7662
|
+
return Chalkboard.vect.init(x(val), y(val));
|
|
7663
|
+
}
|
|
7664
|
+
else {
|
|
7665
|
+
var x = Chalkboard.real.parse("t => " + func.definition[0]), y = Chalkboard.real.parse("t => " + func.definition[1]), z = Chalkboard.real.parse("t => " + func.definition[2]);
|
|
7666
|
+
return Chalkboard.vect.init(x(val), y(val), z(val));
|
|
7667
|
+
}
|
|
7362
7668
|
}
|
|
7363
|
-
if (
|
|
7364
|
-
|
|
7669
|
+
else if (func.type === "surf") {
|
|
7670
|
+
var vect_2 = val;
|
|
7671
|
+
var x = Chalkboard.real.parse("(s, t) => " + func.definition[0]), y = Chalkboard.real.parse("(s, t) => " + func.definition[1]), z = Chalkboard.real.parse("(s, t) => " + func.definition[2]);
|
|
7672
|
+
return Chalkboard.vect.init(x(vect_2.x, vect_2.y), y(vect_2.x, vect_2.y), z(vect_2.x, vect_2.y));
|
|
7365
7673
|
}
|
|
7366
|
-
else if (
|
|
7367
|
-
|
|
7674
|
+
else if (func.type === "mult" && typeof val !== "number") {
|
|
7675
|
+
var vect_3 = val;
|
|
7676
|
+
var f = Chalkboard.real.parse("(x, y) => " + func.definition);
|
|
7677
|
+
return f(vect_3.x, vect_3.y);
|
|
7678
|
+
}
|
|
7679
|
+
else {
|
|
7680
|
+
throw new TypeError('Parameter "func" must be of type "ChalkboardFunction" with a "type" property of "expl", "pola", "curv", "surf", or "mult".');
|
|
7368
7681
|
}
|
|
7369
|
-
return quat.a.toString() + quat_b + quat_c + quat_d;
|
|
7370
|
-
};
|
|
7371
|
-
quat_2.toVector = function (quat) {
|
|
7372
|
-
return Chalkboard.vect.init(quat.a, quat.b, quat.c, quat.d);
|
|
7373
7682
|
};
|
|
7374
|
-
|
|
7375
|
-
|
|
7683
|
+
real.zero = function (type) {
|
|
7684
|
+
if (type === void 0) { type = "expl"; }
|
|
7685
|
+
if (type === "expl" || type === "inve" || type === "pola" || type === "mult") {
|
|
7686
|
+
return Chalkboard.real.define("0", type);
|
|
7687
|
+
}
|
|
7688
|
+
else if (type === "curv") {
|
|
7689
|
+
return Chalkboard.real.define(["0", "0"], type);
|
|
7690
|
+
}
|
|
7691
|
+
else if (type === "surf") {
|
|
7692
|
+
return Chalkboard.real.define(["0", "0", "0"], type);
|
|
7693
|
+
}
|
|
7694
|
+
throw new TypeError('Parameter "type" must be either "expl", "inve", "pola", "curv", "surf", or "mult".');
|
|
7376
7695
|
};
|
|
7377
|
-
})(
|
|
7696
|
+
})(real = Chalkboard.real || (Chalkboard.real = {}));
|
|
7378
7697
|
})(Chalkboard || (Chalkboard = {}));
|
|
7379
7698
|
var Chalkboard;
|
|
7380
7699
|
(function (Chalkboard) {
|
|
@@ -8786,6 +9105,29 @@ var Chalkboard;
|
|
|
8786
9105
|
return result;
|
|
8787
9106
|
}
|
|
8788
9107
|
};
|
|
9108
|
+
tens_1.toTypedArray = function (tens, type) {
|
|
9109
|
+
if (type === void 0) { type = "float32"; }
|
|
9110
|
+
var arr = Chalkboard.tens.toArray(tens);
|
|
9111
|
+
if (type === "int8") {
|
|
9112
|
+
return new Int8Array(arr);
|
|
9113
|
+
}
|
|
9114
|
+
else if (type === "int16") {
|
|
9115
|
+
return new Int16Array(arr);
|
|
9116
|
+
}
|
|
9117
|
+
else if (type === "int32") {
|
|
9118
|
+
return new Int32Array(arr);
|
|
9119
|
+
}
|
|
9120
|
+
else if (type === "float32") {
|
|
9121
|
+
return new Float32Array(arr);
|
|
9122
|
+
}
|
|
9123
|
+
else if (type === "float64") {
|
|
9124
|
+
return new Float64Array(arr);
|
|
9125
|
+
}
|
|
9126
|
+
else if (type === "bigint64") {
|
|
9127
|
+
return new BigInt64Array(arr.map(function (n) { return BigInt(Math.floor(n)); }));
|
|
9128
|
+
}
|
|
9129
|
+
throw new TypeError('Parameter "type" must be "int8", "int16", "int32", "float32", "float64", or "bigint64".');
|
|
9130
|
+
};
|
|
8789
9131
|
tens_1.toVector = function (tens, dimension, index) {
|
|
8790
9132
|
if (index === void 0) { index = 0; }
|
|
8791
9133
|
var arr = Chalkboard.tens.toArray(tens);
|
|
@@ -8806,17 +9148,25 @@ var Chalkboard;
|
|
|
8806
9148
|
var _a;
|
|
8807
9149
|
return (_a = Chalkboard.tens).resize.apply(_a, __spreadArray([tens], Chalkboard.tens.size(tens).reverse(), false));
|
|
8808
9150
|
};
|
|
8809
|
-
tens_1.zero = function (
|
|
8810
|
-
var
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
9151
|
+
tens_1.zero = function () {
|
|
9152
|
+
var size = [];
|
|
9153
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
9154
|
+
size[_i] = arguments[_i];
|
|
9155
|
+
}
|
|
9156
|
+
size = Array.isArray(size[0]) ? size[0] : size;
|
|
9157
|
+
var newNDArray = function (size) {
|
|
9158
|
+
if (size.length === 0) {
|
|
9159
|
+
return 0;
|
|
9160
|
+
}
|
|
9161
|
+
var curr = size[0];
|
|
9162
|
+
var rest = size.slice(1);
|
|
9163
|
+
var result = [];
|
|
9164
|
+
for (var i = 0; i < curr; i++) {
|
|
9165
|
+
result[i] = newNDArray(rest);
|
|
8814
9166
|
}
|
|
8815
9167
|
return result;
|
|
8816
|
-
}
|
|
8817
|
-
|
|
8818
|
-
return 0;
|
|
8819
|
-
}
|
|
9168
|
+
};
|
|
9169
|
+
return newNDArray(size);
|
|
8820
9170
|
};
|
|
8821
9171
|
})(tens = Chalkboard.tens || (Chalkboard.tens = {}));
|
|
8822
9172
|
})(Chalkboard || (Chalkboard = {}));
|
|
@@ -8960,22 +9310,23 @@ var Chalkboard;
|
|
|
8960
9310
|
}
|
|
8961
9311
|
};
|
|
8962
9312
|
trig.cos = function (rad) {
|
|
8963
|
-
|
|
9313
|
+
var x = Chalkboard.trig.coterminal(rad);
|
|
9314
|
+
var x2 = x * x, x4 = x2 * x2, x6 = x4 * x2, x8 = x4 * x4, x10 = x6 * x4, x12 = x8 * x4, x14 = x8 * x6, x16 = x8 * x8, x18 = x10 * x8, x20 = x10 * x10, x22 = x12 * x10, x24 = x12 * x12, x26 = x14 * x12, x28 = x14 * x14;
|
|
8964
9315
|
return (1 -
|
|
8965
|
-
|
|
8966
|
-
|
|
8967
|
-
|
|
8968
|
-
|
|
8969
|
-
|
|
8970
|
-
|
|
8971
|
-
|
|
8972
|
-
|
|
8973
|
-
|
|
8974
|
-
|
|
8975
|
-
|
|
8976
|
-
|
|
8977
|
-
|
|
8978
|
-
|
|
9316
|
+
x2 / 2 +
|
|
9317
|
+
x4 / 24 -
|
|
9318
|
+
x6 / 720 +
|
|
9319
|
+
x8 / 40320 -
|
|
9320
|
+
x10 / 3628800 +
|
|
9321
|
+
x12 / 479001600 -
|
|
9322
|
+
x14 / 87178291200 +
|
|
9323
|
+
x16 / 20922789888000 -
|
|
9324
|
+
x18 / 6402373705728000 +
|
|
9325
|
+
x20 / 2.43290200817664e+18 -
|
|
9326
|
+
x22 / 1.1240007277776077e+21 +
|
|
9327
|
+
x24 / 6.204484017332394e+23 -
|
|
9328
|
+
x26 / 4.0329146112660565e+26 +
|
|
9329
|
+
x28 / 3.0488834461171384e+29);
|
|
8979
9330
|
};
|
|
8980
9331
|
trig.cosh = function (rad) {
|
|
8981
9332
|
return (Math.pow(Chalkboard.E(), rad) + Math.pow(Chalkboard.E(), -rad)) / 2;
|
|
@@ -9002,22 +9353,23 @@ var Chalkboard;
|
|
|
9002
9353
|
return 1 / Chalkboard.trig.cosh(rad);
|
|
9003
9354
|
};
|
|
9004
9355
|
trig.sin = function (rad) {
|
|
9005
|
-
|
|
9006
|
-
|
|
9007
|
-
|
|
9008
|
-
|
|
9009
|
-
|
|
9010
|
-
|
|
9011
|
-
|
|
9012
|
-
|
|
9013
|
-
|
|
9014
|
-
|
|
9015
|
-
|
|
9016
|
-
|
|
9017
|
-
|
|
9018
|
-
|
|
9019
|
-
|
|
9020
|
-
|
|
9356
|
+
var x = Chalkboard.trig.coterminal(rad);
|
|
9357
|
+
var x2 = x * x, x3 = x2 * x, x5 = x3 * x2, x7 = x5 * x2, x9 = x7 * x2, x11 = x9 * x2, x13 = x11 * x2, x15 = x13 * x2, x17 = x15 * x2, x19 = x17 * x2, x21 = x19 * x2, x23 = x21 * x2, x25 = x23 * x2, x27 = x25 * x2, x29 = x27 * x2;
|
|
9358
|
+
return (x -
|
|
9359
|
+
x3 / 6 +
|
|
9360
|
+
x5 / 120 -
|
|
9361
|
+
x7 / 5040 +
|
|
9362
|
+
x9 / 362880 -
|
|
9363
|
+
x11 / 39916800 +
|
|
9364
|
+
x13 / 6227020800 -
|
|
9365
|
+
x15 / 1307674368000 +
|
|
9366
|
+
x17 / 355687428096000 -
|
|
9367
|
+
x19 / 1.21645100408832e+17 +
|
|
9368
|
+
x21 / 5.109094217170944e+19 -
|
|
9369
|
+
x23 / 2.585201673888498e+22 +
|
|
9370
|
+
x25 / 1.5511210043330986e+25 -
|
|
9371
|
+
x27 / 1.0888869450418352e+28 +
|
|
9372
|
+
x29 / 8.841761993739701e+30);
|
|
9021
9373
|
};
|
|
9022
9374
|
trig.sinh = function (rad) {
|
|
9023
9375
|
return (Math.pow(Chalkboard.E(), rad) - Math.pow(Chalkboard.E(), -rad)) / 2;
|
|
@@ -9040,7 +9392,90 @@ var Chalkboard;
|
|
|
9040
9392
|
(function (Chalkboard) {
|
|
9041
9393
|
var vect;
|
|
9042
9394
|
(function (vect_4) {
|
|
9395
|
+
var $ = function (input) {
|
|
9396
|
+
var $$ = function (x, y, z, w) {
|
|
9397
|
+
if (z === undefined && w === undefined) {
|
|
9398
|
+
return { x: x, y: y };
|
|
9399
|
+
}
|
|
9400
|
+
else if (w === undefined) {
|
|
9401
|
+
return { x: x, y: y, z: z };
|
|
9402
|
+
}
|
|
9403
|
+
else {
|
|
9404
|
+
return { x: x, y: y, z: z, w: w };
|
|
9405
|
+
}
|
|
9406
|
+
};
|
|
9407
|
+
var v = input;
|
|
9408
|
+
if (v && typeof v.x === "number" && typeof v.y === "number") {
|
|
9409
|
+
return input;
|
|
9410
|
+
}
|
|
9411
|
+
if (Array.isArray(input)) {
|
|
9412
|
+
if (input.length > 0 && Array.isArray(input[0])) {
|
|
9413
|
+
var matr_4 = input;
|
|
9414
|
+
var rows = Chalkboard.matr.rows(matr_4);
|
|
9415
|
+
var cols = Chalkboard.matr.cols(matr_4);
|
|
9416
|
+
if (cols === 1) {
|
|
9417
|
+
if (rows === 2)
|
|
9418
|
+
return $$(matr_4[0][0], matr_4[1][0]);
|
|
9419
|
+
if (rows === 3)
|
|
9420
|
+
return $$(matr_4[0][0], matr_4[1][0], matr_4[2][0]);
|
|
9421
|
+
if (rows === 4)
|
|
9422
|
+
return $$(matr_4[0][0], matr_4[1][0], matr_4[2][0], matr_4[3][0]);
|
|
9423
|
+
}
|
|
9424
|
+
else if (rows === 1) {
|
|
9425
|
+
if (cols === 2)
|
|
9426
|
+
return $$(matr_4[0][0], matr_4[0][1]);
|
|
9427
|
+
if (cols === 3)
|
|
9428
|
+
return $$(matr_4[0][0], matr_4[0][1], matr_4[0][2]);
|
|
9429
|
+
if (cols === 4)
|
|
9430
|
+
return $$(matr_4[0][0], matr_4[0][1], matr_4[0][2], matr_4[0][3]);
|
|
9431
|
+
}
|
|
9432
|
+
}
|
|
9433
|
+
else {
|
|
9434
|
+
var arr = input;
|
|
9435
|
+
if (arr.length === 2)
|
|
9436
|
+
return $$(arr[0], arr[1]);
|
|
9437
|
+
if (arr.length === 3)
|
|
9438
|
+
return $$(arr[0], arr[1], arr[2]);
|
|
9439
|
+
if (arr.length === 4)
|
|
9440
|
+
return $$(arr[0], arr[1], arr[2], arr[3]);
|
|
9441
|
+
}
|
|
9442
|
+
}
|
|
9443
|
+
if (input instanceof Float32Array || input instanceof Float64Array) {
|
|
9444
|
+
var arr = input;
|
|
9445
|
+
if (arr.length === 2)
|
|
9446
|
+
return $$(arr[0], arr[1]);
|
|
9447
|
+
if (arr.length === 3)
|
|
9448
|
+
return $$(arr[0], arr[1], arr[2]);
|
|
9449
|
+
if (arr.length === 4)
|
|
9450
|
+
return $$(arr[0], arr[1], arr[2], arr[3]);
|
|
9451
|
+
}
|
|
9452
|
+
if (typeof input === "string") {
|
|
9453
|
+
try {
|
|
9454
|
+
var parsed = JSON.parse(input);
|
|
9455
|
+
if (parsed && typeof parsed === "object" && typeof parsed.x === "number" && typeof parsed.y === "number") {
|
|
9456
|
+
return $$(parsed.x, parsed.y, parsed.z !== undefined ? parsed.z : undefined, parsed.w !== undefined ? parsed.w : undefined);
|
|
9457
|
+
}
|
|
9458
|
+
}
|
|
9459
|
+
catch (e) {
|
|
9460
|
+
var str = input.trim();
|
|
9461
|
+
if (str.startsWith("(") && str.endsWith(")")) {
|
|
9462
|
+
var content = str.substring(1, str.length - 1);
|
|
9463
|
+
var components = content.split(",").map(function (part) { return parseFloat(part.trim()); });
|
|
9464
|
+
if (components.length >= 2 && components.every(function (p) { return !isNaN(p); })) {
|
|
9465
|
+
if (components.length === 2)
|
|
9466
|
+
return $$(components[0], components[1]);
|
|
9467
|
+
if (components.length === 3)
|
|
9468
|
+
return $$(components[0], components[1], components[2]);
|
|
9469
|
+
if (components.length === 4)
|
|
9470
|
+
return $$(components[0], components[1], components[2], components[3]);
|
|
9471
|
+
}
|
|
9472
|
+
}
|
|
9473
|
+
}
|
|
9474
|
+
}
|
|
9475
|
+
throw new TypeError("Invalid ChalkboardVector input: ".concat(JSON.stringify(input)));
|
|
9476
|
+
};
|
|
9043
9477
|
vect_4.absolute = function (vect) {
|
|
9478
|
+
vect = $(vect);
|
|
9044
9479
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9045
9480
|
return Chalkboard.vect.init(Math.abs(vect.x), Math.abs(vect.y));
|
|
9046
9481
|
}
|
|
@@ -9055,6 +9490,8 @@ var Chalkboard;
|
|
|
9055
9490
|
}
|
|
9056
9491
|
};
|
|
9057
9492
|
vect_4.add = function (vect1, vect2) {
|
|
9493
|
+
vect1 = $(vect1);
|
|
9494
|
+
vect2 = $(vect2);
|
|
9058
9495
|
if (Chalkboard.vect.isDimensionOf(vect1, 2) && Chalkboard.vect.isDimensionOf(vect2, 2)) {
|
|
9059
9496
|
return Chalkboard.vect.init(vect1.x + vect2.x, vect1.y + vect2.y);
|
|
9060
9497
|
}
|
|
@@ -9069,19 +9506,17 @@ var Chalkboard;
|
|
|
9069
9506
|
}
|
|
9070
9507
|
};
|
|
9071
9508
|
vect_4.ang = function (vect) {
|
|
9509
|
+
vect = $(vect);
|
|
9072
9510
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9073
9511
|
return Chalkboard.trig.arctan2(vect.y, vect.x);
|
|
9074
9512
|
}
|
|
9075
9513
|
else if (Chalkboard.vect.isDimensionOf(vect, 3)) {
|
|
9076
|
-
|
|
9514
|
+
var m = Chalkboard.vect.mag(vect);
|
|
9515
|
+
return [Math.acos(vect.x / m), Math.acos(vect.y / m), Math.acos(vect.z / m)];
|
|
9077
9516
|
}
|
|
9078
9517
|
else if (Chalkboard.vect.isDimensionOf(vect, 4)) {
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
Math.acos(vect.y / Chalkboard.vect.mag(vect)),
|
|
9082
|
-
Math.acos(vect.z / Chalkboard.vect.mag(vect)),
|
|
9083
|
-
Math.acos(vect.w / Chalkboard.vect.mag(vect))
|
|
9084
|
-
];
|
|
9518
|
+
var m = Chalkboard.vect.mag(vect);
|
|
9519
|
+
return [Math.acos(vect.x / m), Math.acos(vect.y / m), Math.acos(vect.z / m), Math.acos(vect.w / m)];
|
|
9085
9520
|
}
|
|
9086
9521
|
else {
|
|
9087
9522
|
throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.');
|
|
@@ -9092,6 +9527,7 @@ var Chalkboard;
|
|
|
9092
9527
|
};
|
|
9093
9528
|
vect_4.constrain = function (vect, range) {
|
|
9094
9529
|
if (range === void 0) { range = [0, 1]; }
|
|
9530
|
+
vect = $(vect);
|
|
9095
9531
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9096
9532
|
return Chalkboard.vect.init(Chalkboard.numb.constrain(vect.x, range), Chalkboard.numb.constrain(vect.y, range));
|
|
9097
9533
|
}
|
|
@@ -9106,9 +9542,27 @@ var Chalkboard;
|
|
|
9106
9542
|
}
|
|
9107
9543
|
};
|
|
9108
9544
|
vect_4.copy = function (vect) {
|
|
9109
|
-
|
|
9545
|
+
vect = $(vect);
|
|
9546
|
+
var _vect = Object.create(Object.getPrototypeOf(vect), Object.getOwnPropertyDescriptors(vect));
|
|
9547
|
+
if (mode === "vector")
|
|
9548
|
+
return _vect;
|
|
9549
|
+
if (mode === "array")
|
|
9550
|
+
return Chalkboard.vect.toArray(_vect);
|
|
9551
|
+
if (mode === "float32array")
|
|
9552
|
+
return new Float32Array(Chalkboard.vect.toArray(_vect));
|
|
9553
|
+
if (mode === "float64array")
|
|
9554
|
+
return new Float64Array(Chalkboard.vect.toArray(_vect));
|
|
9555
|
+
if (mode === "matrix")
|
|
9556
|
+
return Chalkboard.vect.toMatrix(_vect);
|
|
9557
|
+
if (mode === "string")
|
|
9558
|
+
return Chalkboard.vect.toString(_vect);
|
|
9559
|
+
if (mode === "json")
|
|
9560
|
+
return JSON.stringify(_vect);
|
|
9561
|
+
return _vect;
|
|
9110
9562
|
};
|
|
9111
9563
|
vect_4.cross = function (vect1, vect2) {
|
|
9564
|
+
vect1 = $(vect1);
|
|
9565
|
+
vect2 = $(vect2);
|
|
9112
9566
|
if (Chalkboard.vect.isDimensionOf(vect1, 2) && Chalkboard.vect.isDimensionOf(vect2, 2)) {
|
|
9113
9567
|
return Chalkboard.vect.init(0, 0, vect1.x * vect2.y - vect1.y * vect2.x);
|
|
9114
9568
|
}
|
|
@@ -9120,25 +9574,35 @@ var Chalkboard;
|
|
|
9120
9574
|
}
|
|
9121
9575
|
};
|
|
9122
9576
|
vect_4.dimension = function (vectORvectfield) {
|
|
9123
|
-
|
|
9124
|
-
|
|
9125
|
-
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
(typeof vectfield.p === "string" && typeof vectfield.q === "string" && typeof vectfield.r === "string" && typeof vectfield.s === "string")) {
|
|
9135
|
-
return 4;
|
|
9577
|
+
try {
|
|
9578
|
+
var v = $(vectORvectfield);
|
|
9579
|
+
if (typeof v.x === "number" && typeof v.y === "number" && typeof v.z === "undefined" && typeof v.w === "undefined") {
|
|
9580
|
+
return 2;
|
|
9581
|
+
}
|
|
9582
|
+
else if (typeof v.x === "number" && typeof v.y === "number" && typeof v.z === "number" && typeof v.w === "undefined") {
|
|
9583
|
+
return 3;
|
|
9584
|
+
}
|
|
9585
|
+
else if (typeof v.x === "number" && typeof v.y === "number" && typeof v.z === "number" && typeof v.w === "number") {
|
|
9586
|
+
return 4;
|
|
9587
|
+
}
|
|
9136
9588
|
}
|
|
9137
|
-
|
|
9138
|
-
|
|
9589
|
+
catch (_a) {
|
|
9590
|
+
var f = vectORvectfield;
|
|
9591
|
+
if (typeof f.p === "string" && typeof f.q === "string" && typeof f.r === "undefined" && typeof f.s === "undefined") {
|
|
9592
|
+
return 2;
|
|
9593
|
+
}
|
|
9594
|
+
else if (typeof f.p === "string" && typeof f.q === "string" && typeof f.r === "string" && typeof f.s === "undefined") {
|
|
9595
|
+
return 3;
|
|
9596
|
+
}
|
|
9597
|
+
else if (typeof f.p === "string" && typeof f.q === "string" && typeof f.r === "string" && typeof f.s === "string") {
|
|
9598
|
+
return 4;
|
|
9599
|
+
}
|
|
9139
9600
|
}
|
|
9601
|
+
throw new TypeError('Parameter "vectORvectfield" must be a vector or vector field with 2, 3, or 4 dimensions.');
|
|
9140
9602
|
};
|
|
9141
9603
|
vect_4.dist = function (vect1, vect2) {
|
|
9604
|
+
vect1 = $(vect1);
|
|
9605
|
+
vect2 = $(vect2);
|
|
9142
9606
|
if (Chalkboard.vect.isDimensionOf(vect1, 2) && Chalkboard.vect.isDimensionOf(vect2, 2)) {
|
|
9143
9607
|
return Chalkboard.real.sqrt((vect2.x - vect1.x) * (vect2.x - vect1.x) + (vect2.y - vect1.y) * (vect2.y - vect1.y));
|
|
9144
9608
|
}
|
|
@@ -9146,16 +9610,15 @@ var Chalkboard;
|
|
|
9146
9610
|
return Chalkboard.real.sqrt((vect2.x - vect1.x) * (vect2.x - vect1.x) + (vect2.y - vect1.y) * (vect2.y - vect1.y) + (vect2.z - vect1.z) * (vect2.z - vect1.z));
|
|
9147
9611
|
}
|
|
9148
9612
|
else if (Chalkboard.vect.isDimensionOf(vect1, 4) && Chalkboard.vect.isDimensionOf(vect2, 4)) {
|
|
9149
|
-
return Chalkboard.real.sqrt((vect2.x - vect1.x) * (vect2.x - vect1.x) +
|
|
9150
|
-
(vect2.y - vect1.y) * (vect2.y - vect1.y) +
|
|
9151
|
-
(vect2.z - vect1.z) * (vect2.z - vect1.z) +
|
|
9152
|
-
(vect2.w - vect1.w) * (vect2.w - vect1.w));
|
|
9613
|
+
return Chalkboard.real.sqrt((vect2.x - vect1.x) * (vect2.x - vect1.x) + (vect2.y - vect1.y) * (vect2.y - vect1.y) + (vect2.z - vect1.z) * (vect2.z - vect1.z) + (vect2.w - vect1.w) * (vect2.w - vect1.w));
|
|
9153
9614
|
}
|
|
9154
9615
|
else {
|
|
9155
9616
|
throw new TypeError('Parameters "vect1" and "vect2" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.');
|
|
9156
9617
|
}
|
|
9157
9618
|
};
|
|
9158
9619
|
vect_4.distsq = function (vect1, vect2) {
|
|
9620
|
+
vect1 = $(vect1);
|
|
9621
|
+
vect2 = $(vect2);
|
|
9159
9622
|
if (Chalkboard.vect.isDimensionOf(vect1, 2) && Chalkboard.vect.isDimensionOf(vect2, 2)) {
|
|
9160
9623
|
return (vect2.x - vect1.x) * (vect2.x - vect1.x) + (vect2.y - vect1.y) * (vect2.y - vect1.y);
|
|
9161
9624
|
}
|
|
@@ -9163,16 +9626,15 @@ var Chalkboard;
|
|
|
9163
9626
|
return (vect2.x - vect1.x) * (vect2.x - vect1.x) + (vect2.y - vect1.y) * (vect2.y - vect1.y) + (vect2.z - vect1.z) * (vect2.z - vect1.z);
|
|
9164
9627
|
}
|
|
9165
9628
|
else if (Chalkboard.vect.isDimensionOf(vect1, 4) && Chalkboard.vect.isDimensionOf(vect2, 4)) {
|
|
9166
|
-
return ((vect2.x - vect1.x) * (vect2.x - vect1.x) +
|
|
9167
|
-
(vect2.y - vect1.y) * (vect2.y - vect1.y) +
|
|
9168
|
-
(vect2.z - vect1.z) * (vect2.z - vect1.z) +
|
|
9169
|
-
(vect2.w - vect1.w) * (vect2.w - vect1.w));
|
|
9629
|
+
return ((vect2.x - vect1.x) * (vect2.x - vect1.x) + (vect2.y - vect1.y) * (vect2.y - vect1.y) + (vect2.z - vect1.z) * (vect2.z - vect1.z) + (vect2.w - vect1.w) * (vect2.w - vect1.w));
|
|
9170
9630
|
}
|
|
9171
9631
|
else {
|
|
9172
9632
|
throw new TypeError('Parameters "vect1" and "vect2" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.');
|
|
9173
9633
|
}
|
|
9174
9634
|
};
|
|
9175
9635
|
vect_4.dot = function (vect1, vect2) {
|
|
9636
|
+
vect1 = $(vect1);
|
|
9637
|
+
vect2 = $(vect2);
|
|
9176
9638
|
if (Chalkboard.vect.isDimensionOf(vect1, 2) && Chalkboard.vect.isDimensionOf(vect2, 2)) {
|
|
9177
9639
|
return vect1.x * vect2.x + vect1.y * vect2.y;
|
|
9178
9640
|
}
|
|
@@ -9227,6 +9689,7 @@ var Chalkboard;
|
|
|
9227
9689
|
}
|
|
9228
9690
|
};
|
|
9229
9691
|
vect_4.fromAlternateToCartesian = function (vect, type) {
|
|
9692
|
+
vect = $(vect);
|
|
9230
9693
|
if (type === "polar" && Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9231
9694
|
return Chalkboard.vect.init(vect.x * Chalkboard.trig.cos(vect.y), vect.y * Chalkboard.trig.sin(vect.y));
|
|
9232
9695
|
}
|
|
@@ -9252,6 +9715,7 @@ var Chalkboard;
|
|
|
9252
9715
|
}
|
|
9253
9716
|
};
|
|
9254
9717
|
vect_4.fromCartesianToAlternate = function (vect, type) {
|
|
9718
|
+
vect = $(vect);
|
|
9255
9719
|
if (type === "polar" && Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9256
9720
|
return Chalkboard.vect.init(Chalkboard.vect.mag(vect), Chalkboard.vect.ang(vect));
|
|
9257
9721
|
}
|
|
@@ -9269,6 +9733,7 @@ var Chalkboard;
|
|
|
9269
9733
|
}
|
|
9270
9734
|
};
|
|
9271
9735
|
vect_4.fromField = function (vectfield, vect) {
|
|
9736
|
+
vect = $(vect);
|
|
9272
9737
|
if (Chalkboard.vect.dimension(vectfield) === 2 && Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9273
9738
|
var p = Chalkboard.real.parse("(x, y) => " + vectfield.p), q = Chalkboard.real.parse("(x, y) => " + vectfield.q);
|
|
9274
9739
|
return Chalkboard.vect.init(p(vect.x, vect.y), q(vect.x, vect.y));
|
|
@@ -9286,6 +9751,7 @@ var Chalkboard;
|
|
|
9286
9751
|
}
|
|
9287
9752
|
};
|
|
9288
9753
|
vect_4.fromVector = function (vect) {
|
|
9754
|
+
vect = $(vect);
|
|
9289
9755
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9290
9756
|
return Chalkboard.vect.init(vect.x, vect.y, 0);
|
|
9291
9757
|
}
|
|
@@ -9300,17 +9766,34 @@ var Chalkboard;
|
|
|
9300
9766
|
}
|
|
9301
9767
|
};
|
|
9302
9768
|
vect_4.init = function (x, y, z, w) {
|
|
9769
|
+
var v;
|
|
9303
9770
|
if (z === undefined && w === undefined) {
|
|
9304
|
-
|
|
9771
|
+
v = { x: x, y: y };
|
|
9305
9772
|
}
|
|
9306
9773
|
else if (w === undefined) {
|
|
9307
|
-
|
|
9308
|
-
}
|
|
9309
|
-
else {
|
|
9310
|
-
|
|
9311
|
-
}
|
|
9312
|
-
|
|
9313
|
-
|
|
9774
|
+
v = { x: x, y: y, z: z };
|
|
9775
|
+
}
|
|
9776
|
+
else {
|
|
9777
|
+
v = { x: x, y: y, z: z, w: w };
|
|
9778
|
+
}
|
|
9779
|
+
if (mode === "vector")
|
|
9780
|
+
return v;
|
|
9781
|
+
if (mode === "array")
|
|
9782
|
+
return Chalkboard.vect.toArray(v);
|
|
9783
|
+
if (mode === "float32array")
|
|
9784
|
+
return new Float32Array(Chalkboard.vect.toArray(v));
|
|
9785
|
+
if (mode === "float64array")
|
|
9786
|
+
return new Float64Array(Chalkboard.vect.toArray(v));
|
|
9787
|
+
if (mode === "matrix")
|
|
9788
|
+
return Chalkboard.vect.toMatrix(v);
|
|
9789
|
+
if (mode === "string")
|
|
9790
|
+
return Chalkboard.vect.toString(v);
|
|
9791
|
+
if (mode === "json")
|
|
9792
|
+
return JSON.stringify(v);
|
|
9793
|
+
return v;
|
|
9794
|
+
};
|
|
9795
|
+
vect_4.interpolate = function (vect, a, b, c, d) {
|
|
9796
|
+
vect = $(vect);
|
|
9314
9797
|
if (Chalkboard.vect.isDimensionOf(vect, 2) && typeof c === "undefined" && typeof d === "undefined") {
|
|
9315
9798
|
return Chalkboard.vect.init((a * vect.x + b * vect.y) / (a + b), (a * vect.x + b * vect.y) / (a + b));
|
|
9316
9799
|
}
|
|
@@ -9328,20 +9811,35 @@ var Chalkboard;
|
|
|
9328
9811
|
return Chalkboard.vect.dimension(vect1) === Chalkboard.vect.dimension(vect2);
|
|
9329
9812
|
};
|
|
9330
9813
|
vect_4.isDimensionOf = function (vectORvectfield, dimension) {
|
|
9331
|
-
|
|
9332
|
-
|
|
9333
|
-
|
|
9334
|
-
|
|
9335
|
-
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
|
|
9814
|
+
try {
|
|
9815
|
+
var vect_5 = $(vectORvectfield);
|
|
9816
|
+
if (dimension === 2) {
|
|
9817
|
+
return Chalkboard.vect.dimension(vect_5) === 2;
|
|
9818
|
+
}
|
|
9819
|
+
else if (dimension === 3) {
|
|
9820
|
+
return Chalkboard.vect.dimension(vect_5) === 3;
|
|
9821
|
+
}
|
|
9822
|
+
else if (dimension === 4) {
|
|
9823
|
+
return Chalkboard.vect.dimension(vect_5) === 4;
|
|
9824
|
+
}
|
|
9339
9825
|
}
|
|
9340
|
-
|
|
9341
|
-
|
|
9826
|
+
catch (_a) {
|
|
9827
|
+
var vectfield = vectORvectfield;
|
|
9828
|
+
if (dimension === 2) {
|
|
9829
|
+
return Chalkboard.vect.dimension(vectfield) === 2;
|
|
9830
|
+
}
|
|
9831
|
+
else if (dimension === 3) {
|
|
9832
|
+
return Chalkboard.vect.dimension(vectfield) === 3;
|
|
9833
|
+
}
|
|
9834
|
+
else if (dimension === 4) {
|
|
9835
|
+
return Chalkboard.vect.dimension(vectfield) === 4;
|
|
9836
|
+
}
|
|
9342
9837
|
}
|
|
9838
|
+
throw new TypeError('Parameter "dimension" must be 2, 3, or 4.');
|
|
9343
9839
|
};
|
|
9344
9840
|
vect_4.isEqual = function (vect1, vect2) {
|
|
9841
|
+
vect1 = $(vect1);
|
|
9842
|
+
vect2 = $(vect2);
|
|
9345
9843
|
if (Chalkboard.vect.isDimensionEqual(vect1, vect2)) {
|
|
9346
9844
|
if (Chalkboard.vect.isDimensionOf(vect1, 2)) {
|
|
9347
9845
|
return vect1.x === vect2.x && vect1.y === vect2.y;
|
|
@@ -9370,9 +9868,10 @@ var Chalkboard;
|
|
|
9370
9868
|
return Chalkboard.numb.isApproxEqual(Chalkboard.vect.dot(vect1, vect2), Chalkboard.vect.mag(vect1) * Chalkboard.vect.mag(vect2));
|
|
9371
9869
|
};
|
|
9372
9870
|
vect_4.isZero = function (vect) {
|
|
9373
|
-
return Chalkboard.vect.isEqual(vect, Chalkboard.vect.zero(vect));
|
|
9871
|
+
return Chalkboard.vect.isEqual(vect, Chalkboard.vect.zero(Chalkboard.vect.dimension(vect)));
|
|
9374
9872
|
};
|
|
9375
9873
|
vect_4.mag = function (vect) {
|
|
9874
|
+
vect = $(vect);
|
|
9376
9875
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9377
9876
|
return Chalkboard.real.sqrt(vect.x * vect.x + vect.y * vect.y);
|
|
9378
9877
|
}
|
|
@@ -9390,6 +9889,7 @@ var Chalkboard;
|
|
|
9390
9889
|
return Chalkboard.vect.scl(Chalkboard.vect.normalize(vect), num);
|
|
9391
9890
|
};
|
|
9392
9891
|
vect_4.magsq = function (vect) {
|
|
9892
|
+
vect = $(vect);
|
|
9393
9893
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9394
9894
|
return vect.x * vect.x + vect.y * vect.y;
|
|
9395
9895
|
}
|
|
@@ -9403,7 +9903,16 @@ var Chalkboard;
|
|
|
9403
9903
|
throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.');
|
|
9404
9904
|
}
|
|
9405
9905
|
};
|
|
9906
|
+
var mode = "vector";
|
|
9907
|
+
vect_4.modeConfig = function (config) {
|
|
9908
|
+
var _config = config.toLowerCase();
|
|
9909
|
+
if (["vector", "array", "float32array", "float64array", "matrix", "string", "json"].indexOf(_config) === -1) {
|
|
9910
|
+
throw new Error('The mode must be "vector", "array", "float32array", "float64array", "matrix", "string", or "json".');
|
|
9911
|
+
}
|
|
9912
|
+
mode = _config;
|
|
9913
|
+
};
|
|
9406
9914
|
vect_4.negate = function (vect) {
|
|
9915
|
+
vect = $(vect);
|
|
9407
9916
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9408
9917
|
return Chalkboard.vect.init(-vect.x, -vect.y);
|
|
9409
9918
|
}
|
|
@@ -9418,14 +9927,16 @@ var Chalkboard;
|
|
|
9418
9927
|
}
|
|
9419
9928
|
};
|
|
9420
9929
|
vect_4.normalize = function (vect) {
|
|
9930
|
+
vect = $(vect);
|
|
9931
|
+
var m = Chalkboard.vect.mag(vect);
|
|
9421
9932
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9422
|
-
return Chalkboard.vect.init(vect.x /
|
|
9933
|
+
return Chalkboard.vect.init(vect.x / m, vect.y / m);
|
|
9423
9934
|
}
|
|
9424
9935
|
else if (Chalkboard.vect.isDimensionOf(vect, 3)) {
|
|
9425
|
-
return Chalkboard.vect.init(vect.x /
|
|
9936
|
+
return Chalkboard.vect.init(vect.x / m, vect.y / m, vect.z / m);
|
|
9426
9937
|
}
|
|
9427
9938
|
else if (Chalkboard.vect.isDimensionOf(vect, 4)) {
|
|
9428
|
-
return Chalkboard.vect.init(vect.x /
|
|
9939
|
+
return Chalkboard.vect.init(vect.x / m, vect.y / m, vect.z / m, vect.w / m);
|
|
9429
9940
|
}
|
|
9430
9941
|
else {
|
|
9431
9942
|
throw new TypeError('Parameter "vect" must be of type "ChalkboardVector" with 2, 3, or 4 dimensions.');
|
|
@@ -9440,7 +9951,9 @@ var Chalkboard;
|
|
|
9440
9951
|
vect_4.proj = function (vect1, vect2) {
|
|
9441
9952
|
return Chalkboard.vect.scl(vect2, Chalkboard.vect.dot(vect1, vect2) / Chalkboard.vect.dot(vect2, vect2));
|
|
9442
9953
|
};
|
|
9443
|
-
vect_4.random = function (inf, sup
|
|
9954
|
+
vect_4.random = function (dimension, inf, sup) {
|
|
9955
|
+
if (inf === void 0) { inf = 0; }
|
|
9956
|
+
if (sup === void 0) { sup = 1; }
|
|
9444
9957
|
if (dimension === 2) {
|
|
9445
9958
|
return Chalkboard.vect.init(Chalkboard.numb.random(inf, sup), Chalkboard.numb.random(inf, sup));
|
|
9446
9959
|
}
|
|
@@ -9455,6 +9968,7 @@ var Chalkboard;
|
|
|
9455
9968
|
}
|
|
9456
9969
|
};
|
|
9457
9970
|
vect_4.reciprocate = function (vect) {
|
|
9971
|
+
vect = $(vect);
|
|
9458
9972
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9459
9973
|
return Chalkboard.vect.init(1 / vect.x, 1 / vect.y);
|
|
9460
9974
|
}
|
|
@@ -9482,6 +9996,7 @@ var Chalkboard;
|
|
|
9482
9996
|
}
|
|
9483
9997
|
};
|
|
9484
9998
|
vect_4.round = function (vect) {
|
|
9999
|
+
vect = $(vect);
|
|
9485
10000
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9486
10001
|
return Chalkboard.vect.init(Math.round(vect.x), Math.round(vect.y));
|
|
9487
10002
|
}
|
|
@@ -9502,6 +10017,7 @@ var Chalkboard;
|
|
|
9502
10017
|
return Chalkboard.vect.dot(vect1, Chalkboard.vect.cross(vect2, vect3));
|
|
9503
10018
|
};
|
|
9504
10019
|
vect_4.scl = function (vect, num) {
|
|
10020
|
+
vect = $(vect);
|
|
9505
10021
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9506
10022
|
return Chalkboard.vect.init(vect.x * num, vect.y * num);
|
|
9507
10023
|
}
|
|
@@ -9516,6 +10032,7 @@ var Chalkboard;
|
|
|
9516
10032
|
}
|
|
9517
10033
|
};
|
|
9518
10034
|
vect_4.slope = function (vect) {
|
|
10035
|
+
vect = $(vect);
|
|
9519
10036
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9520
10037
|
return vect.y / vect.x;
|
|
9521
10038
|
}
|
|
@@ -9530,6 +10047,8 @@ var Chalkboard;
|
|
|
9530
10047
|
}
|
|
9531
10048
|
};
|
|
9532
10049
|
vect_4.sub = function (vect1, vect2) {
|
|
10050
|
+
vect1 = $(vect1);
|
|
10051
|
+
vect2 = $(vect2);
|
|
9533
10052
|
if (Chalkboard.vect.isDimensionOf(vect1, 2) && Chalkboard.vect.isDimensionOf(vect2, 2)) {
|
|
9534
10053
|
return Chalkboard.vect.init(vect1.x - vect2.x, vect1.y - vect2.y);
|
|
9535
10054
|
}
|
|
@@ -9544,6 +10063,7 @@ var Chalkboard;
|
|
|
9544
10063
|
}
|
|
9545
10064
|
};
|
|
9546
10065
|
vect_4.toArray = function (vect) {
|
|
10066
|
+
vect = $(vect);
|
|
9547
10067
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9548
10068
|
return [vect.x, vect.y];
|
|
9549
10069
|
}
|
|
@@ -9558,10 +10078,12 @@ var Chalkboard;
|
|
|
9558
10078
|
}
|
|
9559
10079
|
};
|
|
9560
10080
|
vect_4.toComplex = function (vect) {
|
|
10081
|
+
vect = $(vect);
|
|
9561
10082
|
return Chalkboard.comp.init(vect.x, vect.y);
|
|
9562
10083
|
};
|
|
9563
10084
|
vect_4.toMatrix = function (vect, axis) {
|
|
9564
10085
|
if (axis === void 0) { axis = 0; }
|
|
10086
|
+
vect = $(vect);
|
|
9565
10087
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9566
10088
|
if (axis === 0) {
|
|
9567
10089
|
return Chalkboard.matr.init([vect.x], [vect.y]);
|
|
@@ -9600,6 +10122,7 @@ var Chalkboard;
|
|
|
9600
10122
|
}
|
|
9601
10123
|
};
|
|
9602
10124
|
vect_4.toQuaternion = function (vect) {
|
|
10125
|
+
vect = $(vect);
|
|
9603
10126
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9604
10127
|
return Chalkboard.quat.init(vect.x, vect.y, 0, 0);
|
|
9605
10128
|
}
|
|
@@ -9614,6 +10137,7 @@ var Chalkboard;
|
|
|
9614
10137
|
}
|
|
9615
10138
|
};
|
|
9616
10139
|
vect_4.toString = function (vect) {
|
|
10140
|
+
vect = $(vect);
|
|
9617
10141
|
if (Chalkboard.vect.isDimensionOf(vect, 2)) {
|
|
9618
10142
|
return "(" + vect.x.toString() + ", " + vect.y.toString() + ")";
|
|
9619
10143
|
}
|
|
@@ -9633,29 +10157,54 @@ var Chalkboard;
|
|
|
9633
10157
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
9634
10158
|
size[_i - 1] = arguments[_i];
|
|
9635
10159
|
}
|
|
10160
|
+
vect = $(vect);
|
|
9636
10161
|
if (Array.isArray(size[0])) {
|
|
9637
10162
|
size = size[0];
|
|
9638
10163
|
}
|
|
9639
10164
|
return (_a = Chalkboard.tens).resize.apply(_a, __spreadArray([Chalkboard.vect.toMatrix(vect)], size, false));
|
|
9640
10165
|
};
|
|
10166
|
+
vect_4.toTypedArray = function (vect, type) {
|
|
10167
|
+
if (type === void 0) { type = "float32"; }
|
|
10168
|
+
vect = $(vect);
|
|
10169
|
+
var arr = Chalkboard.vect.toArray(vect);
|
|
10170
|
+
if (type === "int8") {
|
|
10171
|
+
return new Int8Array(arr);
|
|
10172
|
+
}
|
|
10173
|
+
else if (type === "int16") {
|
|
10174
|
+
return new Int16Array(arr);
|
|
10175
|
+
}
|
|
10176
|
+
else if (type === "int32") {
|
|
10177
|
+
return new Int32Array(arr);
|
|
10178
|
+
}
|
|
10179
|
+
else if (type === "float32") {
|
|
10180
|
+
return new Float32Array(arr);
|
|
10181
|
+
}
|
|
10182
|
+
else if (type === "float64") {
|
|
10183
|
+
return new Float64Array(arr);
|
|
10184
|
+
}
|
|
10185
|
+
else if (type === "bigint64") {
|
|
10186
|
+
return new BigInt64Array(arr.map(function (n) { return BigInt(Math.floor(n)); }));
|
|
10187
|
+
}
|
|
10188
|
+
throw new TypeError('Parameter "type" must be "int8", "int16", "int32", "float32", "float64", or "bigint64".');
|
|
10189
|
+
};
|
|
9641
10190
|
vect_4.vectorQuadruple = function (vect1, vect2, vect3, vect4) {
|
|
9642
10191
|
return Chalkboard.vect.cross(Chalkboard.vect.cross(vect1, vect2), Chalkboard.vect.cross(vect3, vect4));
|
|
9643
10192
|
};
|
|
9644
10193
|
vect_4.vectorTriple = function (vect1, vect2, vect3) {
|
|
9645
10194
|
return Chalkboard.vect.cross(vect1, Chalkboard.vect.cross(vect2, vect3));
|
|
9646
10195
|
};
|
|
9647
|
-
vect_4.zero = function (
|
|
9648
|
-
if (
|
|
10196
|
+
vect_4.zero = function (dimension) {
|
|
10197
|
+
if (dimension === 2) {
|
|
9649
10198
|
return Chalkboard.vect.init(0, 0);
|
|
9650
10199
|
}
|
|
9651
|
-
else if (
|
|
10200
|
+
else if (dimension === 3) {
|
|
9652
10201
|
return Chalkboard.vect.init(0, 0, 0);
|
|
9653
10202
|
}
|
|
9654
|
-
else if (
|
|
10203
|
+
else if (dimension === 4) {
|
|
9655
10204
|
return Chalkboard.vect.init(0, 0, 0, 0);
|
|
9656
10205
|
}
|
|
9657
10206
|
else {
|
|
9658
|
-
throw new TypeError('Parameter "
|
|
10207
|
+
throw new TypeError('Parameter "dimension" must be either 2, 3, or 4.');
|
|
9659
10208
|
}
|
|
9660
10209
|
};
|
|
9661
10210
|
})(vect = Chalkboard.vect || (Chalkboard.vect = {}));
|