@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
|
@@ -1,150 +1,147 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return state
|
|
12
|
-
}
|
|
1
|
+
import { multiplyVector } from '../../vector'
|
|
2
|
+
import { getMarginPoint, isClockWise } from '../../geometry'
|
|
3
|
+
import { calculateBestFittingPlanePolygon } from './updateComputedGeometryPolygon'
|
|
4
|
+
//update and calculate margins for all polygon
|
|
5
|
+
export function updateMarginsOutline(state) {
|
|
6
|
+
state.polygons.forEach((polygon) => {
|
|
7
|
+
polygon = updateMarginOutlinePolygon(polygon)
|
|
8
|
+
})
|
|
9
|
+
return state
|
|
10
|
+
}
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export function getRoofMarginOutline(polygon){
|
|
32
|
-
let clockwiseNormalVector=polygon.normalVector
|
|
33
|
-
if(!polygon.isClockwise){
|
|
34
|
-
clockwiseNormalVector=multiplyVector(-1,clockwiseNormalVector)
|
|
35
|
-
}
|
|
36
|
-
//outterOutline is the outline close to the wall
|
|
37
|
-
polygon.margins.outterOutline=polygon.flatOutline
|
|
38
|
-
polygon.margins.innerOutline=[]
|
|
39
|
-
const length=polygon.outline.length
|
|
40
|
-
polygon.margins.distances = polygon.margins.distances.slice(0, length)
|
|
41
|
-
for(let index=0;index<length;index++){
|
|
42
|
-
if(polygon.margins.distances[index] == undefined){
|
|
43
|
-
polygon.margins.distances[index] = polygon.margins.sameMargin
|
|
44
|
-
}
|
|
45
|
-
const B=polygon.margins.outterOutline[index]
|
|
46
|
-
//A,B,C three consecutive points on the polygon.
|
|
47
|
-
//n is a vector in the plan normal to AB of length margin[A] directed towards the inside
|
|
48
|
-
//m is a vector in the plan normal to BC of length margin[B] directed towards the inside
|
|
49
|
-
//K is the margin outline linked with B
|
|
50
|
-
const A=polygon.margins.outterOutline[(index-1+length)%length]
|
|
51
|
-
const C=polygon.margins.outterOutline[(index+1)%length]
|
|
52
|
-
//filling the margins values if not initiated.
|
|
53
|
-
let marginA
|
|
54
|
-
let marginB
|
|
55
|
-
if(polygon.margins.isSameMargin){
|
|
56
|
-
marginA=polygon.margins.sameMargin
|
|
57
|
-
marginB=polygon.margins.sameMargin
|
|
58
|
-
polygon.margins.distances[index]=polygon.margins.sameMargin
|
|
59
|
-
}else{
|
|
60
|
-
if(!polygon.margins.distances[(index-1+length)%length]===undefined){
|
|
61
|
-
polygon.margins.distances[(index-1+length)%length]=polygon.margins.sameMargin
|
|
62
|
-
}
|
|
63
|
-
if(!polygon.margins.distances[index]===undefined){
|
|
64
|
-
polygon.margins.distances[index]=polygon.margins.sameMargin
|
|
65
|
-
}
|
|
66
|
-
marginA=polygon.margins.distances[(index-1+length)%length]
|
|
67
|
-
marginB=polygon.margins.distances[index]
|
|
68
|
-
}
|
|
69
|
-
let K=getMarginPoint(A,B,C,marginA,marginB,clockwiseNormalVector)
|
|
70
|
-
polygon.margins.innerOutline.push(K)
|
|
71
|
-
}
|
|
72
|
-
return polygon
|
|
73
|
-
}
|
|
12
|
+
export function updateMarginOutlinePolygon(polygon) {
|
|
13
|
+
if (polygon.layer == 'roof') {
|
|
14
|
+
return getRoofMarginOutline(polygon)
|
|
15
|
+
} else if (polygon.layer == 'obstacle') {
|
|
16
|
+
return getObstacleMarginOutline(polygon)
|
|
17
|
+
} else {
|
|
18
|
+
return polygon
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//FYI: polygon.margins={
|
|
22
|
+
// distances:array[#point] //primitives
|
|
23
|
+
// isSameMargin:Boolean //primitives
|
|
24
|
+
// sameMargin:Number //primitives
|
|
25
|
+
// outterOutline:array[Vector3D] //derived (for roof this is the wall)
|
|
26
|
+
// innerOutline:array[Vector3D] //derived (for obstacle this is the wall)
|
|
27
|
+
// }
|
|
74
28
|
|
|
29
|
+
export function getRoofMarginOutline(polygon) {
|
|
30
|
+
let clockwiseNormalVector = polygon.normalVector
|
|
31
|
+
if (!polygon.isClockwise) {
|
|
32
|
+
clockwiseNormalVector = multiplyVector(-1, clockwiseNormalVector)
|
|
33
|
+
}
|
|
34
|
+
//outterOutline is the outline close to the wall
|
|
35
|
+
polygon.margins.outterOutline = polygon.flatOutline
|
|
36
|
+
polygon.margins.innerOutline = []
|
|
37
|
+
const length = polygon.outline.length
|
|
38
|
+
polygon.margins.distances = polygon.margins.distances.slice(0, length)
|
|
39
|
+
for (let index = 0; index < length; index++) {
|
|
40
|
+
if (polygon.margins.distances[index] == undefined) {
|
|
41
|
+
polygon.margins.distances[index] = polygon.margins.sameMargin
|
|
42
|
+
}
|
|
43
|
+
const B = polygon.margins.outterOutline[index]
|
|
44
|
+
//A,B,C three consecutive points on the polygon.
|
|
45
|
+
//n is a vector in the plan normal to AB of length margin[A] directed towards the inside
|
|
46
|
+
//m is a vector in the plan normal to BC of length margin[B] directed towards the inside
|
|
47
|
+
//K is the margin outline linked with B
|
|
48
|
+
const A = polygon.margins.outterOutline[(index - 1 + length) % length]
|
|
49
|
+
const C = polygon.margins.outterOutline[(index + 1) % length]
|
|
50
|
+
//filling the margins values if not initiated.
|
|
51
|
+
let marginA
|
|
52
|
+
let marginB
|
|
53
|
+
if (polygon.margins.isSameMargin) {
|
|
54
|
+
marginA = polygon.margins.sameMargin
|
|
55
|
+
marginB = polygon.margins.sameMargin
|
|
56
|
+
polygon.margins.distances[index] = polygon.margins.sameMargin
|
|
57
|
+
} else {
|
|
58
|
+
if (
|
|
59
|
+
!polygon.margins.distances[(index - 1 + length) % length] === undefined
|
|
60
|
+
) {
|
|
61
|
+
polygon.margins.distances[(index - 1 + length) % length] =
|
|
62
|
+
polygon.margins.sameMargin
|
|
63
|
+
}
|
|
64
|
+
if (!polygon.margins.distances[index] === undefined) {
|
|
65
|
+
polygon.margins.distances[index] = polygon.margins.sameMargin
|
|
66
|
+
}
|
|
67
|
+
marginA = polygon.margins.distances[(index - 1 + length) % length]
|
|
68
|
+
marginB = polygon.margins.distances[index]
|
|
69
|
+
}
|
|
70
|
+
let K = getMarginPoint(A, B, C, marginA, marginB, clockwiseNormalVector)
|
|
71
|
+
polygon.margins.innerOutline.push(K)
|
|
72
|
+
}
|
|
73
|
+
return polygon
|
|
74
|
+
}
|
|
75
75
|
|
|
76
|
-
export function getObstacleMarginOutline(polygon){
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
76
|
+
export function getObstacleMarginOutline(polygon) {
|
|
77
|
+
let clockwiseNormalVector = polygon.normalVector
|
|
78
|
+
if (polygon.isClockwise) {
|
|
79
|
+
clockwiseNormalVector = multiplyVector(-1, clockwiseNormalVector)
|
|
80
|
+
}
|
|
81
|
+
//outterOutline is the outline close to the wall
|
|
82
|
+
polygon.margins.innerOutline = polygon.flatOutline
|
|
83
|
+
polygon.margins.outterOutline = []
|
|
84
|
+
const length = polygon.margins.innerOutline.length
|
|
85
|
+
polygon.margins.distances = polygon.margins.distances.slice(0, length)
|
|
86
|
+
for (let index = 0; index < length; index++) {
|
|
87
|
+
if (polygon.margins.distances[index] == undefined) {
|
|
88
|
+
polygon.margins.distances[index] = polygon.margins.sameMargin
|
|
89
|
+
}
|
|
90
|
+
const B = polygon.margins.innerOutline[index]
|
|
91
|
+
//A,B,C three consecutive points on the polygon.
|
|
92
|
+
//n is a vector in the plan normal to AB of length margin[A] directed towards the inside
|
|
93
|
+
//m is a vector in the plan normal to BC of length margin[B] directed towards the inside
|
|
94
|
+
//K is the margin outline linked with B
|
|
95
|
+
const A = polygon.margins.innerOutline[(index - 1 + length) % length]
|
|
96
|
+
const C = polygon.margins.innerOutline[(index + 1) % length]
|
|
97
|
+
//filling the margins values if not initiated.
|
|
98
|
+
let marginA
|
|
99
|
+
let marginB
|
|
100
|
+
if (polygon.margins.isSameMargin) {
|
|
101
|
+
marginA = polygon.margins.sameMargin
|
|
102
|
+
marginB = polygon.margins.sameMargin
|
|
103
|
+
polygon.margins.distances[index] = polygon.margins.sameMargin
|
|
104
|
+
} else {
|
|
105
|
+
if (
|
|
106
|
+
polygon.margins.distances[(index - 1 + length) % length] === undefined
|
|
107
|
+
) {
|
|
108
|
+
polygon.margins.distances[(index - 1 + length) % length] =
|
|
109
|
+
polygon.margins.sameMargin
|
|
110
|
+
}
|
|
111
|
+
if (polygon.margins.distances[index] === undefined) {
|
|
112
|
+
polygon.margins.distances[index] = polygon.margins.sameMargin
|
|
113
|
+
}
|
|
114
|
+
marginA = polygon.margins.distances[(index - 1 + length) % length]
|
|
115
|
+
marginB = polygon.margins.distances[index]
|
|
116
|
+
}
|
|
117
|
+
let K = getMarginPoint(A, B, C, marginA, marginB, clockwiseNormalVector)
|
|
118
|
+
polygon.margins.outterOutline.push(K)
|
|
119
|
+
}
|
|
120
|
+
return polygon
|
|
121
|
+
}
|
|
119
122
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const C=projectedOutline[(index+1)%length]
|
|
145
|
-
//filling the margins values if not initiated.
|
|
146
|
-
let K=getMarginPoint(A,B,C,margin,margin,clockwiseNormalVector)
|
|
147
|
-
outterOutline.push(K)
|
|
148
|
-
}
|
|
149
|
-
return outterOutline
|
|
123
|
+
export function getOutterOutlineWithConstantMargin(outline, margin) {
|
|
124
|
+
const isClockwise = isClockWise(outline)
|
|
125
|
+
const { projectedOutline, normalVector } =
|
|
126
|
+
calculateBestFittingPlanePolygon(outline)
|
|
127
|
+
let clockwiseNormalVector = normalVector
|
|
128
|
+
if (isClockwise) {
|
|
129
|
+
clockwiseNormalVector = multiplyVector(-1, clockwiseNormalVector)
|
|
130
|
+
}
|
|
131
|
+
//outterOutline is the outline close to the wall
|
|
132
|
+
const outterOutline = []
|
|
133
|
+
const length = outline.length
|
|
134
|
+
for (let index = 0; index < length; index++) {
|
|
135
|
+
const B = projectedOutline[index]
|
|
136
|
+
//A,B,C three consecutive points on the polygon.
|
|
137
|
+
//n is a vector in the plan normal to AB of length margin[A] directed towards the inside
|
|
138
|
+
//m is a vector in the plan normal to BC of length margin[B] directed towards the inside
|
|
139
|
+
//K is the margin outline linked with B
|
|
140
|
+
const A = projectedOutline[(index - 1 + length) % length]
|
|
141
|
+
const C = projectedOutline[(index + 1) % length]
|
|
142
|
+
//filling the margins values if not initiated.
|
|
143
|
+
let K = getMarginPoint(A, B, C, margin, margin, clockwiseNormalVector)
|
|
144
|
+
outterOutline.push(K)
|
|
145
|
+
}
|
|
146
|
+
return outterOutline
|
|
150
147
|
}
|