@eturnity/eturnity_maths 7.16.0-qa-dev03.2 → 7.16.0-qa-dev03.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.16.0-qa-dev03.2",
3
+ "version": "7.16.0-qa-dev03.4",
4
4
  "author": "Eturnity Team",
5
5
  "main": "src/index.js",
6
6
  "private": false,
@@ -13,13 +13,15 @@ import {
13
13
  isPointBetweenSegment,
14
14
  isInsidePolygon,
15
15
  verticalProjectionOnPlane,
16
- polygonsHaveSame2DOutline
16
+ polygonsHaveSame2DOutline,
17
+ calculateArea
17
18
  } from './geometry'
18
19
  import { groupBy } from 'lodash'
19
20
  import { Polygon } from './objects/Polygon'
20
21
  import { defaultBaseHeight, mmTolerance } from './config'
22
+ import { intersectOutlines } from './intersectionPolygon'
21
23
 
22
- export function mergePolygons(polygonIdsToMerge, edges, layer) {
24
+ export function mergePolygons(polygonIdsToMerge, edges, layer, polygons) {
23
25
  const outsideEdge = edges.filter((e) => e.belongsTo.length == 1)
24
26
  const insideEdge = edges.filter((e) => e.belongsTo.length == 2)
25
27
  const insideEdgeToKeep = insideEdge.filter((e) => {
@@ -50,7 +52,15 @@ export function mergePolygons(polygonIdsToMerge, edges, layer) {
50
52
 
51
53
  const polygonList = []
52
54
  for (let k = 0; k < outlineList.length; k++) {
53
- polygonList.push(new Polygon(outlineList[k], layer))
55
+ //check if roof with same outline already exist:
56
+ let polygon = polygons.find((polygon) =>
57
+ polygonsHaveSame2DOutline(outlineList[k], polygon.outline)
58
+ )
59
+ let newPolygon=new Polygon(outlineList[k], layer)
60
+ if (polygon) {
61
+ newPolygon.id=polygon.id
62
+ }
63
+ polygonList.push(newPolygon)
54
64
  }
55
65
  return polygonList
56
66
  }
@@ -457,7 +467,22 @@ export function getOutlineList(nodeList, edgeList, roofs = []) {
457
467
  )
458
468
  if (roof) {
459
469
  outline = JSON.parse(JSON.stringify(roof.outline))
460
- }
470
+ } else {
471
+ let underneathRoofsIntersectionsData = roofs.map(roof=>{
472
+ const intersections = intersectOutlines(roof.outline,outline)
473
+ let area=0
474
+ if(intersections.length){
475
+ area=calculateArea(intersections[0])
476
+ }
477
+ return {roof,intersectionLength:intersections.length,intersections,area}
478
+ })
479
+ underneathRoofsIntersectionsData = underneathRoofsIntersectionsData.filter(d=>d.intersectionLength > 0)
480
+ if(underneathRoofsIntersectionsData.length>0){
481
+ underneathRoofsIntersectionsData.sort((a,b)=> a.roof.area-b.roof.area)
482
+ let roofUnderneath=underneathRoofsIntersectionsData[0].roof
483
+ outline = outline.map(p=>verticalProjectionOnPlane(p,roofUnderneath.normalVector,roofUnderneath.flatOutline[0]))
484
+ }
485
+ }
461
486
  return outline
462
487
  })
463
488
  return outlines