@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,80 +1,80 @@
1
-
2
1
  // Javascript program to print DFS
3
2
  // traversal from a given
4
3
  // graph
5
-
4
+
6
5
  // This class represents a
7
6
  // directed graph using adjacency
8
7
  // list representation
9
- export class Graph
10
- {
11
-
12
- // Constructor
13
- //v=number of vertices
14
- constructor()
15
- {
16
- this.visited=[]
17
- this.dict= []
18
- this.adj = []
19
-
8
+ export class Graph {
9
+ // Constructor
10
+ //v=number of vertices
11
+ constructor() {
12
+ this.visited = []
13
+ this.dict = []
14
+ this.adj = []
15
+ }
16
+
17
+ // Function to add an edge into the graph
18
+ addEdge(uuid1, uuid2) {
19
+ let v = this.dict.indexOf(uuid1)
20
+ let length
21
+ if (v == -1) {
22
+ length = this.dict.length
23
+ this.dict[length] = uuid1
24
+ this.adj[length] = []
25
+ v = length
20
26
  }
21
-
22
- // Function to add an edge into the graph
23
- addEdge(uuid1, uuid2)
24
- {
25
- let v=this.dict.indexOf(uuid1)
26
- let length
27
- if(v==-1){
28
- length=this.dict.length
29
- this.dict[length]=uuid1
30
- this.adj[length]=[]
31
- v=length
32
- }
33
- let w=this.dict.indexOf(uuid2)
34
- if(w==-1){
35
- length=this.dict.length
36
- this.dict[length]=uuid2
37
- this.adj[length]=[]
38
- w=length
39
- }
40
- // Add w to v's list.
41
- if(!this.adj[v]){this.adj[v]=[]}
42
- this.adj[v].push(w);
43
- if(!this.adj[w]){this.adj[w]=[]}
44
- this.adj[w].push(v);
27
+ let w = this.dict.indexOf(uuid2)
28
+ if (w == -1) {
29
+ length = this.dict.length
30
+ this.dict[length] = uuid2
31
+ this.adj[length] = []
32
+ w = length
45
33
  }
46
-
47
- // A function used by DFS
48
- DFSUtil(v, visited)
49
- {
50
-
51
- // Mark the current node as visited and print it
52
- visited[v] = true;
53
- this.visited.push(v)
54
-
55
- // Recur for all the vertices adjacent to this
56
- // vertex
57
- for(let i in this.adj[v])
58
- {
59
- let n = this.adj[v][i]
60
- if (!visited[n])
61
- this.DFSUtil(n, visited);
62
- }
34
+ // Add w to v's list.
35
+ if (!this.adj[v]) {
36
+ this.adj[v] = []
63
37
  }
64
-
65
- // The function to do DFS traversal.
66
- // It uses recursive
67
- // DFSUtil()
68
- DFS(uuidStart){
69
- let v=this.dict.indexOf(uuidStart)
70
- // Mark all the vertices as
71
- // not visited(set as
72
- // false by default in java)
73
- let visited = [];
74
- // Call the recursive helper
75
- // function to print DFS
76
- // traversal
77
- this.DFSUtil(v, visited);
78
- return [...new Set(this.visited.map((i)=>{return this.dict[i]}))]
38
+ this.adj[v].push(w)
39
+ if (!this.adj[w]) {
40
+ this.adj[w] = []
79
41
  }
42
+ this.adj[w].push(v)
43
+ }
44
+
45
+ // A function used by DFS
46
+ DFSUtil(v, visited) {
47
+ // Mark the current node as visited and print it
48
+ visited[v] = true
49
+ this.visited.push(v)
50
+
51
+ // Recur for all the vertices adjacent to this
52
+ // vertex
53
+ for (let i in this.adj[v]) {
54
+ let n = this.adj[v][i]
55
+ if (!visited[n]) this.DFSUtil(n, visited)
56
+ }
57
+ }
58
+
59
+ // The function to do DFS traversal.
60
+ // It uses recursive
61
+ // DFSUtil()
62
+ DFS(uuidStart) {
63
+ let v = this.dict.indexOf(uuidStart)
64
+ // Mark all the vertices as
65
+ // not visited(set as
66
+ // false by default in java)
67
+ let visited = []
68
+ // Call the recursive helper
69
+ // function to print DFS
70
+ // traversal
71
+ this.DFSUtil(v, visited)
72
+ return [
73
+ ...new Set(
74
+ this.visited.map((i) => {
75
+ return this.dict[i]
76
+ })
77
+ )
78
+ ]
79
+ }
80
80
  }
@@ -1,44 +1,47 @@
1
- import {Graph} from './DFS'
2
- import {
3
- isSameSegment2D,
4
- } from '../../geometry'
5
-
6
- export function generateGraph(polygons){
7
- const edges2D=[]
8
- const g=new Graph()
9
- polygons
10
- .filter((poly) => poly.layer=='roof')
11
- .forEach((polygon,index) => {
12
- g.dict.push(polygon.id)
13
- const outline = polygon.outline
14
- outline.forEach((point, i) => {
15
- //check if edge2D already exist
16
- const nextPoint = outline[(i + 1) % outline.length]
17
- let edge2D = edges2D.find((edge) => {
18
- return (
19
- isSameSegment2D([point, nextPoint], edge.outline)
20
- )
21
- })
22
- if (!edge2D) {
23
- //create an edge at this position
24
- edge2D = {}
25
- edge2D.outline=[point, nextPoint]
26
- edge2D.belongsTo = []
27
- edges2D.push(edge2D)
28
- }
29
- //add BelongToPolygon
30
- edge2D.belongsTo.push({
31
- polygonId: polygon.id,
32
- index: i,
33
- polygon
34
- })
35
- })
36
- })
37
- for(let k in edges2D){
38
- let edge=edges2D[k]
39
- if(edge.belongsTo.length==2){
40
- g.addEdge(edge.belongsTo[0].polygonId,edge.belongsTo[1].polygonId)
41
- }
42
- }
43
- return g
44
- }
1
+ import { Graph } from './DFS'
2
+ import { isSameSegment2D } from '../../geometry'
3
+
4
+ export function generateGraph(polygons, {includingRoofOnRoofs = true} = {}) {
5
+ const edges2D = []
6
+ const g = new Graph()
7
+ polygons
8
+ .filter((poly) => poly.layer == 'roof')
9
+ .forEach((polygon, index) => {
10
+ g.dict.push(polygon.id)
11
+ const outline = polygon.outline
12
+ outline.forEach((point, i) => {
13
+ //check if edge2D already exist
14
+ const nextPoint = outline[(i + 1) % outline.length]
15
+ let edge2D = edges2D.find((edge) => {
16
+ return isSameSegment2D([point, nextPoint], edge.outline)
17
+ })
18
+ if (!edge2D) {
19
+ //create an edge at this position
20
+ edge2D = {}
21
+ edge2D.outline = [point, nextPoint]
22
+ edge2D.belongsTo = []
23
+ edges2D.push(edge2D)
24
+ }
25
+ //add BelongToPolygon
26
+ edge2D.belongsTo.push({
27
+ polygonId: polygon.id,
28
+ index: i,
29
+ polygon
30
+ })
31
+ if (includingRoofOnRoofs && polygon.roofs && polygon.roofs.length == 1) {
32
+ edge2D.belongsTo.push({
33
+ polygonId: polygon.roofs[0].id,
34
+ index: null,
35
+ polygon: polygon.roofs[0]
36
+ })
37
+ }
38
+ })
39
+ })
40
+ for (let k in edges2D) {
41
+ let edge = edges2D[k]
42
+ if (edge.belongsTo.length == 2) {
43
+ g.addEdge(edge.belongsTo[0].polygonId, edge.belongsTo[1].polygonId)
44
+ }
45
+ }
46
+ return g
47
+ }
@@ -1,26 +1,26 @@
1
- import { Polygon } from "./Polygon"
2
- export function hydratePolygon(serializedPolygon){
3
- const layer=serializedPolygon.layer
4
- let polygon=new Polygon(serializedPolygon.outline,layer)
5
- polygon.id=serializedPolygon.id
6
- polygon.version=serializedPolygon.version
7
- polygon.name=serializedPolygon.name
8
- polygon.margins=serializedPolygon.margins
9
- if(layer=="obstacle"){
10
- polygon.isParallel=serializedPolygon.isParallel
11
- polygon.height=serializedPolygon.height
12
- }else if(layer=="moduleField"){
13
- polygon.data=serializedPolygon.data
14
- polygon.pvData=serializedPolygon.pvData
15
- polygon.mountingData=serializedPolygon.mountingData
16
- polygon.panels=[]
17
- polygon.userDeactivatedPanels=[]
18
- }else if(layer=="panel"){
19
- polygon.index=serializedPolygon.index
20
- polygon.moduleField=serializedPolygon.moduleField
21
- }else if(layer=="user_deactivated_panel"){
22
- polygon.index=serializedPolygon.index
23
- polygon.moduleField=serializedPolygon.moduleField
24
- }
25
- return polygon
26
- }
1
+ import { Polygon } from './Polygon'
2
+ export function hydratePolygon(serializedPolygon) {
3
+ const layer = serializedPolygon.layer
4
+ let polygon = new Polygon(serializedPolygon.outline, layer)
5
+ polygon.id = serializedPolygon.id
6
+ polygon.version = serializedPolygon.version
7
+ polygon.name = serializedPolygon.name
8
+ polygon.margins = serializedPolygon.margins
9
+ if (layer == 'obstacle') {
10
+ polygon.isParallel = serializedPolygon.isParallel
11
+ polygon.height = serializedPolygon.height
12
+ } else if (layer == 'moduleField') {
13
+ polygon.data = serializedPolygon.data
14
+ polygon.pvData = serializedPolygon.pvData
15
+ polygon.mountingData = serializedPolygon.mountingData
16
+ polygon.panels = []
17
+ polygon.userDeactivatedPanels = []
18
+ } else if (layer == 'panel') {
19
+ polygon.index = serializedPolygon.index
20
+ polygon.moduleField = serializedPolygon.moduleField
21
+ } else if (layer == 'user_deactivated_panel') {
22
+ polygon.index = serializedPolygon.index
23
+ polygon.moduleField = serializedPolygon.moduleField
24
+ }
25
+ return polygon
26
+ }
package/src/snap.js CHANGED
@@ -1,24 +1,30 @@
1
- import { addVector, crossProduct, dotProduct, multiplyVector, vectorLength } from "./vector";
1
+ import {
2
+ addVector,
3
+ crossProduct,
4
+ dotProduct,
5
+ multiplyVector,
6
+ vectorLength
7
+ } from './vector'
2
8
 
3
- export function snapRayToLine(ray,line){
4
- // Variables to record and compare
9
+ export function snapRayToLine(ray, line) {
10
+ // Variables to record and compare
5
11
 
6
- var u = ray.direction;
7
- var A = ray.origin;
8
- var v = line.direction;
9
- var B = line.origin;
12
+ var u = ray.direction
13
+ var A = ray.origin
14
+ var v = line.direction
15
+ var B = line.origin
10
16
 
11
- let n=crossProduct(v,u)
12
- let AB=substractVector(B,A)
13
- let dot=dotProduct(n,AB)
14
- let nLength=vectorLength(n)
15
- let distance=Math.abs(dot/nLength)
17
+ let n = crossProduct(v, u)
18
+ let AB = substractVector(B, A)
19
+ let dot = dotProduct(n, AB)
20
+ let nLength = vectorLength(n)
21
+ let distance = Math.abs(dot / nLength)
16
22
 
17
- let t1=dotProduct(crossProduct(v,n),AB)/dotProduct(n,n)
18
- let t2=dotProduct(crossProduct(u,n),AB)/dotProduct(n,n)
23
+ let t1 = dotProduct(crossProduct(v, n), AB) / dotProduct(n, n)
24
+ let t2 = dotProduct(crossProduct(u, n), AB) / dotProduct(n, n)
19
25
 
20
- let M=addVector(A,multiplyVector(t1,u))
21
- let N=addVector(B,multiplyVector(t2,v))
26
+ let M = addVector(A, multiplyVector(t1, u))
27
+ let N = addVector(B, multiplyVector(t2, v))
22
28
 
23
- return {distance,pointOnRay:M,pointOnLine:N}
24
- }
29
+ return { distance, pointOnRay: M, pointOnLine: N }
30
+ }