@eturnity/eturnity_maths 7.20.0 → 7.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +28 -0
- package/.prettierrc +7 -0
- package/babel.config.js +2 -2
- package/eslint.config.mjs +10 -0
- package/package.json +5 -3
- package/src/config.js +110 -50
- package/src/coords.js +21 -21
- package/src/geo.js +111 -100
- package/src/geometry.js +920 -819
- package/src/index.js +10 -11
- package/src/intersectionPolygon.js +34 -28
- package/src/lib/concaveman.js +181 -181
- package/src/matrix.js +56 -50
- package/src/miscellaneous.js +45 -0
- package/src/objects/Circle.js +76 -41
- package/src/objects/Line.js +275 -177
- package/src/objects/Point.js +30 -27
- package/src/objects/Polygon.js +324 -243
- package/src/objects/derivedState/AddMargin.js +142 -145
- package/src/objects/derivedState/updateComputedGeometryPolygon.js +274 -253
- package/src/objects/graph/DFS.js +69 -69
- package/src/objects/graph/graphCreation.js +47 -44
- package/src/objects/hydrate.js +26 -26
- package/src/snap.js +24 -18
- package/src/splitMergePolygons.js +585 -521
- package/src/test/maths.test.js +7 -7
- package/src/vector.js +66 -66
package/src/test/maths.test.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { deltaLatLngToDistance,distanceToDeltaLatLng } from
|
|
1
|
+
import { deltaLatLngToDistance, distanceToDeltaLatLng } from '../index'
|
|
2
2
|
|
|
3
3
|
test('deltaLatLngToDistance is inverse of distanceToDeltaLatLng x', () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
let { lat, lng } = distanceToDeltaLatLng(1000, 2000, 45)
|
|
5
|
+
expect(deltaLatLngToDistance(lat, lng, 45).x).toBe(1000)
|
|
6
|
+
})
|
|
7
7
|
test('deltaLatLngToDistance is inverse of distanceToDeltaLatLng y', () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
let { lat, lng } = distanceToDeltaLatLng(1000, 2000, 45)
|
|
9
|
+
expect(deltaLatLngToDistance(lat, lng, 45).y).toBe(2000)
|
|
10
|
+
})
|
package/src/vector.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
1
|
export function addVector(u, v) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
const result = {}
|
|
3
|
+
result.x = u.x + v.x
|
|
4
|
+
result.y = u.y + v.y
|
|
5
|
+
result.z = u.z + v.z
|
|
6
|
+
return result
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function substractVector(u, v) {
|
|
10
|
+
const result = {}
|
|
11
|
+
result.x = u.x - v.x
|
|
12
|
+
result.y = u.y - v.y
|
|
13
|
+
result.z = u.z - v.z
|
|
14
|
+
return result
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function multiplyVector(lambda, u) {
|
|
18
|
+
const result = {}
|
|
19
|
+
result.x = u.x * lambda
|
|
20
|
+
result.y = u.y * lambda
|
|
21
|
+
result.z = u.z * lambda
|
|
22
|
+
return result
|
|
23
|
+
}
|
|
24
|
+
export function dotProduct(u, v) {
|
|
25
|
+
const result = u.x * v.x + u.y * v.y + u.z * v.z
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
export function areCollinear(u, v) {
|
|
29
|
+
return vectorLength(crossProduct(u, v)) == 0
|
|
30
|
+
}
|
|
31
|
+
export function areAlmostCollinear(u, v, tolerance) {
|
|
32
|
+
return vectorLength(crossProduct(u, v)) < tolerance
|
|
33
|
+
}
|
|
34
|
+
export function crossProduct(u, v) {
|
|
35
|
+
const result = {}
|
|
36
|
+
result.x = u.y * v.z - u.z * v.y
|
|
37
|
+
result.y = u.z * v.x - u.x * v.z
|
|
38
|
+
result.z = u.x * v.y - u.y * v.x
|
|
39
|
+
return result
|
|
40
|
+
}
|
|
41
|
+
export function meanVector(listVector) {
|
|
42
|
+
let meanPoint = {}
|
|
43
|
+
let sumPoint = { x: 0, y: 0, z: 0 }
|
|
44
|
+
listVector.forEach((p) => {
|
|
45
|
+
sumPoint = addVector(sumPoint, p)
|
|
46
|
+
})
|
|
47
|
+
meanPoint = multiplyVector(1 / listVector.length, sumPoint)
|
|
48
|
+
return meanPoint
|
|
49
|
+
}
|
|
50
|
+
export function vectorLength(v) {
|
|
51
|
+
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z)
|
|
52
|
+
}
|
|
53
|
+
export function vectorLength2D(v) {
|
|
54
|
+
return Math.sqrt(v.x * v.x + v.y * v.y)
|
|
55
|
+
}
|
|
56
|
+
export function normalizeVector(v) {
|
|
57
|
+
let length = vectorLength(v)
|
|
58
|
+
if (length == 0) {
|
|
59
|
+
return v
|
|
7
60
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return result
|
|
61
|
+
return multiplyVector(1 / length, v)
|
|
62
|
+
}
|
|
63
|
+
export function normalize2DVector(v) {
|
|
64
|
+
let length = vectorLength2D(v)
|
|
65
|
+
if (length == 0) {
|
|
66
|
+
return v
|
|
15
67
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const result = {}
|
|
19
|
-
result.x = u.x * lambda
|
|
20
|
-
result.y = u.y * lambda
|
|
21
|
-
result.z = u.z * lambda
|
|
22
|
-
return result
|
|
23
|
-
}
|
|
24
|
-
export function dotProduct(u, v) {
|
|
25
|
-
const result = u.x * v.x + u.y * v.y + u.z * v.z
|
|
26
|
-
return result
|
|
27
|
-
}
|
|
28
|
-
export function areCollinear(u,v){
|
|
29
|
-
return vectorLength(crossProduct(u,v)) == 0
|
|
30
|
-
}
|
|
31
|
-
export function areAlmostCollinear(u,v,tolerance){
|
|
32
|
-
return vectorLength(crossProduct(u,v)) < tolerance
|
|
33
|
-
}
|
|
34
|
-
export function crossProduct(u, v) {
|
|
35
|
-
const result = {}
|
|
36
|
-
result.x = u.y * v.z - u.z * v.y
|
|
37
|
-
result.y = u.z * v.x - u.x * v.z
|
|
38
|
-
result.z = u.x * v.y - u.y * v.x
|
|
39
|
-
return result
|
|
40
|
-
}
|
|
41
|
-
export function meanVector(listVector) {
|
|
42
|
-
let meanPoint = {}
|
|
43
|
-
let sumPoint = { x: 0, y: 0, z: 0 }
|
|
44
|
-
listVector.forEach((p) => {
|
|
45
|
-
sumPoint = addVector(sumPoint, p)
|
|
46
|
-
})
|
|
47
|
-
meanPoint = multiplyVector(1 / listVector.length, sumPoint)
|
|
48
|
-
return meanPoint
|
|
49
|
-
}
|
|
50
|
-
export function vectorLength(v) {
|
|
51
|
-
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z)
|
|
52
|
-
}
|
|
53
|
-
export function vectorLength2D(v) {
|
|
54
|
-
return Math.sqrt(v.x * v.x + v.y * v.y)
|
|
55
|
-
}
|
|
56
|
-
export function normalizeVector(v) {
|
|
57
|
-
let length = vectorLength(v)
|
|
58
|
-
if (length == 0) {
|
|
59
|
-
return v
|
|
60
|
-
}
|
|
61
|
-
return multiplyVector(1 / length, v)
|
|
62
|
-
}
|
|
63
|
-
export function normalize2DVector(v) {
|
|
64
|
-
let length = vectorLength2D(v)
|
|
65
|
-
if (length == 0) {
|
|
66
|
-
return v
|
|
67
|
-
}
|
|
68
|
-
return multiplyVector(1 / length, v)
|
|
69
|
-
}
|
|
68
|
+
return multiplyVector(1 / length, v)
|
|
69
|
+
}
|