@gkucmierz/utils 3.2.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +4 -3
  2. package/main.mjs +132 -128
  3. package/package.json +6 -2
  4. package/src/{langtons-ant.mjs → automata/langtons-ant.mjs} +4 -0
  5. package/src/{combinations.mjs → combinatorics/combinations.mjs} +4 -0
  6. package/src/{gray-code.mjs → combinatorics/gray-code.mjs} +4 -0
  7. package/src/{n-choose-k.mjs → combinatorics/n-choose-k.mjs} +4 -0
  8. package/src/{permutations.mjs → combinatorics/permutations.mjs} +4 -0
  9. package/src/{SetCnt.mjs → data-structures/SetCnt.mjs} +4 -0
  10. package/src/{Trie.mjs → data-structures/Trie.mjs} +4 -0
  11. package/src/{heap.mjs → data-structures/heap.mjs} +4 -0
  12. package/src/{list-node.mjs → data-structures/list-node.mjs} +4 -0
  13. package/src/{binary-search.mjs → developer-utils/binary-search.mjs} +4 -0
  14. package/src/{consume-iterator.mjs → developer-utils/consume-iterator.mjs} +4 -0
  15. package/src/{get-type.mjs → developer-utils/get-type.mjs} +4 -0
  16. package/src/{measure-performance.mjs → developer-utils/measure-performance.mjs} +4 -0
  17. package/src/{memoize.mjs → developer-utils/memoize.mjs} +4 -0
  18. package/src/{natural-search.mjs → developer-utils/natural-search.mjs} +4 -0
  19. package/src/{rand-normal.mjs → developer-utils/rand-normal.mjs} +4 -0
  20. package/src/{range-array.mjs → developer-utils/range-array.mjs} +4 -0
  21. package/src/{set-safe-interval.mjs → developer-utils/set-safe-interval.mjs} +4 -0
  22. package/src/geometry/barycentric.mjs +23 -0
  23. package/src/{math3d.mjs → geometry/math3d.mjs} +5 -0
  24. package/src/{matrix.mjs → geometry/matrix.mjs} +4 -0
  25. package/src/{egcd.mjs → number-theory/egcd.mjs} +4 -0
  26. package/src/{factors.mjs → number-theory/factors.mjs} +4 -0
  27. package/src/{gcd.mjs → number-theory/gcd.mjs} +4 -0
  28. package/src/{lcm.mjs → number-theory/lcm.mjs} +4 -0
  29. package/src/{lucas-lehmer.mjs → number-theory/lucas-lehmer.mjs} +4 -0
  30. package/src/{mobius.mjs → number-theory/mobius.mjs} +4 -0
  31. package/src/{mod.mjs → number-theory/mod.mjs} +4 -0
  32. package/src/{phi.mjs → number-theory/phi.mjs} +4 -0
  33. package/src/{pow-mod.mjs → number-theory/pow-mod.mjs} +4 -0
  34. package/src/{tonelli-shanks.mjs → number-theory/tonelli-shanks.mjs} +4 -0
  35. package/src/{nelder-mead.mjs → optimization/nelder-mead.mjs} +4 -0
  36. package/src/{particle-swarm.mjs → optimization/particle-swarm.mjs} +4 -0
  37. package/src/{simulated-annealing.mjs → optimization/simulated-annealing.mjs} +4 -0
  38. package/src/{golden-ratio.mjs → sequences/golden-ratio.mjs} +4 -0
  39. package/src/{gpn.mjs → sequences/gpn.mjs} +4 -0
  40. package/src/{herons-formula.mjs → sequences/herons-formula.mjs} +4 -0
  41. package/src/{square-root.mjs → sequences/square-root.mjs} +4 -0
  42. package/src/{array-histogram.mjs → string-arrays/array-histogram.mjs} +4 -0
  43. package/src/{base64.mjs → string-arrays/base64.mjs} +4 -0
  44. package/src/{bijective-numeration.mjs → string-arrays/bijective-numeration.mjs} +4 -0
  45. package/src/{chunks.mjs → string-arrays/chunks.mjs} +5 -0
  46. package/src/{copy-case.mjs → string-arrays/copy-case.mjs} +4 -0
  47. package/src/{format-big-number.mjs → string-arrays/format-big-number.mjs} +4 -0
package/README.md CHANGED
@@ -28,7 +28,6 @@ This library provides a wide range of mathematical functions and data structures
28
28
  - `Trie`: Efficient prefix tree implementation (`class`).
29
29
  - `Heap`: Min-heap priority queue (`class`).
30
30
  - `ListNode`: Linked list node implementation (`class`).
31
- - `matrixAsArray`: 2D matrix representation as a flat array.
32
31
 
33
32
  - **Number Theory**:
34
33
  - `gcd`, `lcm`: Greatest Common Divisor and Least Common Multiple (supports BigInt).
@@ -50,9 +49,10 @@ This library provides a wide range of mathematical functions and data structures
50
49
  - `particleSwarmOptimization`: PSO algorithm for global optimization.
51
50
  - `simulatedAnnealing`: Probabilistic technique for approximating the global optimum of a given function.
52
51
 
53
- - **Math & 3D Geometry**:
52
+ - **Geometry & Math**:
53
+ - `barycentricCoordinates`: Triangle barycentric coordinates computation (supports coordinate arrays).
54
+ - `matrixAsArray`: 2D matrix representation as a flat array.
54
55
  - `math3d`: Utilities for 3D vector and matrix math (`crossProduct`, `dotProduct`, `normalize`, `multiplyMatrix4`, `projectToTrackball`, `getRotationMatrixFromVectors`).
55
- - `randNormal`: Normal (Gaussian) distribution random number generator (Box-Muller transform).
56
56
 
57
57
  - **Automata & Simulation**:
58
58
  - `createLangtonsAnt`, `createUnlimitedGrid`: Infinite 2D grid and Langton's Ant cellular automaton engine (Project Euler 349 compatible).
@@ -66,6 +66,7 @@ This library provides a wide range of mathematical functions and data structures
66
66
  - `formatBigNumber`: Intelligent formatting for massively large numbers with suffixes.
67
67
 
68
68
  - **Developer Utilities**:
69
+ - `randNormal`: Normal (Gaussian) distribution random number generator (Box-Muller transform).
69
70
  - `measurePerformance`: A micro-benchmarking tool for high-iteration performance testing.
70
71
  - `setSafeInterval`: A safe, asynchronous alternative to `setInterval` that prevents overlapping executions and supports immediate yielding.
71
72
  - `consumeIteratorNonBlocking`: Yield consumption macro-tasks queue resolver for heavy computations.
package/main.mjs CHANGED
@@ -1,178 +1,182 @@
1
1
 
2
2
  import {
3
- SetCnt
4
- } from './src/SetCnt.mjs'
5
- import {
6
- Trie
7
- } from './src/Trie.mjs'
8
- import {
9
- arrayHistogram
10
- } from './src/array-histogram.mjs'
11
- import {
12
- fromBase64, fromBase64Url, toBase64, toBase64Url
13
- } from './src/base64.mjs'
3
+ createLangtonsAnt, createUnlimitedGrid
4
+ } from './src/automata/langtons-ant.mjs'
14
5
  import {
15
- bijective2num, bijective2numBI, num2bijective, num2bijectiveBI
16
- } from './src/bijective-numeration.mjs'
6
+ combinations, combinationsIterator
7
+ } from './src/combinatorics/combinations.mjs'
17
8
  import {
18
- binarySearchArr, binarySearchGE, binarySearchLE, binarySearchRangeIncl
19
- } from './src/binary-search.mjs'
9
+ bin2gray, gray2bin
10
+ } from './src/combinatorics/gray-code.mjs'
20
11
  import {
21
- chunks, chunksAsyncIterator, chunksIterator
22
- } from './src/chunks.mjs'
12
+ nChooseK
13
+ } from './src/combinatorics/n-choose-k.mjs'
23
14
  import {
24
- combinations, combinationsIterator
25
- } from './src/combinations.mjs'
15
+ permutations, permutationsIterator
16
+ } from './src/combinatorics/permutations.mjs'
26
17
  import {
27
- consumeIteratorNonBlocking
28
- } from './src/consume-iterator.mjs'
18
+ SetCnt
19
+ } from './src/data-structures/SetCnt.mjs'
29
20
  import {
30
- copyCase
31
- } from './src/copy-case.mjs'
21
+ Trie
22
+ } from './src/data-structures/Trie.mjs'
32
23
  import {
33
- egcd
34
- } from './src/egcd.mjs'
24
+ Heap
25
+ } from './src/data-structures/heap.mjs'
35
26
  import {
36
- factors, factorsBI
37
- } from './src/factors.mjs'
27
+ ListNode
28
+ } from './src/data-structures/list-node.mjs'
38
29
  import {
39
- formatBigNumber, formatBigNumberBI, wrapFn
40
- } from './src/format-big-number.mjs'
30
+ binarySearchArr, binarySearchGE, binarySearchLE, binarySearchRangeIncl
31
+ } from './src/developer-utils/binary-search.mjs'
41
32
  import {
42
- gcd, gcdBI
43
- } from './src/gcd.mjs'
33
+ consumeIteratorNonBlocking
34
+ } from './src/developer-utils/consume-iterator.mjs'
44
35
  import {
45
36
  getType
46
- } from './src/get-type.mjs'
47
- import {
48
- goldenRatio, goldenRatioBI, goldenRatioStr
49
- } from './src/golden-ratio.mjs'
50
- import {
51
- gpn, gpnBI
52
- } from './src/gpn.mjs'
37
+ } from './src/developer-utils/get-type.mjs'
53
38
  import {
54
- bin2gray, gray2bin
55
- } from './src/gray-code.mjs'
39
+ measurePerformance
40
+ } from './src/developer-utils/measure-performance.mjs'
56
41
  import {
57
- Heap
58
- } from './src/heap.mjs'
42
+ memoize
43
+ } from './src/developer-utils/memoize.mjs'
59
44
  import {
60
- heronsFormula, heronsFormulaBI
61
- } from './src/herons-formula.mjs'
45
+ naturalSearch
46
+ } from './src/developer-utils/natural-search.mjs'
62
47
  import {
63
- createLangtonsAnt, createUnlimitedGrid
64
- } from './src/langtons-ant.mjs'
48
+ randNormal
49
+ } from './src/developer-utils/rand-normal.mjs'
65
50
  import {
66
- lcm, lcmBI
67
- } from './src/lcm.mjs'
51
+ array2range, range2array
52
+ } from './src/developer-utils/range-array.mjs'
68
53
  import {
69
- ListNode
70
- } from './src/list-node.mjs'
54
+ setSafeInterval
55
+ } from './src/developer-utils/set-safe-interval.mjs'
71
56
  import {
72
- lucasLehmerBI
73
- } from './src/lucas-lehmer.mjs'
57
+ barycentricCoordinates
58
+ } from './src/geometry/barycentric.mjs'
74
59
  import {
75
60
  axisAngleToMatrix4, crossProduct, dotProduct, getRotationMatrixFromVectors, multiplyMatrix4, normalize, projectToTrackball
76
- } from './src/math3d.mjs'
61
+ } from './src/geometry/math3d.mjs'
77
62
  import {
78
63
  matrixAsArray
79
- } from './src/matrix.mjs'
64
+ } from './src/geometry/matrix.mjs'
80
65
  import {
81
- measurePerformance
82
- } from './src/measure-performance.mjs'
66
+ egcd
67
+ } from './src/number-theory/egcd.mjs'
83
68
  import {
84
- memoize
85
- } from './src/memoize.mjs'
69
+ factors, factorsBI
70
+ } from './src/number-theory/factors.mjs'
71
+ import {
72
+ gcd, gcdBI
73
+ } from './src/number-theory/gcd.mjs'
74
+ import {
75
+ lcm, lcmBI
76
+ } from './src/number-theory/lcm.mjs'
77
+ import {
78
+ lucasLehmerBI
79
+ } from './src/number-theory/lucas-lehmer.mjs'
86
80
  import {
87
81
  mobius, mobiusBI
88
- } from './src/mobius.mjs'
82
+ } from './src/number-theory/mobius.mjs'
89
83
  import {
90
84
  mod, modBI
91
- } from './src/mod.mjs'
85
+ } from './src/number-theory/mod.mjs'
92
86
  import {
93
- nChooseK
94
- } from './src/n-choose-k.mjs'
87
+ phi, phiBI
88
+ } from './src/number-theory/phi.mjs'
95
89
  import {
96
- naturalSearch
97
- } from './src/natural-search.mjs'
90
+ powMod, powModBI
91
+ } from './src/number-theory/pow-mod.mjs'
92
+ import {
93
+ tonelliShanksBI
94
+ } from './src/number-theory/tonelli-shanks.mjs'
98
95
  import {
99
96
  nelderMead
100
- } from './src/nelder-mead.mjs'
97
+ } from './src/optimization/nelder-mead.mjs'
101
98
  import {
102
99
  particleSwarmOptimization
103
- } from './src/particle-swarm.mjs'
100
+ } from './src/optimization/particle-swarm.mjs'
104
101
  import {
105
- permutations, permutationsIterator
106
- } from './src/permutations.mjs'
102
+ simulatedAnnealing
103
+ } from './src/optimization/simulated-annealing.mjs'
107
104
  import {
108
- phi, phiBI
109
- } from './src/phi.mjs'
105
+ goldenRatio, goldenRatioBI, goldenRatioStr
106
+ } from './src/sequences/golden-ratio.mjs'
110
107
  import {
111
- powMod, powModBI
112
- } from './src/pow-mod.mjs'
108
+ gpn, gpnBI
109
+ } from './src/sequences/gpn.mjs'
113
110
  import {
114
- randNormal
115
- } from './src/rand-normal.mjs'
111
+ heronsFormula, heronsFormulaBI
112
+ } from './src/sequences/herons-formula.mjs'
116
113
  import {
117
- array2range, range2array
118
- } from './src/range-array.mjs'
114
+ squareRoot, squareRootBI
115
+ } from './src/sequences/square-root.mjs'
119
116
  import {
120
- setSafeInterval
121
- } from './src/set-safe-interval.mjs'
117
+ arrayHistogram
118
+ } from './src/string-arrays/array-histogram.mjs'
122
119
  import {
123
- simulatedAnnealing
124
- } from './src/simulated-annealing.mjs'
120
+ fromBase64, fromBase64Url, toBase64, toBase64Url
121
+ } from './src/string-arrays/base64.mjs'
125
122
  import {
126
- squareRoot, squareRootBI
127
- } from './src/square-root.mjs'
123
+ bijective2num, bijective2numBI, num2bijective, num2bijectiveBI
124
+ } from './src/string-arrays/bijective-numeration.mjs'
128
125
  import {
129
- tonelliShanksBI
130
- } from './src/tonelli-shanks.mjs'
126
+ chunks, chunksAsyncIterator, chunksIterator
127
+ } from './src/string-arrays/chunks.mjs'
128
+ import {
129
+ copyCase
130
+ } from './src/string-arrays/copy-case.mjs'
131
+ import {
132
+ formatBigNumber, formatBigNumberBI, wrapFn
133
+ } from './src/string-arrays/format-big-number.mjs'
131
134
 
132
- export * from './src/SetCnt.mjs';
133
- export * from './src/Trie.mjs';
134
- export * from './src/array-histogram.mjs';
135
- export * from './src/base64.mjs';
136
- export * from './src/bijective-numeration.mjs';
137
- export * from './src/binary-search.mjs';
138
- export * from './src/chunks.mjs';
139
- export * from './src/combinations.mjs';
140
- export * from './src/consume-iterator.mjs';
141
- export * from './src/copy-case.mjs';
142
- export * from './src/egcd.mjs';
143
- export * from './src/factors.mjs';
144
- export * from './src/format-big-number.mjs';
145
- export * from './src/gcd.mjs';
146
- export * from './src/get-type.mjs';
147
- export * from './src/golden-ratio.mjs';
148
- export * from './src/gpn.mjs';
149
- export * from './src/gray-code.mjs';
150
- export * from './src/heap.mjs';
151
- export * from './src/herons-formula.mjs';
152
- export * from './src/langtons-ant.mjs';
153
- export * from './src/lcm.mjs';
154
- export * from './src/list-node.mjs';
155
- export * from './src/lucas-lehmer.mjs';
156
- export * from './src/math3d.mjs';
157
- export * from './src/matrix.mjs';
158
- export * from './src/measure-performance.mjs';
159
- export * from './src/memoize.mjs';
160
- export * from './src/mobius.mjs';
161
- export * from './src/mod.mjs';
162
- export * from './src/n-choose-k.mjs';
163
- export * from './src/natural-search.mjs';
164
- export * from './src/nelder-mead.mjs';
165
- export * from './src/particle-swarm.mjs';
166
- export * from './src/permutations.mjs';
167
- export * from './src/phi.mjs';
168
- export * from './src/pow-mod.mjs';
169
- export * from './src/rand-normal.mjs';
170
- export * from './src/range-array.mjs';
171
- export * from './src/set-safe-interval.mjs';
172
- export * from './src/simulated-annealing.mjs';
173
- export * from './src/square-root.mjs';
174
- export * from './src/tonelli-shanks.mjs';
135
+ export * from './src/automata/langtons-ant.mjs';
136
+ export * from './src/combinatorics/combinations.mjs';
137
+ export * from './src/combinatorics/gray-code.mjs';
138
+ export * from './src/combinatorics/n-choose-k.mjs';
139
+ export * from './src/combinatorics/permutations.mjs';
140
+ export * from './src/data-structures/SetCnt.mjs';
141
+ export * from './src/data-structures/Trie.mjs';
142
+ export * from './src/data-structures/heap.mjs';
143
+ export * from './src/data-structures/list-node.mjs';
144
+ export * from './src/developer-utils/binary-search.mjs';
145
+ export * from './src/developer-utils/consume-iterator.mjs';
146
+ export * from './src/developer-utils/get-type.mjs';
147
+ export * from './src/developer-utils/measure-performance.mjs';
148
+ export * from './src/developer-utils/memoize.mjs';
149
+ export * from './src/developer-utils/natural-search.mjs';
150
+ export * from './src/developer-utils/rand-normal.mjs';
151
+ export * from './src/developer-utils/range-array.mjs';
152
+ export * from './src/developer-utils/set-safe-interval.mjs';
153
+ export * from './src/geometry/barycentric.mjs';
154
+ export * from './src/geometry/math3d.mjs';
155
+ export * from './src/geometry/matrix.mjs';
156
+ export * from './src/number-theory/egcd.mjs';
157
+ export * from './src/number-theory/factors.mjs';
158
+ export * from './src/number-theory/gcd.mjs';
159
+ export * from './src/number-theory/lcm.mjs';
160
+ export * from './src/number-theory/lucas-lehmer.mjs';
161
+ export * from './src/number-theory/mobius.mjs';
162
+ export * from './src/number-theory/mod.mjs';
163
+ export * from './src/number-theory/phi.mjs';
164
+ export * from './src/number-theory/pow-mod.mjs';
165
+ export * from './src/number-theory/tonelli-shanks.mjs';
166
+ export * from './src/optimization/nelder-mead.mjs';
167
+ export * from './src/optimization/particle-swarm.mjs';
168
+ export * from './src/optimization/simulated-annealing.mjs';
169
+ export * from './src/sequences/golden-ratio.mjs';
170
+ export * from './src/sequences/gpn.mjs';
171
+ export * from './src/sequences/herons-formula.mjs';
172
+ export * from './src/sequences/square-root.mjs';
173
+ export * from './src/string-arrays/array-histogram.mjs';
174
+ export * from './src/string-arrays/base64.mjs';
175
+ export * from './src/string-arrays/bijective-numeration.mjs';
176
+ export * from './src/string-arrays/chunks.mjs';
177
+ export * from './src/string-arrays/copy-case.mjs';
178
+ export * from './src/string-arrays/format-big-number.mjs';
175
179
 
176
180
  export default [
177
- SetCnt, Trie, arrayHistogram, fromBase64, fromBase64Url, toBase64, toBase64Url, bijective2num, bijective2numBI, num2bijective, num2bijectiveBI, binarySearchArr, binarySearchGE, binarySearchLE, binarySearchRangeIncl, chunks, chunksAsyncIterator, chunksIterator, combinations, combinationsIterator, consumeIteratorNonBlocking, copyCase, egcd, factors, factorsBI, formatBigNumber, formatBigNumberBI, wrapFn, gcd, gcdBI, getType, goldenRatio, goldenRatioBI, goldenRatioStr, gpn, gpnBI, bin2gray, gray2bin, Heap, heronsFormula, heronsFormulaBI, createLangtonsAnt, createUnlimitedGrid, lcm, lcmBI, ListNode, lucasLehmerBI, axisAngleToMatrix4, crossProduct, dotProduct, getRotationMatrixFromVectors, multiplyMatrix4, normalize, projectToTrackball, matrixAsArray, measurePerformance, memoize, mobius, mobiusBI, mod, modBI, nChooseK, naturalSearch, nelderMead, particleSwarmOptimization, permutations, permutationsIterator, phi, phiBI, powMod, powModBI, randNormal, array2range, range2array, setSafeInterval, simulatedAnnealing, squareRoot, squareRootBI, tonelliShanksBI
181
+ createLangtonsAnt, createUnlimitedGrid, combinations, combinationsIterator, bin2gray, gray2bin, nChooseK, permutations, permutationsIterator, SetCnt, Trie, Heap, ListNode, binarySearchArr, binarySearchGE, binarySearchLE, binarySearchRangeIncl, consumeIteratorNonBlocking, getType, measurePerformance, memoize, naturalSearch, randNormal, array2range, range2array, setSafeInterval, barycentricCoordinates, axisAngleToMatrix4, crossProduct, dotProduct, getRotationMatrixFromVectors, multiplyMatrix4, normalize, projectToTrackball, matrixAsArray, egcd, factors, factorsBI, gcd, gcdBI, lcm, lcmBI, lucasLehmerBI, mobius, mobiusBI, mod, modBI, phi, phiBI, powMod, powModBI, tonelliShanksBI, nelderMead, particleSwarmOptimization, simulatedAnnealing, goldenRatio, goldenRatioBI, goldenRatioStr, gpn, gpnBI, heronsFormula, heronsFormulaBI, squareRoot, squareRootBI, arrayHistogram, fromBase64, fromBase64Url, toBase64, toBase64Url, bijective2num, bijective2numBI, num2bijective, num2bijectiveBI, chunks, chunksAsyncIterator, chunksIterator, copyCase, formatBigNumber, formatBigNumberBI, wrapFn
178
182
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gkucmierz/utils",
3
- "version": "3.2.0",
3
+ "version": "4.0.1",
4
4
  "type": "module",
5
5
  "description": "Usefull functions for solving programming tasks",
6
6
  "keywords": [
@@ -53,7 +53,11 @@
53
53
  "rand-normal",
54
54
  "format-big-number",
55
55
  "natural-search",
56
- "mobius"
56
+ "mobius",
57
+ "barycentric",
58
+ "barycentric-coordinates",
59
+ "geometry",
60
+ "interpolation"
57
61
  ],
58
62
  "files": [
59
63
  "main.mjs",
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module automata
3
+ */
4
+
1
5
  /**
2
6
  * Creates an unlimited, dynamically expanding 2D grid using nested Maps.
3
7
  * Ideal for sparse matrices or algorithms operating on an infinite plane (e.g., Langton's Ant, Game of Life).
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module combinatorics
3
+ */
4
+
1
5
  /**
2
6
  * Generates all possible combinations of size n from a set of size k without repetition.
3
7
  * Yields arrays of indices representing the current combination.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module combinatorics
3
+ */
4
+
1
5
  /**
2
6
  * Internal logic for toggling bit state based on MSB progression.
3
7
  */
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module combinatorics
3
+ */
4
+
1
5
  /**
2
6
  * Newton's formula (Binomial Coefficient) n choose k.
3
7
  * Evaluates the number of possible combinations.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module combinatorics
3
+ */
4
+
1
5
  /**
2
6
  * Creates a permutations generator from a specified size or an array of elements.
3
7
  *
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module data-structures
3
+ */
4
+
1
5
  /**
2
6
  * Set-like data structure built using Map with elements counter.
3
7
  * Allows adding multiple occurrences of the same element.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module data-structures
3
+ */
4
+
1
5
  /**
2
6
  * Creates a Trie (prefix tree) data structure.
3
7
  * Implemented as a proper ES6 Class to fix prototyping documentation and encapsulate nodes.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module data-structures
3
+ */
4
+
1
5
  /**
2
6
  * Creates a Min Heap data structure.
3
7
  * Implemented as a ES6 Class to fix prototyping documentation
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module data-structures
3
+ */
4
+
1
5
 
2
6
 
3
7
  /**
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module developer-utils
3
+ */
4
+
1
5
 
2
6
  /**
3
7
  * Performs a binary search for an exact element in a sorted array.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module developer-utils
3
+ */
4
+
1
5
  /**
2
6
  * Consume iterator values asynchronously utilizing macro-task queue
3
7
  * to prevent Event Loop blocking.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module developer-utils
3
+ */
4
+
1
5
 
2
6
  /**
3
7
  * Returns the type of the value as a lowercase string.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module developer-utils
3
+ */
4
+
1
5
  /**
2
6
  * Measures the execution time of a given function by running it multiple times.
3
7
  * Useful for micro-benchmarking and performance comparison.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module developer-utils
3
+ */
4
+
1
5
 
2
6
  /**
3
7
  * Creates a memoized version of a function.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module developer-utils
3
+ */
4
+
1
5
  /**
2
6
  * Natural Search Algorithm by gkucmierz
3
7
  * Mathematically finds the exponential boundary and binary searches bounds for a conditional function.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module developer-utils
3
+ */
4
+
1
5
  /**
2
6
  * Generates a random number from a normal (Gaussian) distribution.
3
7
  * Uses the Box-Muller transform.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module developer-utils
3
+ */
4
+
1
5
 
2
6
  // https://www.codewars.com/kata/57d83dfc950d842dcb00005b/train/javascript
3
7
 
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module developer-utils
3
+ */
4
+
1
5
  /**
2
6
  * A safe alternative to setInterval that uses recursive setTimeout.
3
7
  * It waits for the callback (even if it's async) to finish before scheduling the next tick,
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @module geometry
3
+ */
4
+
5
+ /**
6
+ * Calculates the barycentric coordinates of a 2D point P relative to a triangle ABC.
7
+ * @param {Array<number>} p - Point [x, y]
8
+ * @param {Array<number>} a - Vertex A [x, y]
9
+ * @param {Array<number>} b - Vertex B [x, y]
10
+ * @param {Array<number>} c - Vertex C [x, y]
11
+ * @returns {Array<number>} [l1, l2, l3] barycentric coordinates summing to 1
12
+ * @see {@link https://instacode.app/run/FASwtgDg9gTgLgAgN4IEYEMYE8DGBTAOzhhBwGEpYATEA9OPAZwQF8EAzGKMBAIgAEA5gGsArjjAg8MAF4B6UXBAAbRrwDcwYBmz4iJcpRg06DRpqA|▶ Try it live in Instacode}
13
+ */
14
+ export const barycentricCoordinates = (p, a, b, c) => {
15
+ const det = (b[1] - c[1]) * (a[0] - c[0]) + (c[0] - b[0]) * (a[1] - c[1]);
16
+ if (Math.abs(det) < 1e-9) {
17
+ return [1/3, 1/3, 1/3]; // Fallback for collinear vertices
18
+ }
19
+ const l1 = ((b[1] - c[1]) * (p[0] - c[0]) + (c[0] - b[0]) * (p[1] - c[1])) / det;
20
+ const l2 = ((c[1] - a[1]) * (p[0] - c[0]) + (a[0] - c[0]) * (p[1] - c[1])) / det;
21
+ const l3 = 1 - l1 - l2;
22
+ return [l1, l2, l3];
23
+ };
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module geometry
3
+ */
4
+
1
5
  /**
2
6
  * Pure 3D Math Engine for Arcball/Trackball raw matrix transformations
3
7
  * @see {@link https://instacode.app/run/FASwtgDg9gTgLgAgN4IMYygZ0wBQwEwFdVEBfBAMwzAQCIABAcwGtiwQBTGALwHpC4IADaZaAbmDB0WXAWJwJQA|▶ Try it live in Instacode}
@@ -65,3 +69,4 @@ export const getRotationMatrixFromVectors = (u, v) => {
65
69
  const angle = Math.acos(Math.max(-1, Math.min(1, dot)));
66
70
  return axisAngleToMatrix4(axis, angle);
67
71
  };
72
+
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module geometry
3
+ */
4
+
1
5
 
2
6
 
3
7
  /**
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module number-theory
3
+ */
4
+
1
5
 
2
6
  /**
3
7
  * Extended Euclidean Algorithm.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module number-theory
3
+ */
4
+
1
5
 
2
6
  /**
3
7
  * Calculates the prime factorization of a number.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module number-theory
3
+ */
4
+
1
5
 
2
6
  const getGCD = ZERO => {
3
7
  return (a, b) => {
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module number-theory
3
+ */
4
+
1
5
 
2
6
  import {
3
7
  gcd,
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module number-theory
3
+ */
4
+
1
5
  /**
2
6
  * Calculates whether a given Mersenne number (2^p - 1) is prime using the Lucas-Lehmer primality test.
3
7
  *
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module number-theory
3
+ */
4
+
1
5
  import { factors, factorsBI } from './factors.mjs';
2
6
 
3
7
  /**
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module number-theory
3
+ */
4
+
1
5
 
2
6
  const getMod = ZERO => {
3
7
  return (dividend, divisor) => {
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module number-theory
3
+ */
4
+
1
5
 
2
6
  import {
3
7
  gcd,
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module number-theory
3
+ */
4
+
1
5
 
2
6
  // implementation of power function with modulus like native python pow
3
7
 
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module number-theory
3
+ */
4
+
1
5
 
2
6
  import {
3
7
  powModBI,
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module optimization
3
+ */
4
+
1
5
  /**
2
6
  * Nelder-Mead Simplex Algorithm (Direct Search Gradient-Free Optimization)
3
7
  * Maximizes continuous N-dimensional spaces through contraction and expansion.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module optimization
3
+ */
4
+
1
5
  /**
2
6
  * Particle Swarm Optimization (PSO)
3
7
  * A stochastic, population-based metaheuristic for maximizing complex multidimensional bounds.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module optimization
3
+ */
4
+
1
5
  /**
2
6
  * Simulated Annealing (Derivative-Free Stochastic Optimization)
3
7
  * Maximizes the evaluate function payload.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module sequences
3
+ */
4
+
1
5
  import { squareRootBI } from './square-root.mjs';
2
6
 
3
7
  /**
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module sequences
3
+ */
4
+
1
5
 
2
6
  // Generalized pentagonal numbers
3
7
  // https://oeis.org/A001318
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module sequences
3
+ */
4
+
1
5
 
2
6
  import {
3
7
  squareRootBI,
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module sequences
3
+ */
4
+
1
5
 
2
6
 
3
7
  /**
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module string-arrays
3
+ */
4
+
1
5
  /**
2
6
  * Generates a Map with unique elements and their occurring frequencies.
3
7
  * Transforms an array into a Map of (key -> quantity) using an optional mapping callback.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module string-arrays
3
+ */
4
+
1
5
 
2
6
  /**
3
7
  * Encodes a string to Base64.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module string-arrays
3
+ */
4
+
1
5
 
2
6
  /**
3
7
  * Converts a number to a bijective base-k string.
@@ -1,3 +1,8 @@
1
+ /**
2
+ * @module string-arrays
3
+ * @see {@link https://instacode.app/run/FASwtgDg9gTgLgAgN4IMYAsCuA7A1gZwQF8EAzGKMBAIgAEBzXTVMEAUxgC8B6TOEADb5qAbmDAMOAmKA|▶ Try it live in Instacode}
4
+ */
5
+
1
6
  export const chunks = (input, size = 1) => {
2
7
  if (size < 1) size = 1;
3
8
 
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module string-arrays
3
+ */
4
+
1
5
 
2
6
  /**
3
7
  * Copies the case pattern from one string to another.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @module string-arrays
3
+ */
4
+
1
5
 
2
6
  /**
3
7
  * Formats a BigNumber, Number or string representation of a number