@gkucmierz/utils 3.1.0 → 4.0.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/README.md +4 -3
- package/main.mjs +133 -125
- package/package.json +7 -2
- package/src/geometry/barycentric.mjs +19 -0
- package/src/{math3d.mjs → geometry/math3d.mjs} +1 -0
- package/src/number-theory/mobius.mjs +31 -0
- /package/src/{langtons-ant.mjs → automata/langtons-ant.mjs} +0 -0
- /package/src/{combinations.mjs → combinatorics/combinations.mjs} +0 -0
- /package/src/{gray-code.mjs → combinatorics/gray-code.mjs} +0 -0
- /package/src/{n-choose-k.mjs → combinatorics/n-choose-k.mjs} +0 -0
- /package/src/{permutations.mjs → combinatorics/permutations.mjs} +0 -0
- /package/src/{SetCnt.mjs → data-structures/SetCnt.mjs} +0 -0
- /package/src/{Trie.mjs → data-structures/Trie.mjs} +0 -0
- /package/src/{heap.mjs → data-structures/heap.mjs} +0 -0
- /package/src/{list-node.mjs → data-structures/list-node.mjs} +0 -0
- /package/src/{binary-search.mjs → developer-utils/binary-search.mjs} +0 -0
- /package/src/{consume-iterator.mjs → developer-utils/consume-iterator.mjs} +0 -0
- /package/src/{get-type.mjs → developer-utils/get-type.mjs} +0 -0
- /package/src/{measure-performance.mjs → developer-utils/measure-performance.mjs} +0 -0
- /package/src/{memoize.mjs → developer-utils/memoize.mjs} +0 -0
- /package/src/{natural-search.mjs → developer-utils/natural-search.mjs} +0 -0
- /package/src/{rand-normal.mjs → developer-utils/rand-normal.mjs} +0 -0
- /package/src/{range-array.mjs → developer-utils/range-array.mjs} +0 -0
- /package/src/{set-safe-interval.mjs → developer-utils/set-safe-interval.mjs} +0 -0
- /package/src/{matrix.mjs → geometry/matrix.mjs} +0 -0
- /package/src/{egcd.mjs → number-theory/egcd.mjs} +0 -0
- /package/src/{factors.mjs → number-theory/factors.mjs} +0 -0
- /package/src/{gcd.mjs → number-theory/gcd.mjs} +0 -0
- /package/src/{lcm.mjs → number-theory/lcm.mjs} +0 -0
- /package/src/{lucas-lehmer.mjs → number-theory/lucas-lehmer.mjs} +0 -0
- /package/src/{mod.mjs → number-theory/mod.mjs} +0 -0
- /package/src/{phi.mjs → number-theory/phi.mjs} +0 -0
- /package/src/{pow-mod.mjs → number-theory/pow-mod.mjs} +0 -0
- /package/src/{tonelli-shanks.mjs → number-theory/tonelli-shanks.mjs} +0 -0
- /package/src/{nelder-mead.mjs → optimization/nelder-mead.mjs} +0 -0
- /package/src/{particle-swarm.mjs → optimization/particle-swarm.mjs} +0 -0
- /package/src/{simulated-annealing.mjs → optimization/simulated-annealing.mjs} +0 -0
- /package/src/{golden-ratio.mjs → sequences/golden-ratio.mjs} +0 -0
- /package/src/{gpn.mjs → sequences/gpn.mjs} +0 -0
- /package/src/{herons-formula.mjs → sequences/herons-formula.mjs} +0 -0
- /package/src/{square-root.mjs → sequences/square-root.mjs} +0 -0
- /package/src/{array-histogram.mjs → string-arrays/array-histogram.mjs} +0 -0
- /package/src/{base64.mjs → string-arrays/base64.mjs} +0 -0
- /package/src/{bijective-numeration.mjs → string-arrays/bijective-numeration.mjs} +0 -0
- /package/src/{chunks.mjs → string-arrays/chunks.mjs} +0 -0
- /package/src/{copy-case.mjs → string-arrays/copy-case.mjs} +0 -0
- /package/src/{format-big-number.mjs → string-arrays/format-big-number.mjs} +0 -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
|
-
- **
|
|
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,174 +1,182 @@
|
|
|
1
1
|
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from './src/
|
|
5
|
-
import {
|
|
6
|
-
Trie
|
|
7
|
-
} from './src/Trie.mjs'
|
|
3
|
+
createLangtonsAnt, createUnlimitedGrid
|
|
4
|
+
} from './src/automata/langtons-ant.mjs'
|
|
8
5
|
import {
|
|
9
|
-
|
|
10
|
-
} from './src/
|
|
6
|
+
combinations, combinationsIterator
|
|
7
|
+
} from './src/combinatorics/combinations.mjs'
|
|
11
8
|
import {
|
|
12
|
-
|
|
13
|
-
} from './src/
|
|
9
|
+
bin2gray, gray2bin
|
|
10
|
+
} from './src/combinatorics/gray-code.mjs'
|
|
14
11
|
import {
|
|
15
|
-
|
|
16
|
-
} from './src/
|
|
12
|
+
nChooseK
|
|
13
|
+
} from './src/combinatorics/n-choose-k.mjs'
|
|
17
14
|
import {
|
|
18
|
-
|
|
19
|
-
} from './src/
|
|
15
|
+
permutations, permutationsIterator
|
|
16
|
+
} from './src/combinatorics/permutations.mjs'
|
|
20
17
|
import {
|
|
21
|
-
|
|
22
|
-
} from './src/
|
|
18
|
+
SetCnt
|
|
19
|
+
} from './src/data-structures/SetCnt.mjs'
|
|
23
20
|
import {
|
|
24
|
-
|
|
25
|
-
} from './src/
|
|
21
|
+
Trie
|
|
22
|
+
} from './src/data-structures/Trie.mjs'
|
|
26
23
|
import {
|
|
27
|
-
|
|
28
|
-
} from './src/
|
|
24
|
+
Heap
|
|
25
|
+
} from './src/data-structures/heap.mjs'
|
|
29
26
|
import {
|
|
30
|
-
|
|
31
|
-
} from './src/
|
|
27
|
+
ListNode
|
|
28
|
+
} from './src/data-structures/list-node.mjs'
|
|
32
29
|
import {
|
|
33
|
-
|
|
34
|
-
} from './src/
|
|
30
|
+
binarySearchArr, binarySearchGE, binarySearchLE, binarySearchRangeIncl
|
|
31
|
+
} from './src/developer-utils/binary-search.mjs'
|
|
35
32
|
import {
|
|
36
|
-
|
|
37
|
-
} from './src/
|
|
33
|
+
consumeIteratorNonBlocking
|
|
34
|
+
} from './src/developer-utils/consume-iterator.mjs'
|
|
38
35
|
import {
|
|
39
|
-
|
|
40
|
-
} from './src/
|
|
36
|
+
getType
|
|
37
|
+
} from './src/developer-utils/get-type.mjs'
|
|
41
38
|
import {
|
|
42
|
-
|
|
43
|
-
} from './src/
|
|
39
|
+
measurePerformance
|
|
40
|
+
} from './src/developer-utils/measure-performance.mjs'
|
|
44
41
|
import {
|
|
45
|
-
|
|
46
|
-
} from './src/
|
|
42
|
+
memoize
|
|
43
|
+
} from './src/developer-utils/memoize.mjs'
|
|
47
44
|
import {
|
|
48
|
-
|
|
49
|
-
} from './src/
|
|
45
|
+
naturalSearch
|
|
46
|
+
} from './src/developer-utils/natural-search.mjs'
|
|
50
47
|
import {
|
|
51
|
-
|
|
52
|
-
} from './src/
|
|
48
|
+
randNormal
|
|
49
|
+
} from './src/developer-utils/rand-normal.mjs'
|
|
53
50
|
import {
|
|
54
|
-
|
|
55
|
-
} from './src/
|
|
51
|
+
array2range, range2array
|
|
52
|
+
} from './src/developer-utils/range-array.mjs'
|
|
56
53
|
import {
|
|
57
|
-
|
|
58
|
-
} from './src/
|
|
54
|
+
setSafeInterval
|
|
55
|
+
} from './src/developer-utils/set-safe-interval.mjs'
|
|
59
56
|
import {
|
|
60
|
-
|
|
61
|
-
} from './src/
|
|
57
|
+
barycentricCoordinates
|
|
58
|
+
} from './src/geometry/barycentric.mjs'
|
|
62
59
|
import {
|
|
63
|
-
|
|
64
|
-
} from './src/
|
|
60
|
+
axisAngleToMatrix4, crossProduct, dotProduct, getRotationMatrixFromVectors, multiplyMatrix4, normalize, projectToTrackball
|
|
61
|
+
} from './src/geometry/math3d.mjs'
|
|
65
62
|
import {
|
|
66
|
-
|
|
67
|
-
} from './src/
|
|
63
|
+
matrixAsArray
|
|
64
|
+
} from './src/geometry/matrix.mjs'
|
|
68
65
|
import {
|
|
69
|
-
|
|
70
|
-
} from './src/
|
|
66
|
+
egcd
|
|
67
|
+
} from './src/number-theory/egcd.mjs'
|
|
71
68
|
import {
|
|
72
|
-
|
|
73
|
-
} from './src/
|
|
69
|
+
factors, factorsBI
|
|
70
|
+
} from './src/number-theory/factors.mjs'
|
|
74
71
|
import {
|
|
75
|
-
|
|
76
|
-
} from './src/
|
|
72
|
+
gcd, gcdBI
|
|
73
|
+
} from './src/number-theory/gcd.mjs'
|
|
77
74
|
import {
|
|
78
|
-
|
|
79
|
-
} from './src/
|
|
75
|
+
lcm, lcmBI
|
|
76
|
+
} from './src/number-theory/lcm.mjs'
|
|
80
77
|
import {
|
|
81
|
-
|
|
82
|
-
} from './src/
|
|
78
|
+
lucasLehmerBI
|
|
79
|
+
} from './src/number-theory/lucas-lehmer.mjs'
|
|
83
80
|
import {
|
|
84
|
-
|
|
85
|
-
} from './src/
|
|
81
|
+
mobius, mobiusBI
|
|
82
|
+
} from './src/number-theory/mobius.mjs'
|
|
86
83
|
import {
|
|
87
84
|
mod, modBI
|
|
88
|
-
} from './src/mod.mjs'
|
|
85
|
+
} from './src/number-theory/mod.mjs'
|
|
89
86
|
import {
|
|
90
|
-
|
|
91
|
-
} from './src/
|
|
87
|
+
phi, phiBI
|
|
88
|
+
} from './src/number-theory/phi.mjs'
|
|
92
89
|
import {
|
|
93
|
-
|
|
94
|
-
} from './src/
|
|
90
|
+
powMod, powModBI
|
|
91
|
+
} from './src/number-theory/pow-mod.mjs'
|
|
92
|
+
import {
|
|
93
|
+
tonelliShanksBI
|
|
94
|
+
} from './src/number-theory/tonelli-shanks.mjs'
|
|
95
95
|
import {
|
|
96
96
|
nelderMead
|
|
97
|
-
} from './src/nelder-mead.mjs'
|
|
97
|
+
} from './src/optimization/nelder-mead.mjs'
|
|
98
98
|
import {
|
|
99
99
|
particleSwarmOptimization
|
|
100
|
-
} from './src/particle-swarm.mjs'
|
|
100
|
+
} from './src/optimization/particle-swarm.mjs'
|
|
101
101
|
import {
|
|
102
|
-
|
|
103
|
-
} from './src/
|
|
102
|
+
simulatedAnnealing
|
|
103
|
+
} from './src/optimization/simulated-annealing.mjs'
|
|
104
104
|
import {
|
|
105
|
-
|
|
106
|
-
} from './src/
|
|
105
|
+
goldenRatio, goldenRatioBI, goldenRatioStr
|
|
106
|
+
} from './src/sequences/golden-ratio.mjs'
|
|
107
107
|
import {
|
|
108
|
-
|
|
109
|
-
} from './src/
|
|
108
|
+
gpn, gpnBI
|
|
109
|
+
} from './src/sequences/gpn.mjs'
|
|
110
110
|
import {
|
|
111
|
-
|
|
112
|
-
} from './src/
|
|
111
|
+
heronsFormula, heronsFormulaBI
|
|
112
|
+
} from './src/sequences/herons-formula.mjs'
|
|
113
113
|
import {
|
|
114
|
-
|
|
115
|
-
} from './src/
|
|
114
|
+
squareRoot, squareRootBI
|
|
115
|
+
} from './src/sequences/square-root.mjs'
|
|
116
116
|
import {
|
|
117
|
-
|
|
118
|
-
} from './src/
|
|
117
|
+
arrayHistogram
|
|
118
|
+
} from './src/string-arrays/array-histogram.mjs'
|
|
119
119
|
import {
|
|
120
|
-
|
|
121
|
-
} from './src/
|
|
120
|
+
fromBase64, fromBase64Url, toBase64, toBase64Url
|
|
121
|
+
} from './src/string-arrays/base64.mjs'
|
|
122
122
|
import {
|
|
123
|
-
|
|
124
|
-
} from './src/
|
|
123
|
+
bijective2num, bijective2numBI, num2bijective, num2bijectiveBI
|
|
124
|
+
} from './src/string-arrays/bijective-numeration.mjs'
|
|
125
125
|
import {
|
|
126
|
-
|
|
127
|
-
} from './src/
|
|
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'
|
|
128
134
|
|
|
129
|
-
export * from './src/
|
|
130
|
-
export * from './src/
|
|
131
|
-
export * from './src/
|
|
132
|
-
export * from './src/
|
|
133
|
-
export * from './src/
|
|
134
|
-
export * from './src/
|
|
135
|
-
export * from './src/
|
|
136
|
-
export * from './src/
|
|
137
|
-
export * from './src/
|
|
138
|
-
export * from './src/
|
|
139
|
-
export * from './src/
|
|
140
|
-
export * from './src/
|
|
141
|
-
export * from './src/
|
|
142
|
-
export * from './src/
|
|
143
|
-
export * from './src/
|
|
144
|
-
export * from './src/
|
|
145
|
-
export * from './src/
|
|
146
|
-
export * from './src/
|
|
147
|
-
export * from './src/
|
|
148
|
-
export * from './src/
|
|
149
|
-
export * from './src/
|
|
150
|
-
export * from './src/
|
|
151
|
-
export * from './src/
|
|
152
|
-
export * from './src/
|
|
153
|
-
export * from './src/
|
|
154
|
-
export * from './src/
|
|
155
|
-
export * from './src/
|
|
156
|
-
export * from './src/
|
|
157
|
-
export * from './src/
|
|
158
|
-
export * from './src/
|
|
159
|
-
export * from './src/
|
|
160
|
-
export * from './src/nelder-mead.mjs';
|
|
161
|
-
export * from './src/particle-swarm.mjs';
|
|
162
|
-
export * from './src/
|
|
163
|
-
export * from './src/
|
|
164
|
-
export * from './src/
|
|
165
|
-
export * from './src/
|
|
166
|
-
export * from './src/
|
|
167
|
-
export * from './src/
|
|
168
|
-
export * from './src/
|
|
169
|
-
export * from './src/
|
|
170
|
-
export * from './src/
|
|
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';
|
|
171
179
|
|
|
172
180
|
export default [
|
|
173
|
-
|
|
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
|
|
174
182
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gkucmierz/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Usefull functions for solving programming tasks",
|
|
6
6
|
"keywords": [
|
|
@@ -52,7 +52,12 @@
|
|
|
52
52
|
"simulated-annealing",
|
|
53
53
|
"rand-normal",
|
|
54
54
|
"format-big-number",
|
|
55
|
-
"natural-search"
|
|
55
|
+
"natural-search",
|
|
56
|
+
"mobius",
|
|
57
|
+
"barycentric",
|
|
58
|
+
"barycentric-coordinates",
|
|
59
|
+
"geometry",
|
|
60
|
+
"interpolation"
|
|
56
61
|
],
|
|
57
62
|
"files": [
|
|
58
63
|
"main.mjs",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the barycentric coordinates of a 2D point P relative to a triangle ABC.
|
|
3
|
+
* @param {Array<number>} p - Point [x, y]
|
|
4
|
+
* @param {Array<number>} a - Vertex A [x, y]
|
|
5
|
+
* @param {Array<number>} b - Vertex B [x, y]
|
|
6
|
+
* @param {Array<number>} c - Vertex C [x, y]
|
|
7
|
+
* @returns {Array<number>} [l1, l2, l3] barycentric coordinates summing to 1
|
|
8
|
+
* @see {@link https://instacode.app/run/FASwtgDg9gTgLgAgN4IEYEMYE8DGBTAOzhhBwGEpYATEA9OPAZwQF8EAzGKMBAIgAEA5gGsArjjAg8MAF4B6UXBAAbRrwDcwYBmz4iJcpRg06DRpqA|▶ Try it live in Instacode}
|
|
9
|
+
*/
|
|
10
|
+
export const barycentricCoordinates = (p, a, b, c) => {
|
|
11
|
+
const det = (b[1] - c[1]) * (a[0] - c[0]) + (c[0] - b[0]) * (a[1] - c[1]);
|
|
12
|
+
if (Math.abs(det) < 1e-9) {
|
|
13
|
+
return [1/3, 1/3, 1/3]; // Fallback for collinear vertices
|
|
14
|
+
}
|
|
15
|
+
const l1 = ((b[1] - c[1]) * (p[0] - c[0]) + (c[0] - b[0]) * (p[1] - c[1])) / det;
|
|
16
|
+
const l2 = ((c[1] - a[1]) * (p[0] - c[0]) + (a[0] - c[0]) * (p[1] - c[1])) / det;
|
|
17
|
+
const l3 = 1 - l1 - l2;
|
|
18
|
+
return [l1, l2, l3];
|
|
19
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { factors, factorsBI } from './factors.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calculates the Mobius function μ(n) of a number.
|
|
5
|
+
* @param {number} n - A positive integer.
|
|
6
|
+
* @returns {number} The Mobius function value (1, -1, or 0).
|
|
7
|
+
* @see {@link https://instacode.app/run/FASwtgDg9gTgLgAgN4LFARiArgZwQXwQDMYowEAiAAQHMBrLAYzBAFMYAvAeizhABscFANzBgaTLlFA|▶ Try it live in Instacode}
|
|
8
|
+
*/
|
|
9
|
+
export const mobius = n => {
|
|
10
|
+
if (n < 1) return 0;
|
|
11
|
+
if (n === 1) return 1;
|
|
12
|
+
const f = factors(n);
|
|
13
|
+
const unique = new Set(f);
|
|
14
|
+
if (unique.size !== f.length) return 0;
|
|
15
|
+
return f.length % 2 === 0 ? 1 : -1;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Calculates the Mobius function μ(n) of a BigInt.
|
|
20
|
+
* @param {bigint} n - A positive BigInt.
|
|
21
|
+
* @returns {number} The Mobius function value (1, -1, or 0).
|
|
22
|
+
* @see {@link https://instacode.app/run/FASwtgDg9gTgLgAgN4LFARiArgZwEICSCAvggGYxRgIBEAAgOYDWWAxmCAKYwBeA9FjggANjhoBuYMDSZchSUA|▶ Try it live in Instacode}
|
|
23
|
+
*/
|
|
24
|
+
export const mobiusBI = n => {
|
|
25
|
+
if (n < 1n) return 0;
|
|
26
|
+
if (n === 1n) return 1;
|
|
27
|
+
const f = factorsBI(n);
|
|
28
|
+
const unique = new Set(f);
|
|
29
|
+
if (unique.size !== f.length) return 0;
|
|
30
|
+
return f.length % 2 === 0 ? 1 : -1;
|
|
31
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|