@eturnity/eturnity_maths 7.2.2-qa-7.2.2 → 7.2.2-qa-7.2.4

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_maths",
3
- "version": "7.2.2-qa-7.2.2",
3
+ "version": "7.2.2-qa-7.2.4",
4
4
  "author": "Eturnity Team",
5
5
  "main": "src/index.js",
6
6
  "private": false,
package/src/geometry.js CHANGED
@@ -15,13 +15,22 @@ import {Point} from './objects/Point'
15
15
  import {Line} from './objects/Line'
16
16
  import concaveman from 'concaveman'
17
17
 
18
- export function getConcaveOutline(selectedPanels,onPanelOutline){
18
+ export function getConcaveOutlines(selectedPanels,onePanelOutline){
19
+ let buckets=groupAdjacentObjects(selectedPanels)
20
+ const outlines = []
21
+ for(let bucketIndex=0;bucketIndex<buckets.length;bucketIndex++){
22
+ outlines.push(getConcaveOutline(selectedPanels.filter((p,i)=>buckets[bucketIndex].includes(i)),onePanelOutline))
23
+ }
24
+ return outlines
25
+ }
26
+
27
+ export function getConcaveOutline(selectedPanels,onePanelOutline){
19
28
  const points = selectedPanels.reduce((acc, cur) => {
20
29
  acc.push(...cur.outline.map((p) => [p.x, p.y]))
21
30
  return acc
22
31
  }, [])
23
- let AB = getDistanceBetweenPoints(onPanelOutline[0], onPanelOutline[1])
24
- let AD = getDistanceBetweenPoints(onPanelOutline[0], onPanelOutline[3])
32
+ let AB = getDistanceBetweenPoints(onePanelOutline[0], onePanelOutline[1])
33
+ let AD = getDistanceBetweenPoints(onePanelOutline[0], onePanelOutline[3])
25
34
  let longEdgeLength = Math.max(AB, AD)+100
26
35
  var concaveResult = concaveman(points, 1, longEdgeLength)
27
36
  concaveResult.pop()
@@ -719,9 +728,54 @@ export function get3DDistanceBetweenPoints(firstPoint, secondPoint) {
719
728
  const det = (B.x - A.x) * (C.y - A.y) - (C.x - A.x) * (B.y - A.y)
720
729
  return det < 0
721
730
  }
722
-
731
+ export function groupAdjacentObjects(objects){
732
+ if(!objects || objects.length==0) return []
733
+ // objects with 2D indexes
734
+ // Check if the objects form an adjacent group
735
+ let numberOfObjects=objects.length
736
+ let indexList=Array.from({length: numberOfObjects}, (e, i)=> i)
737
+ let buckets = []
738
+ let inBucket=0
739
+ while (inBucket<objects.length)
740
+ {
741
+ let detatchedIndex=indexList.find(i=>!buckets.flat().includes(i))
742
+ if(detatchedIndex==null) break
743
+ let queue = [detatchedIndex]
744
+ let visited = []
745
+ while (queue.length > 0) {
746
+ const currentObjectIndex = queue.pop()
747
+ if (visited.indexOf(currentObjectIndex) == -1) {
748
+ //if next queued index hasn't been visited, we mark it as visited and we collect all neighbourg to queue
749
+ visited.push(currentObjectIndex)
750
+ let x = objects[currentObjectIndex].index[0]
751
+ let y = objects[currentObjectIndex].index[1]
752
+ const left = objects.findIndex(
753
+ (o) => o.index[0] == x - 1 && o.index[1] == y
754
+ )
755
+ const right = objects.findIndex(
756
+ (o) => o.index[0] == x + 1 && o.index[1] == y
757
+ )
758
+ const top = objects.findIndex(
759
+ (o) => o.index[0] == x && o.index[1] == y - 1
760
+ )
761
+ const bottom = objects.findIndex(
762
+ (o) => o.index[0] == x && o.index[1] == y + 1
763
+ )
764
+ if (left != -1 && visited.indexOf(left) == -1) queue.push(left)
765
+ if (right != -1 && visited.indexOf(right) == -1) queue.push(right)
766
+ if (top != -1 && visited.indexOf(top) == -1) queue.push(top)
767
+ if (bottom != -1 && visited.indexOf(bottom) == -1) queue.push(bottom)
768
+ }
769
+ }
770
+ inBucket+=visited.length
771
+ buckets.push(visited)
772
+ }
773
+
774
+ return buckets
775
+ }
723
776
  // Function to check if two indexes are adjacent
724
777
  export function areAdjacent(objects) {
778
+ if(!objects || objects.length==0) return false
725
779
  // objects with 2D indexes
726
780
  // Check if the objects form an adjacent group
727
781
  let visited = []
@@ -166,6 +166,7 @@ export class Polygon {
166
166
  extraSerialization.mountingData = this.mountingData?{...this.mountingData}:null
167
167
  extraSerialization.modules = modules
168
168
  extraSerialization.needsOptimisation = this.needsOptimisation
169
+ extraSerialization.priority = this.priority
169
170
 
170
171
  } else if (this.layer == 'panel') {
171
172
  extraSerialization.index = this.index