@eturnity/eturnity_maths 6.32.0 → 6.33.0-qa.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_maths",
3
- "version": "6.32.0",
3
+ "version": "6.33.0-qa.0",
4
4
  "author": "Eturnity Team",
5
5
  "main": "src/index.js",
6
6
  "private": false,
package/src/geo.js CHANGED
@@ -2,8 +2,66 @@ import {
2
2
  earthRadius
3
3
  } from './config'
4
4
 
5
+
6
+ export function lon2tile(lon,zoom) { return (Math.floor((lon+180)/360*Math.pow(2,zoom))); }
7
+ export function lat2tile(lat,zoom) { return (Math.floor((1-Math.log(Math.tan(lat*Math.PI/180) + 1/Math.cos(lat*Math.PI/180))/Math.PI)/2 *Math.pow(2,zoom))); }
8
+ export function tile2long(x,z) {
9
+ return (x/Math.pow(2,z)*360-180);
10
+ }
11
+ export function tile2lat(y,z) {
12
+ var n=Math.PI-2*Math.PI*y/Math.pow(2,z);
13
+ return (180/Math.PI*Math.atan(0.5*(Math.exp(n)-Math.exp(-n))));
14
+ }
15
+ export function latLngToTileXY(lat,lng,zoom){
16
+ const xTile = lon2tile(lng,zoom)
17
+ const yTile = lat2tile(lat,zoom)
18
+ return {
19
+ x:xTile,
20
+ y:yTile
21
+ }
22
+ }
23
+
24
+ export function tileXYZToLatLng(x,y,zoom){
25
+ const longitude=tile2long(x,zoom)
26
+ const latitude=tile2lat(y,zoom)
27
+ return {lat: latitude,lng: longitude};
28
+ }
5
29
 
6
- export function distanceToDeltaLatLng(x, y, latitude) {
30
+ export function tileToCorners(x,y,zoom,lat,lng){
31
+ const tileAltitude=0
32
+ const tileLatLng=tileXYZToLatLng(x,y,zoom)
33
+ const deltaLat=tileLatLng.lat-lat
34
+ const deltaLng=tileLatLng.lng-lng
35
+ let { x:x_mm, y:y_mm }=deltaLatLngToDistance(deltaLat, deltaLng, lat)
36
+ let size=(earthRadius * 2000 * Math.PI / Math.pow(2.0, zoom))*Math.cos(lat*Math.PI/180)
37
+ let corner0={
38
+ x:x_mm,
39
+ y:y_mm,
40
+ z:tileAltitude
41
+ }
42
+ let corner1={
43
+ x:x_mm+size,
44
+ y:y_mm,
45
+ z:tileAltitude
46
+ }
47
+ let corner2={
48
+ x:x_mm+size,
49
+ y:y_mm-size,
50
+ z:tileAltitude
51
+ }
52
+ let corner3={
53
+ x:x_mm,
54
+ y:y_mm-size,
55
+ z:tileAltitude
56
+ }
57
+ return [
58
+ corner3,
59
+ corner0,
60
+ corner1,
61
+ corner2,
62
+ ]
63
+ }
64
+ export function distanceToDeltaLatLng(x, y, latitude) {
7
65
  //x,y,z in ENU coords
8
66
  let lat = (180 / Math.PI) * (y / 1000) / earthRadius
9
67
  let lng =((180 / Math.PI) * (x / 1000) / earthRadius)/(Math.cos(((latitude) * Math.PI) / 180))
@@ -21,7 +21,7 @@ export function updateComputedGeometryState(state) {
21
21
  })
22
22
  return state
23
23
  }
24
- export function updateOutlineFromInclineDirection(incline, direction, outline,initialAverageHeight) {
24
+ export function updateOutlineFromInclineDirection(incline, direction, outline,initialAverageHeight,isRoofOnRoof = false) {
25
25
  const newNormalVector = {}
26
26
  newNormalVector.x =
27
27
  Math.sin((incline * Math.PI) / 180) * Math.sin((direction * Math.PI) / 180)
@@ -29,14 +29,21 @@ export function updateOutlineFromInclineDirection(incline, direction, outline,in
29
29
  Math.sin((incline * Math.PI) / 180) * Math.cos((direction * Math.PI) / 180)
30
30
  newNormalVector.z = Math.cos((incline * Math.PI) / 180)
31
31
  let meanPoint = meanVector(outline)
32
- let minAltitude=Math.min(...outline.map(p=>p.z))
33
32
  meanPoint.z=initialAverageHeight
34
33
  let newOutline = outline.map((p) => {
35
34
  return verticalProjectionOnPlane(p, newNormalVector, meanPoint)
36
35
  })
37
36
  //if some points are with negative altitude, we offset the whole roof
38
- const newMinAltitude = Math.min(...newOutline.map((p) => p.z))
39
- let altitudeOffset=newMinAltitude-minAltitude
37
+ let altitudeOffset
38
+ let minAltitude=Math.min(...outline.map(p=>p.z))
39
+ let maxAltitude=Math.max(...outline.map(p=>p.z))
40
+ let newMinAltitude = Math.min(...newOutline.map((p) => p.z))
41
+ let newMaxAltitude = Math.max(...newOutline.map((p) => p.z))
42
+ if(isRoofOnRoof && maxAltitude!=0){
43
+ altitudeOffset=newMaxAltitude-maxAltitude
44
+ }else{
45
+ altitudeOffset=newMinAltitude-minAltitude
46
+ }
40
47
  newOutline.forEach((p) => (p.z -= altitudeOffset))
41
48
 
42
49
  //if some points are with altitude>50000, we limit those points