@eturnity/eturnity_maths 1.0.2
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/babel.config.js +3 -0
- package/package.json +30 -0
- package/src/assets/theme.js +45 -0
- package/src/config.js +77 -0
- package/src/coords.js +24 -0
- package/src/geo.js +51 -0
- package/src/geometry.js +760 -0
- package/src/index.js +10 -0
- package/src/intersectionPolygon.js +623 -0
- package/src/matrix.js +53 -0
- package/src/objects/Circle.js +51 -0
- package/src/objects/Line.js +110 -0
- package/src/objects/Point.js +57 -0
- package/src/objects/Polygon.js +240 -0
- package/src/objects/derivedState/AddMargin.js +109 -0
- package/src/objects/derivedState/UpdateRoofModuleFieldRelations.js +119 -0
- package/src/objects/derivedState/UpdateRoofObstacleRelations.js +86 -0
- package/src/objects/derivedState/index.js +2 -0
- package/src/objects/derivedState/updateComputedGeometryPolygon.js +168 -0
- package/src/objects/graph/DFS.js +80 -0
- package/src/objects/graph/graphCreation.js +44 -0
- package/src/objects/hydrate.js +24 -0
- package/src/objects/index.js +8 -0
- package/src/splitMergePolygons.js +553 -0
- package/src/test/maths.test.js +10 -0
- package/src/vector.js +56 -0
- package/webpack.config.js +11 -0
package/babel.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eturnity/eturnity_maths",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"author": "Eturnity Team",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"private": false,
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+ssh://git@bitbucket.org/eturnitydevs/eturnity_maths.git"
|
|
13
|
+
},
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"homepage": "https://bitbucket.org/eturnitydevs/eturnity_maths#readme",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"lodash": "^4.17.21",
|
|
18
|
+
"paper": "^0.12.17",
|
|
19
|
+
"planar-face-discovery": "^2.0.7",
|
|
20
|
+
"svd-js": "^1.1.1",
|
|
21
|
+
"uuid": "^9.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@babel/core": "^7.21.4",
|
|
25
|
+
"@babel/preset-env": "^7.21.4",
|
|
26
|
+
"babel-jest": "^29.5.0",
|
|
27
|
+
"jest": "^29.5.0"
|
|
28
|
+
},
|
|
29
|
+
"description": ""
|
|
30
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const theme = {
|
|
2
|
+
colors: {
|
|
3
|
+
primary: '#282387',
|
|
4
|
+
secondary: '#818181',
|
|
5
|
+
tertiary: '#d5d5d5',
|
|
6
|
+
black: '#263238',
|
|
7
|
+
yellow: '#fdb813',
|
|
8
|
+
darkGray: '#818181',
|
|
9
|
+
mediumGray: '#d5d5d5',
|
|
10
|
+
lightGray: '#f2f2f2',
|
|
11
|
+
white: '#ffffff',
|
|
12
|
+
blue: '#48a2d0',
|
|
13
|
+
brightBlue: '#0068DE',
|
|
14
|
+
ballBlue: '#2CC0EB',
|
|
15
|
+
red: '#FF5656',
|
|
16
|
+
blue1: '#e4efff',
|
|
17
|
+
blue2: '#F6FAFF',
|
|
18
|
+
grey1: '#666',
|
|
19
|
+
grey2: '#c4c4c4',
|
|
20
|
+
grey3: '#b2b9c5',
|
|
21
|
+
grey4: '#dee2eb',
|
|
22
|
+
grey5: '#fafafa',
|
|
23
|
+
grey6: '#555d61',
|
|
24
|
+
turquoise: '#20A4CA',
|
|
25
|
+
green: '#99db0c',
|
|
26
|
+
purple: '#505ca6',
|
|
27
|
+
disabled: '#dfe1e1',
|
|
28
|
+
transparentWhite1: '#ffffff32',
|
|
29
|
+
transparentBlack1: '#263238e6',
|
|
30
|
+
transparentBlue1: '#20a4cae6',
|
|
31
|
+
blueElectric: '#66dffa',
|
|
32
|
+
eturnityGrey: '#263238'
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
screen: {
|
|
36
|
+
mobileSmall: '345px',
|
|
37
|
+
mobile: '425px',
|
|
38
|
+
mobileLarge: '530px',
|
|
39
|
+
tablet: '768px',
|
|
40
|
+
tabletLarge: '950px'
|
|
41
|
+
},
|
|
42
|
+
borderRadius: '4px'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default theme
|
package/src/config.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import theme from './assets/theme'
|
|
2
|
+
|
|
3
|
+
export const polygonCloseTolerance=15
|
|
4
|
+
export const snapToPointTolerance = 15
|
|
5
|
+
export const snapToIntersectionPointTolerance = 15
|
|
6
|
+
export const snapToLineTolerance = 10
|
|
7
|
+
export const distanceToCloseNode = 70
|
|
8
|
+
export const mmTolerance=50
|
|
9
|
+
export const earthRadius=6371008
|
|
10
|
+
|
|
11
|
+
export const layerColors = {
|
|
12
|
+
construction: { fillColor: 'transparent', strokeColor: theme.colors.blueElectric ,strokeWidth:3 },
|
|
13
|
+
roof: { fillColor: 'rgba(255, 255, 255, 0.1)', strokeColor: 'white' ,strokeWidth:0 },
|
|
14
|
+
roofInside: { fillColor: 'rgba(255, 255, 255, 0.1)', strokeColor: 'white' ,strokeWidth:1},
|
|
15
|
+
obstacle: { fillColor: theme.colors.red, strokeColor: 'red' ,strokeWidth:1 },
|
|
16
|
+
panel: { fillColor: 'rgba(115, 115, 229, 0.1)', strokeColor: '#ffffff' ,strokeWidth:1},
|
|
17
|
+
user_deactivated_panel: { fillColor: 'rgba(115, 115, 229, 0.1)', strokeColor: 'white' ,strokeWidth:4},
|
|
18
|
+
selectedPanel: { fillColor: '#0068DE80', strokeColor: theme.colors.blue ,strokeWidth:1},
|
|
19
|
+
snap: { fillColor: 'transparent', strokeColor: 'white' },
|
|
20
|
+
moduleField: { fillColor: 'rgba(255, 255, 255, 0.1)', strokeColor: 'white' ,strokeWidth:3 },
|
|
21
|
+
hoveredModuleFieldEdge: { strokeColor: theme.colors.blue ,strokeWidth:6 },
|
|
22
|
+
tmpModuleField: { fillColor: 'rgba(115, 115, 229, 0.4)', strokeColor: theme.colors.blue ,strokeWidth:2 },
|
|
23
|
+
selectedModuleField: {fillColor: '#0068DE80', strokeColor: theme.colors.blue ,strokeWidth:3},
|
|
24
|
+
highlight: { fillColor: 'rgba(255, 255, 255, 0.2)', strokeColor: 'white' ,strokeWidth:1 },
|
|
25
|
+
selectedRoof: { fillColor: '#0068DE80', strokeColor: 'white' ,strokeWidth:3 },
|
|
26
|
+
selectedObstacle: { fillColor: '#0068DE80', strokeColor: theme.colors.blue ,strokeWidth:2 },
|
|
27
|
+
selectedAndHighlighted: {fillColor: '#0068DEA0', strokeColor: theme.colors.blue ,strokeWidth:3},
|
|
28
|
+
flatWarning: {fillColor: '#ffff0090', strokeColor: 'yellow' ,strokeWidth:1},
|
|
29
|
+
customLength: { fillColor: 'transparent', strokeColor: theme.colors.blueElectric ,strokeWidth:1 }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const baseEdgeOfModuleField=theme.colors.blueElectric
|
|
33
|
+
export const maximumGapLimit=500
|
|
34
|
+
export const defaultBaseHeight=3000
|
|
35
|
+
export const colorArrayBase=[
|
|
36
|
+
"#FF5656",
|
|
37
|
+
"#FDB813",
|
|
38
|
+
"#505CA6",
|
|
39
|
+
"#C84E4E",
|
|
40
|
+
"#8392EE",
|
|
41
|
+
"#6CD5D5",
|
|
42
|
+
"#90A650",
|
|
43
|
+
"#D27CCA",
|
|
44
|
+
"#6276DF",
|
|
45
|
+
]
|
|
46
|
+
export const colorArray=colorArrayBase.map(c=>c+"c0")
|
|
47
|
+
export const layerTools={
|
|
48
|
+
map:[],
|
|
49
|
+
roof:["drawRoof","selectRoof"],
|
|
50
|
+
obstacle:["drawObstacle"],
|
|
51
|
+
margin:["selectMargin"],
|
|
52
|
+
panel:["selectModuleField"],
|
|
53
|
+
}
|
|
54
|
+
//3D visualisation:
|
|
55
|
+
export const beamRadius=0.05
|
|
56
|
+
export const maxMargin=2500
|
|
57
|
+
export const node3DRadius=0.05
|
|
58
|
+
export const beamColor="#ffffff"
|
|
59
|
+
export const node3DColor="white"
|
|
60
|
+
export const beamOpacity=0.3
|
|
61
|
+
export const node3dOpacity=0.3
|
|
62
|
+
export const dimMarginColor='#ff000020'
|
|
63
|
+
export const hitOption = {
|
|
64
|
+
segments: true,
|
|
65
|
+
stroke: true,
|
|
66
|
+
fill: true,
|
|
67
|
+
tolerance: 10
|
|
68
|
+
}
|
|
69
|
+
export const zoomFactor=Math.exp(Math.log(2)/10)
|
|
70
|
+
export const hitOptionPolygonStrict = {
|
|
71
|
+
segments: false,
|
|
72
|
+
stroke: false,
|
|
73
|
+
fill: true,
|
|
74
|
+
tolerance: 0
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const dragHeightSensitivity=20
|
package/src/coords.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function toRealityRefFunction(canvasSize, mmPerPx, layoutOffset) {
|
|
2
|
+
return (point) => {
|
|
3
|
+
let realityX = (point.x - layoutOffset.x) * mmPerPx
|
|
4
|
+
// let realityY = -(point.y - layoutOffset.y - (canvasSize.height*layoutOffset.zoom)/(100 * 2)) * mmPerPx
|
|
5
|
+
let realityY = -( point.y - layoutOffset.y) * mmPerPx
|
|
6
|
+
|
|
7
|
+
return { x: realityX, y: realityY, z: point.z }
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function toCanvasRefFunction(canvasSize, mmPerPx, layoutOffset) {
|
|
11
|
+
return (point) => {
|
|
12
|
+
if (!point) {
|
|
13
|
+
console.error('no point', point)
|
|
14
|
+
}
|
|
15
|
+
if (!canvasSize) {
|
|
16
|
+
console.error('no canvas Size')
|
|
17
|
+
return null
|
|
18
|
+
}
|
|
19
|
+
let canvasX = layoutOffset.x + point.x / mmPerPx
|
|
20
|
+
let canvasY = layoutOffset.y - point.y / mmPerPx
|
|
21
|
+
|
|
22
|
+
return { x: canvasX, y: canvasY, z: point.z }
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/geo.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Point } from 'paper/dist/paper-core'
|
|
2
|
+
import {
|
|
3
|
+
polygonCloseTolerance,
|
|
4
|
+
earthRadius
|
|
5
|
+
} from './config'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export function distanceToDeltaLatLng(x, y, latitude) {
|
|
9
|
+
//x,y,z in ENU coords
|
|
10
|
+
let lat = (180 / Math.PI) * (y / 1000) / earthRadius
|
|
11
|
+
let lng =((180 / Math.PI) * (x / 1000) / earthRadius)/(Math.cos(((latitude) * Math.PI) / 180))
|
|
12
|
+
return { lat, lng }
|
|
13
|
+
}
|
|
14
|
+
export function deltaLatLngToDistance(deltaLat, deltaLng, latitude) {
|
|
15
|
+
//x,y,z in ENU coords
|
|
16
|
+
let y=earthRadius * deltaLat *1000/(180 / Math.PI)
|
|
17
|
+
let x=earthRadius* deltaLng * 1000 *(Math.cos(((latitude) * Math.PI) / 180))/(180 / Math.PI)
|
|
18
|
+
return { x, y }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function datum2spherical(lat1, lat2, lng1, lng2) {
|
|
22
|
+
const earthOrigin = Math.PI * earthRadius
|
|
23
|
+
|
|
24
|
+
//const d = earthRadius * arccos[(sin(lat1) * sin(lat2)) + cos(lat1) * cos(lat2) * cos(lng2 – lng1)]
|
|
25
|
+
const averageLat = (lat1 + lat2) / 2
|
|
26
|
+
const x =
|
|
27
|
+
1000 *
|
|
28
|
+
earthRadius *
|
|
29
|
+
arccos(
|
|
30
|
+
sin(averageLat) * sin(averageLat) +
|
|
31
|
+
cos(averageLat) * cos(averageLat) * cos(lng2 - lng1)
|
|
32
|
+
)
|
|
33
|
+
const y =
|
|
34
|
+
1000 * earthRadius * arccos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2))
|
|
35
|
+
|
|
36
|
+
// const x = longitude * earthOrigin / 180.0;
|
|
37
|
+
// let y = Math.log(Math.tan((90 + latitude) * Math.PI / 360.0)) / (Math.PI / 180.0);
|
|
38
|
+
|
|
39
|
+
// y = y * earthOrigin / 180.0;
|
|
40
|
+
|
|
41
|
+
return { x, y }
|
|
42
|
+
}
|
|
43
|
+
function cos(deg) {
|
|
44
|
+
return Math.cos((deg * Math.PI) / 180)
|
|
45
|
+
}
|
|
46
|
+
function sin(deg) {
|
|
47
|
+
return Math.sin((deg * Math.PI) / 180)
|
|
48
|
+
}
|
|
49
|
+
function arccos(val) {
|
|
50
|
+
return Math.acos(val)
|
|
51
|
+
}
|