@eturnity/eturnity_3d 9.37.0 → 9.40.0

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_3d",
3
3
  "private": false,
4
- "version": "9.37.0",
4
+ "version": "9.40.0",
5
5
  "files": [
6
6
  "dist",
7
7
  "src"
@@ -17,7 +17,7 @@
17
17
  "merge-remote-master": "node scripts/merge-remote-master.js"
18
18
  },
19
19
  "dependencies": {
20
- "@eturnity/eturnity_maths": "9.37.0",
20
+ "@eturnity/eturnity_maths": "9.40.0",
21
21
  "@originjs/vite-plugin-commonjs": "1.0.3",
22
22
  "core-js": "3.30.2",
23
23
  "cors": "2.8.5",
@@ -120,6 +120,47 @@ export function updateModuleFieldFittingPanels(moduleField) {
120
120
  }
121
121
  }
122
122
 
123
+ // Guarded variant of updateModuleFieldFittingPanels used by the new panel
124
+ // placement engine: preserves the current visibility, tolerates fields without
125
+ // panels/roof/margins, and skips the fitting_panel_area_m2 check.
126
+ export function clipModuleFieldFittingPanels(moduleField) {
127
+ const prevVisible = moduleField?.fittingPanels?.visible
128
+ delete moduleField.fittingPanels
129
+ if (!moduleField?.panels?.length) return
130
+ if (!moduleField?.roof || !moduleField.data?.has_fitting_panels) return
131
+ const innerOutline = moduleField.roof.margins?.innerOutline
132
+ if (!innerOutline?.length) return
133
+
134
+ const outlines = getModuleFieldRoofIntersections(moduleField, innerOutline)
135
+ if (!outlines?.length) return
136
+ const holes = getModuleFieldHoleOutlines(moduleField)
137
+ const polygons = []
138
+
139
+ outlines.forEach((outline) => {
140
+ polygons.push({
141
+ outline,
142
+ // Clean up holes outside of the outline
143
+ holes: holes
144
+ .flatMap((hole) => intersectOutlines(hole, outline))
145
+ .filter(Boolean),
146
+ })
147
+ })
148
+ if (!polygons.length) return
149
+
150
+ const hasCustomTexture = !!moduleField.pvData?.texture_img_url
151
+ const defaultTextureIndex = moduleField.pvData?.module_texture_version_id || 0
152
+ const color = hasCustomTexture
153
+ ? moduleField.pvData?.backsheet_color
154
+ : defaultTextureColorMap[defaultTextureIndex]
155
+ const mappedColor = fittingPanelsColorMap[color || 'default']
156
+
157
+ moduleField.fittingPanels = {
158
+ polygons,
159
+ visible: prevVisible !== false,
160
+ color: mappedColor,
161
+ }
162
+ }
163
+
123
164
  export function getRoofInnerMarginOutline({
124
165
  roof,
125
166
  moduleField,
@@ -0,0 +1,81 @@
1
+ import {
2
+ clipModuleFieldFittingPanels,
3
+ updateModuleFieldFittingPanels,
4
+ } from './UpdateRoofModuleFieldRelations'
5
+
6
+ function rect(x, y, width, height) {
7
+ return [
8
+ { x, y, z: 0 },
9
+ { x: x + width, y, z: 0 },
10
+ { x: x + width, y: y + height, z: 0 },
11
+ { x, y: y + height, z: 0 },
12
+ ]
13
+ }
14
+
15
+ function buildModuleField({ data = { has_fitting_panels: true } } = {}) {
16
+ const roof = {
17
+ id: 'roof-1',
18
+ normalVector: { x: 0, y: 0, z: 1 },
19
+ flatOutline: [{ x: 0, y: 0, z: 0 }],
20
+ margins: { innerOutline: rect(0, 0, 10000, 10000) },
21
+ holes: [],
22
+ moduleFields: [],
23
+ }
24
+ return {
25
+ id: 'mf-1',
26
+ layer: 'moduleField',
27
+ outline: rect(1000, 1000, 4000, 4000),
28
+ roof,
29
+ panels: [{ id: 'panel-1' }],
30
+ data,
31
+ pvData: {},
32
+ priority: 0,
33
+ }
34
+ }
35
+
36
+ describe('clipModuleFieldFittingPanels', () => {
37
+ test('builds fitting panels clipped to the roof inner outline', () => {
38
+ const moduleField = buildModuleField()
39
+ clipModuleFieldFittingPanels(moduleField)
40
+ expect(moduleField.fittingPanels).toBeDefined()
41
+ expect(moduleField.fittingPanels.polygons.length).toBeGreaterThan(0)
42
+ expect(moduleField.fittingPanels.visible).toBe(true)
43
+ })
44
+
45
+ test('preserves an explicitly hidden visibility across rebuilds', () => {
46
+ const moduleField = buildModuleField()
47
+ clipModuleFieldFittingPanels(moduleField)
48
+ moduleField.fittingPanels.visible = false
49
+ clipModuleFieldFittingPanels(moduleField)
50
+ expect(moduleField.fittingPanels.visible).toBe(false)
51
+ })
52
+
53
+ test('removes fitting panels for a field without panels', () => {
54
+ const moduleField = buildModuleField()
55
+ moduleField.fittingPanels = { polygons: [], visible: true }
56
+ moduleField.panels = []
57
+ clipModuleFieldFittingPanels(moduleField)
58
+ expect(moduleField.fittingPanels).toBeUndefined()
59
+ })
60
+
61
+ test('tolerates a field without roof or fitting-panel data', () => {
62
+ const noRoof = buildModuleField()
63
+ noRoof.roof = null
64
+ expect(() => clipModuleFieldFittingPanels(noRoof)).not.toThrow()
65
+ expect(noRoof.fittingPanels).toBeUndefined()
66
+
67
+ const noData = buildModuleField({ data: { has_fitting_panels: false } })
68
+ clipModuleFieldFittingPanels(noData)
69
+ expect(noData.fittingPanels).toBeUndefined()
70
+ })
71
+
72
+ test('does not require fitting_panel_area_m2, unlike the legacy builder', () => {
73
+ const clipped = buildModuleField()
74
+ clipModuleFieldFittingPanels(clipped)
75
+ expect(clipped.fittingPanels).toBeDefined()
76
+
77
+ const legacy = buildModuleField()
78
+ updateModuleFieldFittingPanels(legacy)
79
+ expect(legacy.fittingPanels).toBeUndefined()
80
+ })
81
+ })