@eturnity/eturnity_maths 7.51.2 → 8.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/package.json
CHANGED
package/src/geometry.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
vectorLength,
|
|
10
10
|
normalizeVector,
|
|
11
11
|
} from './vector'
|
|
12
|
-
import {
|
|
12
|
+
import { inverse3x3Matrix, multiplyMatrices } from './matrix'
|
|
13
13
|
import { Point } from './objects/Point'
|
|
14
14
|
import { Line } from './objects/Line'
|
|
15
15
|
import concaveman from './lib/concaveman'
|
|
@@ -132,7 +132,7 @@ export function getDataAboutTwo3DLines(A, u, B, v) {
|
|
|
132
132
|
[u.y, v.y, w.y],
|
|
133
133
|
[u.z, v.z, w.z],
|
|
134
134
|
]
|
|
135
|
-
let mInv =
|
|
135
|
+
let mInv = inverse3x3Matrix(m)
|
|
136
136
|
if (!mInv) {
|
|
137
137
|
return null
|
|
138
138
|
}
|
|
@@ -12,6 +12,33 @@ import {
|
|
|
12
12
|
getOutlineList,
|
|
13
13
|
} from './splitMergePolygons'
|
|
14
14
|
|
|
15
|
+
export function isOutlineTouchingOutline(outline, outlineSelection) {
|
|
16
|
+
const isOutlinePointWithinSelection = outline.some((p) =>
|
|
17
|
+
isInsidePolygon(p, outlineSelection)
|
|
18
|
+
)
|
|
19
|
+
if (isOutlinePointWithinSelection) {
|
|
20
|
+
return true
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const isEdgeInSelection = outline.some((p, index) => {
|
|
24
|
+
const nextIndex = (index + 1) % outline.length
|
|
25
|
+
const nextP = outline[nextIndex]
|
|
26
|
+
return outlineSelection.some((selectionPoint, selectionIndex) => {
|
|
27
|
+
const nextSelectionIndex = (selectionIndex + 1) % outlineSelection.length
|
|
28
|
+
const nextSelectionPoint = outlineSelection[nextSelectionIndex]
|
|
29
|
+
return doLineSegmentsIntersect(
|
|
30
|
+
p,
|
|
31
|
+
nextP,
|
|
32
|
+
selectionPoint,
|
|
33
|
+
nextSelectionPoint
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
if (isEdgeInSelection) {
|
|
38
|
+
return true
|
|
39
|
+
}
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
15
42
|
export function isOutlineTouchingBoundingBox(outline, bbox) {
|
|
16
43
|
const isOutlinePointWithinBbox = outline.some(
|
|
17
44
|
(p) =>
|
package/src/matrix.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import { substractVector } from './vector'
|
|
2
|
-
export function inverse2x2Matrix([a, b, c, d]) {
|
|
3
|
-
//inverse matrix |a,
|
|
4
|
-
// |
|
|
5
|
-
const det = a *
|
|
1
|
+
import { substractVector, addVector, multiplyVector } from './vector'
|
|
2
|
+
export function inverse2x2Matrix([[a, b], [c, d]]) {
|
|
3
|
+
//inverse matrix |a,b|
|
|
4
|
+
// |c,d|
|
|
5
|
+
const det = a * d - c * b
|
|
6
6
|
if (det == 0) {
|
|
7
7
|
return null
|
|
8
8
|
}
|
|
9
|
-
return [
|
|
9
|
+
return [
|
|
10
|
+
[d / det, -b / det],
|
|
11
|
+
[-c / det, a / det],
|
|
12
|
+
]
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
export function
|
|
15
|
+
export function inverse3x3Matrix(m) {
|
|
16
|
+
//inverse matrix |a,b,c|
|
|
17
|
+
// |d,e,f|
|
|
18
|
+
// |g,h,i|
|
|
13
19
|
let [[a, b, c], [d, e, f], [g, h, i]] = m
|
|
14
20
|
let x = e * i - h * f
|
|
15
21
|
let y = f * g - d * i
|
|
@@ -19,7 +25,7 @@ export function inverse3x3matrix(m) {
|
|
|
19
25
|
? [
|
|
20
26
|
[x, c * h - b * i, b * f - c * e],
|
|
21
27
|
[y, a * i - c * g, d * c - a * f],
|
|
22
|
-
[z, g * b - a * h, a * e - d * b]
|
|
28
|
+
[z, g * b - a * h, a * e - d * b],
|
|
23
29
|
].map((r) => r.map((v) => (v /= det)))
|
|
24
30
|
: null
|
|
25
31
|
}
|
|
@@ -55,11 +61,32 @@ export function multiplyMatrices(a, b) {
|
|
|
55
61
|
export function rotateTransformation(point, angle, center = { x: 0, y: 0 }) {
|
|
56
62
|
let rotationMatrix = [
|
|
57
63
|
[Math.cos(angle), Math.sin(angle)],
|
|
58
|
-
[-Math.sin(angle), Math.cos(angle)]
|
|
64
|
+
[-Math.sin(angle), Math.cos(angle)],
|
|
59
65
|
]
|
|
60
66
|
let k = multiplyMatrices(rotationMatrix, [
|
|
61
67
|
[point.x - center.x],
|
|
62
|
-
[point.y - center.y]
|
|
68
|
+
[point.y - center.y],
|
|
63
69
|
])
|
|
64
70
|
return { x: k[0][0] + center.x, y: k[1][0] + center.y }
|
|
65
71
|
}
|
|
72
|
+
|
|
73
|
+
export function getOutlineFromCornerPointsAndDirections(
|
|
74
|
+
downPoint,
|
|
75
|
+
point,
|
|
76
|
+
directions
|
|
77
|
+
) {
|
|
78
|
+
let M = [
|
|
79
|
+
[directions[0].x, directions[1].x],
|
|
80
|
+
[directions[0].y, directions[1].y],
|
|
81
|
+
]
|
|
82
|
+
let invM = inverse2x2Matrix(M)
|
|
83
|
+
const v = substractVector(point, downPoint)
|
|
84
|
+
const coefs = multiplyMatrices(invM, [[v.x], [v.y]])
|
|
85
|
+
const coords = [
|
|
86
|
+
downPoint,
|
|
87
|
+
addVector(downPoint, multiplyVector(coefs[0], directions[0])),
|
|
88
|
+
point,
|
|
89
|
+
addVector(downPoint, multiplyVector(coefs[1], directions[1])),
|
|
90
|
+
]
|
|
91
|
+
return coords
|
|
92
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { inverse2x2Matrix, multiplyMatrices } from '../../index'
|
|
2
|
+
|
|
3
|
+
describe('inverse2x2Matrix function', () => {
|
|
4
|
+
test('returns identity if MxinvM ', () => {
|
|
5
|
+
const M = [
|
|
6
|
+
[4, 3],
|
|
7
|
+
[7, 1],
|
|
8
|
+
]
|
|
9
|
+
const invM = inverse2x2Matrix(M)
|
|
10
|
+
const id = multiplyMatrices(M, invM)
|
|
11
|
+
for (let i = 0; i < id.length; i++) {
|
|
12
|
+
for (let j = 0; j < id.length; j++) {
|
|
13
|
+
expect(id[i][j] - (i == j ? 1 : 0) < 0.001).toBe(true)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { inverse3x3Matrix, multiplyMatrices } from '../../index'
|
|
2
|
+
|
|
3
|
+
describe('inverse3x3Matrix function', () => {
|
|
4
|
+
test('returns identity if MxinvM ', () => {
|
|
5
|
+
const M = [
|
|
6
|
+
[4, 3, 2],
|
|
7
|
+
[7, 1, 0],
|
|
8
|
+
[2, 1, 8],
|
|
9
|
+
]
|
|
10
|
+
const invM = inverse3x3Matrix(M)
|
|
11
|
+
const id = multiplyMatrices(M, invM)
|
|
12
|
+
for (let i = 0; i < id.length; i++) {
|
|
13
|
+
for (let j = 0; j < id.length; j++) {
|
|
14
|
+
expect(id[i][j] - (i == j ? 1 : 0) < 0.001).toBe(true)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
})
|