@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.
@@ -1,150 +1,147 @@
1
- import {
2
- multiplyVector
3
- } from '../../vector'
4
- import {getMarginPoint,isClockWise} from '../../geometry'
5
- import {calculateBestFittingPlanePolygon} from './updateComputedGeometryPolygon'
6
- //update and calculate margins for all polygon
7
- export function updateMarginsOutline(state){
8
- state.polygons.forEach(polygon=>{
9
- polygon=updateMarginOutlinePolygon(polygon)
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
- export function updateMarginOutlinePolygon(polygon){
15
- if(polygon.layer=="roof"){
16
- return getRoofMarginOutline(polygon)
17
- }else if(polygon.layer=='obstacle'){
18
- return getObstacleMarginOutline(polygon)
19
- }else{
20
- return polygon
21
- }
22
- }
23
- //FYI: polygon.margins={
24
- // distances:array[#point] //primitives
25
- // isSameMargin:Boolean //primitives
26
- // sameMargin:Number //primitives
27
- // outterOutline:array[Vector3D] //derived (for roof this is the wall)
28
- // innerOutline:array[Vector3D] //derived (for obstacle this is the wall)
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
- 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(polygon.margins.distances[(index-1+length)%length]===undefined){
106
- polygon.margins.distances[(index-1+length)%length]=polygon.margins.sameMargin
107
- }
108
- if(polygon.margins.distances[index]===undefined){
109
- polygon.margins.distances[index]=polygon.margins.sameMargin
110
- }
111
- marginA=polygon.margins.distances[(index-1+length)%length]
112
- marginB=polygon.margins.distances[index]
113
- }
114
- let K=getMarginPoint(A,B,C,marginA,marginB,clockwiseNormalVector)
115
- polygon.margins.outterOutline.push(K)
116
- }
117
- return polygon
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
- export function getOutterOutlineWithConstantMargin(outline,margin){
121
- const isClockwise = isClockWise(outline)
122
- const {
123
- projectedOutline,
124
- maximumGap,
125
- normalVector,
126
- meanPoint,
127
- incline,
128
- direction
129
- } = calculateBestFittingPlanePolygon(outline)
130
- let clockwiseNormalVector=normalVector
131
- if(isClockwise){
132
- clockwiseNormalVector=multiplyVector(-1,clockwiseNormalVector)
133
- }
134
- //outterOutline is the outline close to the wall
135
- const outterOutline=[]
136
- const length=outline.length
137
- for(let index=0;index<length;index++){
138
- const B=projectedOutline[index]
139
- //A,B,C three consecutive points on the polygon.
140
- //n is a vector in the plan normal to AB of length margin[A] directed towards the inside
141
- //m is a vector in the plan normal to BC of length margin[B] directed towards the inside
142
- //K is the margin outline linked with B
143
- const A=projectedOutline[(index-1+length)%length]
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
  }