@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/src/index.js CHANGED
@@ -1,11 +1,10 @@
1
-
2
- export * from './coords';
3
- export * from './geo';
4
- export * from './geometry';
5
- export * from './matrix';
6
- export * from './vector';
7
- export * from './snap';
8
- export * from './intersectionPolygon';
9
- export * from './objects';
10
- export * from './splitMergePolygons';
11
-
1
+ export * from './coords'
2
+ export * from './geo'
3
+ export * from './geometry'
4
+ export * from './matrix'
5
+ export * from './vector'
6
+ export * from './snap'
7
+ export * from './intersectionPolygon'
8
+ export * from './objects'
9
+ export * from './splitMergePolygons'
10
+ export * from './miscellaneous'
@@ -1,10 +1,10 @@
1
-
2
1
  import {
3
2
  getPointInsideOutline,
4
3
  isInsidePolygon,
5
4
  isSamePoint2D
6
5
  } from './geometry'
7
- import {getIntersections,
6
+ import {
7
+ getIntersections,
8
8
  getNodeList,
9
9
  getEdgeList,
10
10
  getOutlineList
@@ -29,19 +29,19 @@ export function isSelfIntersecting(outline, isClosePolygon = true) {
29
29
  //check if two nodes are in same position
30
30
  for (let k = 0; k < length; k++) {
31
31
  let A = outline[k]
32
- let B = outline[(k + 1)%length]
33
- if(isSamePoint2D(A,B)) return true
32
+ let B = outline[(k + 1) % length]
33
+ if (isSamePoint2D(A, B)) return true
34
34
  }
35
35
  if (length < 4) return false
36
- let closeOffset=isClosePolygon?0:1
36
+ let closeOffset = isClosePolygon ? 0 : 1
37
37
  //let AB and CD be two edges we are testing for intersection
38
- for (let k = 0; k < length-closeOffset; k++) {
38
+ for (let k = 0; k < length - closeOffset; k++) {
39
39
  let A = outline[k]
40
- let B = outline[(k + 1)%length]
40
+ let B = outline[(k + 1) % length]
41
41
  let offset = k == 0 ? 0 : 1
42
42
  for (let j = k + 2; j < length - 1 + offset - closeOffset; j++) {
43
43
  let C = outline[j]
44
- let D = outline[(j + 1)%length]
44
+ let D = outline[(j + 1) % length]
45
45
  if (doLineSegmentsIntersect(A, B, C, D)) {
46
46
  isSelfIntersecting = true
47
47
  break
@@ -54,9 +54,11 @@ export function isSelfIntersecting(outline, isClosePolygon = true) {
54
54
  return isSelfIntersecting
55
55
  }
56
56
 
57
-
58
- export function logicOperationOnPolygons(outline1,outline2,mode='intersect')
59
- {
57
+ export function logicOperationOnPolygons(
58
+ outline1,
59
+ outline2,
60
+ mode = 'intersect'
61
+ ) {
60
62
  const fig1 = outline1.map((p) => {
61
63
  return { x: p.x, y: p.y, z: p.z }
62
64
  })
@@ -66,32 +68,35 @@ export function logicOperationOnPolygons(outline1,outline2,mode='intersect')
66
68
  })
67
69
  //nodeList:
68
70
  let dirtyNodeList = []
69
- fig1.forEach((p) => {dirtyNodeList.push(p)})
70
- fig2.forEach((p) => {dirtyNodeList.push(p)})
71
+ fig1.forEach((p) => {
72
+ dirtyNodeList.push(p)
73
+ })
74
+ fig2.forEach((p) => {
75
+ dirtyNodeList.push(p)
76
+ })
71
77
  //edgeList (just in term of indexes)
72
- const edges=fig2.map((p,index)=>{
73
- return {outline:[p,fig2[(index+1)%fig2.length]]}
78
+ const edges = fig2.map((p, index) => {
79
+ return { outline: [p, fig2[(index + 1) % fig2.length]] }
74
80
  })
75
- let intersections = getIntersections({outline:fig1}, edges)
81
+ let intersections = getIntersections({ outline: fig1 }, edges)
76
82
 
77
83
  //2. gather all nodes+intersection in a list[[x,y],[x,y]]
78
- const nodeList = getNodeList(intersections, edges, {outline:fig1})
84
+ const nodeList = getNodeList(intersections, edges, { outline: fig1 })
79
85
  //3. generate all edges not cut, those cut and those from construction polyline
80
-
81
86
 
82
87
  const edgeList = getEdgeList(
83
88
  nodeList,
84
89
  intersections,
85
90
  edges,
86
- {outline:fig1},
91
+ { outline: fig1 },
87
92
  1
88
93
  )
89
94
  //4. run planar-face-discovery to get all cycles and rebuild our polygons
90
- try{
91
- const outlineList = getOutlineList(nodeList, edgeList)
95
+ try {
96
+ const outlineList = getOutlineList(nodeList, edgeList)
92
97
  return filterPolygons(outlineList, fig1, fig2, mode)
93
- }catch(err){
94
- console.error("error with getOutlineList",nodeList, edgeList,err)
98
+ } catch (err) {
99
+ console.error('error with getOutlineList', nodeList, edgeList, err)
95
100
  return []
96
101
  }
97
102
  }
@@ -102,7 +107,10 @@ function filterPolygons(polygons, fig1, fig2, mode) {
102
107
  var point
103
108
  var bigPolygons = removeSmallPolygons(polygons, 0.0001)
104
109
  for (var i = 0; i < bigPolygons.length; i++) {
105
- point = getPointInsideOutline(bigPolygons[i],bigPolygons.filter((p,index)=>index!=i))
110
+ point = getPointInsideOutline(
111
+ bigPolygons[i],
112
+ bigPolygons.filter((p, index) => index != i)
113
+ )
106
114
  c1 = isInsidePolygon(point, fig1)
107
115
  c2 = isInsidePolygon(point, fig2)
108
116
  if (
@@ -113,14 +121,13 @@ function filterPolygons(polygons, fig1, fig2, mode) {
113
121
  ) {
114
122
  //fig1 + fig2
115
123
  //remove undefined point:
116
- bigPolygons[i]=bigPolygons[i].filter(p=>!!p)
124
+ bigPolygons[i] = bigPolygons[i].filter((p) => !!p)
117
125
  filtered.push(bigPolygons[i])
118
126
  }
119
127
  }
120
128
  return filtered
121
129
  }
122
130
 
123
-
124
131
  export function intersectOutlines(outline1, outline2) {
125
132
  const fig1 = outline1.map((p) => {
126
133
  return { x: p.x, y: p.y, z: p.z }
@@ -129,8 +136,7 @@ export function intersectOutlines(outline1, outline2) {
129
136
  return { x: p.x, y: p.y, z: p.z }
130
137
  })
131
138
 
132
- return logicOperationOnPolygons(fig1,fig2,'intersect')
133
-
139
+ return logicOperationOnPolygons(fig1, fig2, 'intersect')
134
140
  }
135
141
 
136
142
  function alignPolygon(polygon, points) {