@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/.eslintrc.js +28 -0
- package/.prettierrc +7 -0
- package/babel.config.js +2 -2
- package/eslint.config.mjs +10 -0
- package/package.json +5 -3
- package/src/config.js +110 -50
- package/src/coords.js +21 -21
- package/src/geo.js +111 -100
- package/src/geometry.js +920 -819
- package/src/index.js +10 -11
- package/src/intersectionPolygon.js +34 -28
- package/src/lib/concaveman.js +181 -181
- package/src/matrix.js +56 -50
- package/src/miscellaneous.js +45 -0
- package/src/objects/Circle.js +76 -41
- package/src/objects/Line.js +275 -177
- package/src/objects/Point.js +30 -27
- package/src/objects/Polygon.js +324 -243
- package/src/objects/derivedState/AddMargin.js +142 -145
- package/src/objects/derivedState/updateComputedGeometryPolygon.js +274 -253
- package/src/objects/graph/DFS.js +69 -69
- package/src/objects/graph/graphCreation.js +47 -44
- package/src/objects/hydrate.js +26 -26
- package/src/snap.js +24 -18
- package/src/splitMergePolygons.js +585 -521
- package/src/test/maths.test.js +7 -7
- package/src/vector.js +66 -66
package/src/objects/graph/DFS.js
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
48
|
-
|
|
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
|
-
|
|
66
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
}
|
package/src/objects/hydrate.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { Polygon } from
|
|
2
|
-
export function hydratePolygon(serializedPolygon){
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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 {
|
|
1
|
+
import {
|
|
2
|
+
addVector,
|
|
3
|
+
crossProduct,
|
|
4
|
+
dotProduct,
|
|
5
|
+
multiplyVector,
|
|
6
|
+
vectorLength
|
|
7
|
+
} from './vector'
|
|
2
8
|
|
|
3
|
-
export function snapRayToLine(ray,line){
|
|
4
|
-
|
|
9
|
+
export function snapRayToLine(ray, line) {
|
|
10
|
+
// Variables to record and compare
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
var u = ray.direction
|
|
13
|
+
var A = ray.origin
|
|
14
|
+
var v = line.direction
|
|
15
|
+
var B = line.origin
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
18
|
-
|
|
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
|
-
|
|
21
|
-
|
|
26
|
+
let M = addVector(A, multiplyVector(t1, u))
|
|
27
|
+
let N = addVector(B, multiplyVector(t2, v))
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
}
|
|
29
|
+
return { distance, pointOnRay: M, pointOnLine: N }
|
|
30
|
+
}
|