@openglobus/og 0.16.3 → 0.17.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.
Files changed (197) hide show
  1. package/README.md +1 -1
  2. package/css/og.css +24 -2
  3. package/dist/@openglobus/og.css +1 -1
  4. package/dist/@openglobus/og.esm.js +2 -2
  5. package/dist/@openglobus/og.esm.js.map +1 -1
  6. package/dist/@openglobus/og.umd.js +2 -2
  7. package/dist/@openglobus/og.umd.js.map +1 -1
  8. package/package.json +1 -1
  9. package/src/og/Clock.js +1 -5
  10. package/src/og/Events.js +2 -6
  11. package/src/og/Extent.js +5 -9
  12. package/src/og/Globe.js +93 -56
  13. package/src/og/ImageCanvas.js +13 -6
  14. package/src/og/Lock.js +44 -48
  15. package/src/og/LonLat.js +1 -5
  16. package/src/og/Object3d.js +2 -2
  17. package/src/og/QueueArray.js +1 -1
  18. package/src/og/Stack.js +49 -53
  19. package/src/og/astro/earth.js +112 -116
  20. package/src/og/astro/jd.js +514 -518
  21. package/src/og/astro/orbit.js +119 -123
  22. package/src/og/astro/rotation.js +36 -40
  23. package/src/og/bv/Box.js +77 -81
  24. package/src/og/bv/Sphere.js +57 -61
  25. package/src/og/camera/Camera.js +20 -7
  26. package/src/og/camera/Frustum.js +4 -4
  27. package/src/og/camera/PlanetCamera.js +15 -22
  28. package/src/og/cons.js +1 -1
  29. package/src/og/control/Atmosphere.js +0 -4
  30. package/src/og/control/Control.js +9 -8
  31. package/src/og/control/DebugInfo.js +3 -7
  32. package/src/og/control/DrawingSwitcher.js +117 -0
  33. package/src/og/control/EarthCoordinates.js +214 -214
  34. package/src/og/control/EarthNavigation.js +6 -13
  35. package/src/og/control/GeoImageDragControl.js +0 -4
  36. package/src/og/control/KeyboardNavigation.js +0 -4
  37. package/src/og/control/LayerAnimation.js +0 -4
  38. package/src/og/control/LayerSwitcher.js +2 -4
  39. package/src/og/control/Lighting.js +12 -16
  40. package/src/og/control/MouseNavigation.js +1 -5
  41. package/src/og/control/MouseWheelZoomControl.js +0 -4
  42. package/src/og/control/RulerSwitcher.js +0 -4
  43. package/src/og/control/ScaleControl.js +2 -6
  44. package/src/og/control/ShowFps.js +40 -44
  45. package/src/og/control/SimpleNavigation.js +10 -10
  46. package/src/og/control/SimpleSkyBackground.js +0 -4
  47. package/src/og/control/Sun.js +0 -4
  48. package/src/og/control/ToggleWireframe.js +35 -39
  49. package/src/og/control/ZoomControl.js +0 -4
  50. package/src/og/control/drawing/DrawingControl.js +51 -0
  51. package/src/og/control/drawing/LineStringDrawingScene.js +203 -0
  52. package/src/og/control/drawing/PolygonDrawingScene.js +785 -0
  53. package/src/og/control/elevationProfile/ElevationProfile.js +275 -0
  54. package/src/og/control/index.js +5 -1
  55. package/src/og/control/ruler/Ruler.js +0 -4
  56. package/src/og/control/ruler/RulerScene.js +3 -2
  57. package/src/og/control/selection/Selection.js +0 -4
  58. package/src/og/control/selection/SelectionScene.js +2 -4
  59. package/src/og/control/timeline/TimelineControl.js +4 -4
  60. package/src/og/control/timeline/TimelineModel.js +2 -2
  61. package/src/og/control/timeline/TimelineView.js +1 -0
  62. package/src/og/control/visibleExtent/Segment.js +7 -7
  63. package/src/og/control/visibleExtent/drawnode.js +0 -4
  64. package/src/og/ellipsoid/Ellipsoid.js +236 -325
  65. package/src/og/ellipsoid/wgs84.js +0 -4
  66. package/src/og/entity/BaseBillboard.js +375 -379
  67. package/src/og/entity/Billboard.js +0 -4
  68. package/src/og/entity/BillboardHandler.js +3 -7
  69. package/src/og/entity/Entity.js +22 -22
  70. package/src/og/entity/EntityCollection.js +14 -18
  71. package/src/og/entity/GeoObject.js +6 -8
  72. package/src/og/entity/GeoObjectHandler.js +30 -24
  73. package/src/og/entity/Geometry.js +5 -4
  74. package/src/og/entity/GeometryHandler.js +18 -19
  75. package/src/og/entity/Label.js +0 -4
  76. package/src/og/entity/LabelHandler.js +10 -14
  77. package/src/og/entity/LabelWorker.js +1 -1
  78. package/src/og/entity/PointCloud.js +2 -6
  79. package/src/og/entity/PointCloudHandler.js +122 -126
  80. package/src/og/entity/Polyline.js +15 -17
  81. package/src/og/entity/PolylineHandler.js +104 -108
  82. package/src/og/entity/Ray.js +29 -29
  83. package/src/og/entity/RayHandler.js +2 -2
  84. package/src/og/entity/Strip.js +1 -1
  85. package/src/og/entity/StripHandler.js +2 -2
  86. package/src/og/index.js +3 -1
  87. package/src/og/input/KeyboardHandler.js +128 -132
  88. package/src/og/input/MouseHandler.js +94 -98
  89. package/src/og/input/TouchHandler.js +59 -63
  90. package/src/og/input/input.js +44 -48
  91. package/src/og/layer/BaseGeoImage.js +6 -9
  92. package/src/og/layer/CanvasTiles.js +1 -5
  93. package/src/og/layer/GeoImage.js +0 -4
  94. package/src/og/layer/GeoTexture2d.js +0 -4
  95. package/src/og/layer/GeoVideo.js +0 -4
  96. package/src/og/layer/KML.js +1 -0
  97. package/src/og/layer/Layer.js +22 -26
  98. package/src/og/layer/Material.js +0 -4
  99. package/src/og/layer/Vector.js +25 -22
  100. package/src/og/layer/WMS.js +182 -186
  101. package/src/og/layer/XYZ.js +0 -4
  102. package/src/og/light/LightSource.js +0 -4
  103. package/src/og/math/Line2.js +28 -32
  104. package/src/og/math/Mat3.js +152 -156
  105. package/src/og/math/Ray.js +0 -4
  106. package/src/og/math/Vec2.js +0 -4
  107. package/src/og/math/Vec3.js +5 -4
  108. package/src/og/math/Vec4.js +0 -4
  109. package/src/og/math/coder.js +104 -104
  110. package/src/og/math.js +42 -10
  111. package/src/og/mercator.js +1 -1
  112. package/src/og/proj/EPSG3857.js +13 -13
  113. package/src/og/proj/Proj.js +59 -63
  114. package/src/og/quadTree/EPSG4326QuadTreeStrategy.js +1 -0
  115. package/src/og/quadTree/EarthQuadTreeStrategy.js +1 -0
  116. package/src/og/quadTree/EntityCollectionNode.js +12 -16
  117. package/src/og/quadTree/MarsQuadTreeStrategy.js +1 -0
  118. package/src/og/quadTree/Node.js +15 -14
  119. package/src/og/quadTree/QuadTreeStrategy.js +1 -0
  120. package/src/og/quadTree/Wgs84QuadTreeStrategy.js +1 -0
  121. package/src/og/renderer/Renderer.js +114 -27
  122. package/src/og/renderer/RendererEvents.js +0 -4
  123. package/src/og/scene/Axes.js +74 -78
  124. package/src/og/scene/BaseNode.js +1 -5
  125. package/src/og/scene/Planet.js +127 -130
  126. package/src/og/scene/RenderNode.js +20 -12
  127. package/src/og/scene/SkyBox.js +104 -108
  128. package/src/og/segment/Segment.js +10 -6
  129. package/src/og/segment/SegmentLonLat.js +3 -7
  130. package/src/og/segment/segmentHelper.js +229 -225
  131. package/src/og/shaders/atmos.js +1 -1
  132. package/src/og/shaders/billboard.js +0 -4
  133. package/src/og/shaders/drawnode.js +5 -9
  134. package/src/og/shaders/geoObject.js +0 -4
  135. package/src/og/shaders/label.js +0 -4
  136. package/src/og/shaders/pickingMask.js +0 -4
  137. package/src/og/shaders/pointCloud.js +0 -4
  138. package/src/og/shaders/polyline.js +0 -4
  139. package/src/og/shaders/ray.js +0 -4
  140. package/src/og/shaders/skybox.js +0 -4
  141. package/src/og/terrain/EmptyTerrain.js +0 -4
  142. package/src/og/utils/FontAtlas.js +0 -4
  143. package/src/og/utils/GeoImageCreator.js +2 -3
  144. package/src/og/utils/NormalMapCreator.js +11 -12
  145. package/src/og/utils/PlainSegmentWorker.js +9 -9
  146. package/src/og/utils/TerrainWorker.js +2 -2
  147. package/src/og/utils/TextureAtlas.js +1 -1
  148. package/src/og/utils/VectorTileCreator.js +3 -9
  149. package/src/og/utils/earcut.js +8 -8
  150. package/src/og/utils/shared.js +30 -11
  151. package/src/og/webgl/Framebuffer.js +2 -6
  152. package/src/og/webgl/Handler.js +46 -20
  153. package/src/og/webgl/Multisample.js +2 -6
  154. package/src/og/webgl/Program.js +4 -8
  155. package/src/og/webgl/ProgramController.js +2 -2
  156. package/types/Clock.d.ts +1 -1
  157. package/types/Extent.d.ts +5 -5
  158. package/types/Globe.d.ts +15 -1
  159. package/types/ImageCanvas.d.ts +5 -0
  160. package/types/bv/Box.d.ts +1 -1
  161. package/types/bv/Sphere.d.ts +3 -3
  162. package/types/camera/Camera.d.ts +3 -2
  163. package/types/camera/PlanetCamera.d.ts +4 -4
  164. package/types/control/DrawingSwitcher.d.ts +13 -0
  165. package/types/control/EarthCoordinates.d.ts +1 -1
  166. package/types/control/Lighting.d.ts +8 -8
  167. package/types/control/drawing/DrawingControl.d.ts +14 -0
  168. package/types/control/drawing/LineStringDrawingScene.d.ts +5 -0
  169. package/types/control/drawing/PolygonDrawingScene.d.ts +99 -0
  170. package/types/control/index.d.ts +3 -1
  171. package/types/control/ruler/RulerScene.d.ts +0 -1
  172. package/types/control/selection/SelectionScene.d.ts +0 -1
  173. package/types/ellipsoid/Ellipsoid.d.ts +53 -64
  174. package/types/entity/Entity.d.ts +3 -2
  175. package/types/entity/GeoObject.d.ts +1 -2
  176. package/types/entity/Geometry.d.ts +5 -0
  177. package/types/entity/Polyline.d.ts +1 -1
  178. package/types/entity/Ray.d.ts +1 -0
  179. package/types/index.d.ts +1 -0
  180. package/types/layer/BaseGeoImage.d.ts +1 -1
  181. package/types/layer/CanvasTiles.d.ts +1 -1
  182. package/types/layer/Layer.d.ts +1 -1
  183. package/types/layer/Vector.d.ts +1 -0
  184. package/types/math/Vec3.d.ts +2 -0
  185. package/types/math.d.ts +7 -0
  186. package/types/renderer/Renderer.d.ts +7 -1
  187. package/types/scene/Axes.d.ts +0 -1
  188. package/types/scene/Planet.d.ts +27 -26
  189. package/types/scene/RenderNode.d.ts +2 -0
  190. package/types/scene/SkyBox.d.ts +0 -1
  191. package/types/segment/Segment.d.ts +3 -2
  192. package/types/segment/SegmentLonLat.d.ts +0 -1
  193. package/types/utils/GeoImageCreator.d.ts +1 -1
  194. package/types/utils/NormalMapCreator.d.ts +1 -1
  195. package/types/utils/VectorTileCreator.d.ts +2 -2
  196. package/types/utils/shared.d.ts +2 -0
  197. package/types/webgl/Handler.d.ts +6 -4
@@ -1,156 +1,152 @@
1
- /**
2
- * @module og/math/Mat3
3
- */
4
-
5
- "use strict";
6
-
7
- import { Mat4 } from "./Mat4.js";
8
- import { Vec3 } from "./Vec3.js";
9
-
10
- /**
11
- * Class represents a 3x3 matrix.
12
- * @class
13
- */
14
- export class Mat3 {
15
- constructor() {
16
- /**
17
- * A 3x3 matrix, indexable as a column-major order array.
18
- * @public
19
- * @type {Array.<number>}
20
- */
21
- this._m = new Array(9);
22
- }
23
-
24
- /**
25
- * Sets column-major order array matrix.
26
- * @public
27
- * @param {Array.<number>} m - Matrix array.
28
- * @returns {Mat3}
29
- */
30
- set(m) {
31
- this._m[0] = m[0];
32
- this._m[1] = m[1];
33
- this._m[2] = m[2];
34
- this._m[3] = m[3];
35
- this._m[4] = m[4];
36
- this._m[5] = m[5];
37
- this._m[6] = m[6];
38
- this._m[7] = m[7];
39
- this._m[8] = m[8];
40
- return this;
41
- }
42
-
43
- /**
44
- * Duplicates a Mat3 instance.
45
- * @public
46
- * @returns {Mat3}
47
- */
48
- clone() {
49
- var res = new Mat3();
50
- res.set(this);
51
- return res;
52
- }
53
-
54
- /**
55
- * Copy matrix.
56
- * @public
57
- * @param {Mat3} a - Matrix to copy.
58
- * @returns {Mat3}
59
- */
60
- copy(a) {
61
- return this.set(a._m);
62
- }
63
-
64
- /**
65
- * Creates trasposed matrix from the current.
66
- * @public
67
- * @returns {Mat3}
68
- */
69
- transposeTo() {
70
- var res = new Mat3();
71
- var m = this._m;
72
- res._m[0] = m[0];
73
- res._m[1] = m[3];
74
- res._m[2] = m[6];
75
- res._m[3] = m[1];
76
- res._m[4] = m[4];
77
- res._m[5] = m[7];
78
- res._m[6] = m[2];
79
- res._m[7] = m[5];
80
- res._m[8] = m[8];
81
- return res;
82
- }
83
-
84
- /**
85
- * Sets matrix to identity.
86
- * @public
87
- * @returns {Mat3}
88
- */
89
- setIdentity() {
90
- this._m[0] = 1;
91
- this._m[1] = 0;
92
- this._m[2] = 0;
93
- this._m[3] = 0;
94
- this._m[4] = 1;
95
- this._m[5] = 0;
96
- this._m[6] = 0;
97
- this._m[7] = 0;
98
- this._m[8] = 1;
99
- return this;
100
- }
101
-
102
- /**
103
- * Multiply to 3d vector.
104
- * @public
105
- * @params {Vec3} p - 3d vector.
106
- * @returns {Vec3}
107
- */
108
- mulVec(p) {
109
- var d = p.x,
110
- e = p.y,
111
- g = p.z;
112
- var m = this._m;
113
- return new Vec3(
114
- m[0] * d + m[3] * e + m[6] * g,
115
- m[1] * d + m[4] * e + m[7] * g,
116
- m[2] * d + m[5] * e + m[8] * g
117
- );
118
- }
119
-
120
- /**
121
- * Converts to 4x4 matrix.
122
- * @public
123
- * @returns {Mat4}
124
- */
125
- toMatrix4() {
126
- var res = new Mat4();
127
- var b = res._m;
128
- var a = this._m;
129
- b[0] = a[0];
130
- b[1] = a[1];
131
- b[2] = a[2];
132
- b[3] = 0;
133
- b[4] = a[3];
134
- b[5] = a[4];
135
- b[6] = a[5];
136
- b[7] = 0;
137
- b[8] = a[6];
138
- b[9] = a[7];
139
- b[10] = a[8];
140
- b[11] = 0;
141
- b[12] = 0;
142
- b[13] = 0;
143
- b[14] = 0;
144
- b[15] = 1;
145
- return res;
146
- }
147
- }
148
-
149
- /**
150
- * Mat3 factory.
151
- * @static
152
- * @return {Mat3}
153
- */
154
- export function mat3() {
155
- return new Mat3();
156
- }
1
+ "use strict";
2
+
3
+ import { Mat4 } from "./Mat4.js";
4
+ import { Vec3 } from "./Vec3.js";
5
+
6
+ /**
7
+ * Class represents a 3x3 matrix.
8
+ * @class
9
+ */
10
+ export class Mat3 {
11
+ constructor() {
12
+ /**
13
+ * A 3x3 matrix, indexable as a column-major order array.
14
+ * @public
15
+ * @type {Array.<number>}
16
+ */
17
+ this._m = new Array(9);
18
+ }
19
+
20
+ /**
21
+ * Sets column-major order array matrix.
22
+ * @public
23
+ * @param {Array.<number>} m - Matrix array.
24
+ * @returns {Mat3}
25
+ */
26
+ set(m) {
27
+ this._m[0] = m[0];
28
+ this._m[1] = m[1];
29
+ this._m[2] = m[2];
30
+ this._m[3] = m[3];
31
+ this._m[4] = m[4];
32
+ this._m[5] = m[5];
33
+ this._m[6] = m[6];
34
+ this._m[7] = m[7];
35
+ this._m[8] = m[8];
36
+ return this;
37
+ }
38
+
39
+ /**
40
+ * Duplicates a Mat3 instance.
41
+ * @public
42
+ * @returns {Mat3}
43
+ */
44
+ clone() {
45
+ var res = new Mat3();
46
+ res.set(this);
47
+ return res;
48
+ }
49
+
50
+ /**
51
+ * Copy matrix.
52
+ * @public
53
+ * @param {Mat3} a - Matrix to copy.
54
+ * @returns {Mat3}
55
+ */
56
+ copy(a) {
57
+ return this.set(a._m);
58
+ }
59
+
60
+ /**
61
+ * Creates trasposed matrix from the current.
62
+ * @public
63
+ * @returns {Mat3}
64
+ */
65
+ transposeTo() {
66
+ var res = new Mat3();
67
+ var m = this._m;
68
+ res._m[0] = m[0];
69
+ res._m[1] = m[3];
70
+ res._m[2] = m[6];
71
+ res._m[3] = m[1];
72
+ res._m[4] = m[4];
73
+ res._m[5] = m[7];
74
+ res._m[6] = m[2];
75
+ res._m[7] = m[5];
76
+ res._m[8] = m[8];
77
+ return res;
78
+ }
79
+
80
+ /**
81
+ * Sets matrix to identity.
82
+ * @public
83
+ * @returns {Mat3}
84
+ */
85
+ setIdentity() {
86
+ this._m[0] = 1;
87
+ this._m[1] = 0;
88
+ this._m[2] = 0;
89
+ this._m[3] = 0;
90
+ this._m[4] = 1;
91
+ this._m[5] = 0;
92
+ this._m[6] = 0;
93
+ this._m[7] = 0;
94
+ this._m[8] = 1;
95
+ return this;
96
+ }
97
+
98
+ /**
99
+ * Multiply to 3d vector.
100
+ * @public
101
+ * @params {Vec3} p - 3d vector.
102
+ * @returns {Vec3}
103
+ */
104
+ mulVec(p) {
105
+ var d = p.x,
106
+ e = p.y,
107
+ g = p.z;
108
+ var m = this._m;
109
+ return new Vec3(
110
+ m[0] * d + m[3] * e + m[6] * g,
111
+ m[1] * d + m[4] * e + m[7] * g,
112
+ m[2] * d + m[5] * e + m[8] * g
113
+ );
114
+ }
115
+
116
+ /**
117
+ * Converts to 4x4 matrix.
118
+ * @public
119
+ * @returns {Mat4}
120
+ */
121
+ toMatrix4() {
122
+ var res = new Mat4();
123
+ var b = res._m;
124
+ var a = this._m;
125
+ b[0] = a[0];
126
+ b[1] = a[1];
127
+ b[2] = a[2];
128
+ b[3] = 0;
129
+ b[4] = a[3];
130
+ b[5] = a[4];
131
+ b[6] = a[5];
132
+ b[7] = 0;
133
+ b[8] = a[6];
134
+ b[9] = a[7];
135
+ b[10] = a[8];
136
+ b[11] = 0;
137
+ b[12] = 0;
138
+ b[13] = 0;
139
+ b[14] = 0;
140
+ b[15] = 1;
141
+ return res;
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Mat3 factory.
147
+ * @static
148
+ * @return {Mat3}
149
+ */
150
+ export function mat3() {
151
+ return new Mat3();
152
+ }
@@ -1,7 +1,3 @@
1
- /**
2
- * @module og/math/Ray
3
- */
4
-
5
1
  "use strict";
6
2
 
7
3
  import { EPS10 } from "../math.js";
@@ -1,7 +1,3 @@
1
- /**
2
- * @module og/math/Vec2
3
- */
4
-
5
1
  "use strict";
6
2
 
7
3
  import { Vec3 } from "./Vec3.js";
@@ -1,7 +1,3 @@
1
- /**
2
- * @module og/math/Vec3
3
- */
4
-
5
1
  "use strict";
6
2
 
7
3
  import { Quat } from "./Quat.js";
@@ -85,6 +81,11 @@ export class Vec3 {
85
81
  return new Vec3(0, 0, 1);
86
82
  }
87
83
 
84
+ /** @const */
85
+ static get NORTH() {
86
+ return Vec3.UNIT_Z;
87
+ }
88
+
88
89
  /**
89
90
  * Separate 63 bit Vec3 to two Vec3 32 bit float values.
90
91
  * @function
@@ -1,7 +1,3 @@
1
- /**
2
- * @module og/math/Vec4
3
- */
4
-
5
1
  "use strict";
6
2
 
7
3
  import { frac } from "../math.js";
@@ -1,104 +1,104 @@
1
- /**
2
- * @module og/math/coder
3
- */
4
-
5
- "use strict";
6
-
7
- import * as math from "../math.js";
8
- import { Vec4 } from "./Vec4.js";
9
-
10
- /**
11
- * Encode 32 bit float value to the RGBA vector.
12
- * @function
13
- * @param {number} v - 32 bit float value.
14
- * @returns {math.Vec4} - RGBA vector value.
15
- */
16
- export function encodeFloatToRGBA(v) {
17
- var enc = new Vec4((1.0 * v) % 1, (255.0 * v) % 1, (65025.0 * v) % 1, (160581375.0 * v) % 1);
18
- var yzww = new Vec4(enc.y / 255, enc.z / 255, enc.w / 255, 0);
19
- return enc.subA(yzww);
20
- }
21
-
22
- /**
23
- * Decode RGBA vector to 32 bit float value.
24
- * @function
25
- * @param {Vec4} rgba - RGBA encoded 32 bit float value.
26
- * @returns {number} - Float value.
27
- */
28
- export function decodeFloatFromRGBA(rgba) {
29
- var s = 1.0 - math.step(128.0, rgba.x) * 2.0;
30
- var e = 2.0 * math.mod(rgba.x, 128.0) + math.step(128.0, rgba.y) - 127.0;
31
- var m = math.mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;
32
- return s * math.exp2(e) * (m * 1.1920928955078125e-7);
33
- }
34
-
35
- /**
36
- * Decode RGBA vector to 32 bit float value.
37
- * @function
38
- * @param {Vec4} rgba - RGBA encoded 32 bit float value.
39
- * @returns {number} - Float value.
40
- */
41
- export function decodeFloatFromRGBAArr(arr, use32) {
42
- var s = 1.0 - math.step(128.0, arr[0]) * 2.0;
43
- var e = 2.0 * math.mod(arr[0], 128.0) + math.step(128.0, arr[1]) - 127.0;
44
- var m = math.mod(arr[1], 128.0) * 65536.0 + arr[2] * 256.0 + (use32 ? arr[3] : 0.0) + 8388608.0;
45
- return s * math.exp2(e) * (m * 1.1920928955078125e-7);
46
- }
47
-
48
- /**
49
- * Separate 64 bit value to two 32 bit float values.
50
- * @function
51
- * @param {number} value - Double type value.
52
- * @returns {Array.<number>} Encoded array. (exactly 2 entries)
53
- */
54
- export function doubleToTwoFloats(value) {
55
- var high, low;
56
- if (value >= 0.0) {
57
- let doubleHigh = Math.floor(value / 65536.0) * 65536.0;
58
- high = Math.fround(doubleHigh);
59
- low = Math.fround(value - doubleHigh);
60
- } else {
61
- let doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
62
- high = Math.fround(-doubleHigh);
63
- low = Math.fround(value + doubleHigh);
64
- }
65
- return new Float32Array([high, low]);
66
- }
67
-
68
- /**
69
- * Separate 64 bit value to two 32 bit float values.
70
- * @function
71
- * @param {number} value - Double type value.
72
- * @returns {Array.<number>} Encoded array. (exactly 2 entries)
73
- */
74
- export function doubleToTwoFloats2(value, highLowArr) {
75
- if (value >= 0.0) {
76
- let doubleHigh = Math.floor(value / 65536.0) * 65536.0;
77
- highLowArr[0] = Math.fround(doubleHigh);
78
- highLowArr[1] = Math.fround(value - doubleHigh);
79
- } else {
80
- let doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
81
- highLowArr[0] = Math.fround(-doubleHigh);
82
- highLowArr[1] = Math.fround(value + doubleHigh);
83
- }
84
- return highLowArr;
85
- }
86
-
87
- /**
88
- * Separate 64 bit value to two 32 bit float values.
89
- * @function
90
- * @param {number} value - Double type value.
91
- * @returns {Array.<number>} Encoded array. (exactly 2 entries)
92
- */
93
- export function doubleToTwoFloatsV2(value, highLowVec) {
94
- if (value >= 0.0) {
95
- let doubleHigh = Math.floor(value / 65536.0) * 65536.0;
96
- highLowVec.x = Math.fround(doubleHigh);
97
- highLowVec.y = Math.fround(value - doubleHigh);
98
- } else {
99
- let doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
100
- highLowVec.x = Math.fround(-doubleHigh);
101
- highLowVec.y = Math.fround(value + doubleHigh);
102
- }
103
- return highLowVec;
104
- }
1
+ /**
2
+ * @module og/math/coder
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import * as math from "../math.js";
8
+ import { Vec4 } from "./Vec4.js";
9
+
10
+ /**
11
+ * Encode 32 bit float value to the RGBA vector.
12
+ * @function
13
+ * @param {number} v - 32 bit float value.
14
+ * @returns {math.Vec4} - RGBA vector value.
15
+ */
16
+ export function encodeFloatToRGBA(v) {
17
+ var enc = new Vec4((1.0 * v) % 1, (255.0 * v) % 1, (65025.0 * v) % 1, (160581375.0 * v) % 1);
18
+ var yzww = new Vec4(enc.y / 255, enc.z / 255, enc.w / 255, 0);
19
+ return enc.subA(yzww);
20
+ }
21
+
22
+ /**
23
+ * Decode RGBA vector to 32 bit float value.
24
+ * @function
25
+ * @param {Vec4} rgba - RGBA encoded 32 bit float value.
26
+ * @returns {number} - Float value.
27
+ */
28
+ export function decodeFloatFromRGBA(rgba) {
29
+ var s = 1.0 - math.step(128.0, rgba.x) * 2.0;
30
+ var e = 2.0 * math.mod(rgba.x, 128.0) + math.step(128.0, rgba.y) - 127.0;
31
+ var m = math.mod(rgba.y, 128.0) * 65536.0 + rgba.z * 256.0 + rgba.w + 8388608.0;
32
+ return s * math.exp2(e) * (m * 1.1920928955078125e-7);
33
+ }
34
+
35
+ /**
36
+ * Decode RGBA vector to 32 bit float value.
37
+ * @function
38
+ * @param {Vec4} rgba - RGBA encoded 32 bit float value.
39
+ * @returns {number} - Float value.
40
+ */
41
+ export function decodeFloatFromRGBAArr(arr, use32) {
42
+ var s = 1.0 - math.step(128.0, arr[0]) * 2.0;
43
+ var e = 2.0 * math.mod(arr[0], 128.0) + math.step(128.0, arr[1]) - 127.0;
44
+ var m = math.mod(arr[1], 128.0) * 65536.0 + arr[2] * 256.0 + (use32 ? arr[3] : 0.0) + 8388608.0;
45
+ return s * math.exp2(e) * (m * 1.1920928955078125e-7);
46
+ }
47
+
48
+ /**
49
+ * Separate 64 bit value to two 32 bit float values.
50
+ * @function
51
+ * @param {number} value - Double type value.
52
+ * @returns {Array.<number>} Encoded array. (exactly 2 entries)
53
+ */
54
+ export function doubleToTwoFloats(value) {
55
+ var high, low;
56
+ if (value >= 0.0) {
57
+ let doubleHigh = Math.floor(value / 65536.0) * 65536.0;
58
+ high = Math.fround(doubleHigh);
59
+ low = Math.fround(value - doubleHigh);
60
+ } else {
61
+ let doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
62
+ high = Math.fround(-doubleHigh);
63
+ low = Math.fround(value + doubleHigh);
64
+ }
65
+ return new Float32Array([high, low]);
66
+ }
67
+
68
+ /**
69
+ * Separate 64 bit value to two 32 bit float values.
70
+ * @function
71
+ * @param {number} value - Double type value.
72
+ * @returns {Array.<number>} Encoded array. (exactly 2 entries)
73
+ */
74
+ export function doubleToTwoFloats2(value, highLowArr) {
75
+ if (value >= 0.0) {
76
+ let doubleHigh = Math.floor(value / 65536.0) * 65536.0;
77
+ highLowArr[0] = Math.fround(doubleHigh);
78
+ highLowArr[1] = Math.fround(value - doubleHigh);
79
+ } else {
80
+ let doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
81
+ highLowArr[0] = Math.fround(-doubleHigh);
82
+ highLowArr[1] = Math.fround(value + doubleHigh);
83
+ }
84
+ return highLowArr;
85
+ }
86
+
87
+ /**
88
+ * Separate 64 bit value to two 32 bit float values.
89
+ * @function
90
+ * @param {number} value - Double type value.
91
+ * @returns {Array.<number>} Encoded array. (exactly 2 entries)
92
+ */
93
+ export function doubleToTwoFloatsV2(value, highLowVec) {
94
+ if (value >= 0.0) {
95
+ let doubleHigh = Math.floor(value / 65536.0) * 65536.0;
96
+ highLowVec.x = Math.fround(doubleHigh);
97
+ highLowVec.y = Math.fround(value - doubleHigh);
98
+ } else {
99
+ let doubleHigh = Math.floor(-value / 65536.0) * 65536.0;
100
+ highLowVec.x = Math.fround(-doubleHigh);
101
+ highLowVec.y = Math.fround(value + doubleHigh);
102
+ }
103
+ return highLowVec;
104
+ }
package/src/og/math.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @module og/math
3
3
  */
4
+
4
5
  "use strict";
5
6
 
6
7
  /** @const */
@@ -49,12 +50,12 @@ export const DEGREES_TO_HOURS = 1.0 / 15.0;
49
50
  /** @const */
50
51
  export const SQRT_HALF = Math.sqrt(0.5);
51
52
 
52
- export const EPS1 = 0.1;
53
- export const EPS2 = 0.01;
54
- export const EPS3 = 0.001;
55
- export const EPS4 = 0.0001;
56
- export const EPS5 = 0.00001;
57
- export const EPS6 = 0.000001;
53
+ export const EPS1 = 1e-1;
54
+ export const EPS2 = 1e-2;
55
+ export const EPS3 = 1e-3;
56
+ export const EPS4 = 1e-4;
57
+ export const EPS5 = 1e-5;
58
+ export const EPS6 = 1e-6;
58
59
  export const EPS7 = 1e-7;
59
60
  export const EPS8 = 1e-8;
60
61
  export const EPS9 = 1e-9;
@@ -137,7 +138,7 @@ export function isPowerOfTwo(x) {
137
138
  */
138
139
  export function nextHighestPowerOfTwo(x, maxValue = 4096) {
139
140
  --x;
140
- for (var i = 1; i < 32; i <<= 1) {
141
+ for (let i = 1; i < 32; i <<= 1) {
141
142
  x = x | (x >> i);
142
143
  }
143
144
  return (x + 1) > maxValue ? maxValue : x + 1
@@ -226,7 +227,7 @@ export function step(edge, x) {
226
227
  */
227
228
  export function frac(x) {
228
229
  const mx = Math.abs(x)
229
- return mx - Math.floor(mx);
230
+ return mx - Math.floor(mx);
230
231
  }
231
232
 
232
233
  /**
@@ -361,7 +362,7 @@ export function negativePItoPI(a) {
361
362
  export function solve_iteration_fixed(f, x0, maxIter) {
362
363
  var x = 0;
363
364
  var x2 = x0;
364
- for (var i = 0; i < maxIter; i++) {
365
+ for (let i = 0; i < maxIter; i++) {
365
366
  x = x2;
366
367
  x2 = f(x);
367
368
  }
@@ -381,7 +382,7 @@ export function solve_iteration_fixed(f, x0, maxIter) {
381
382
  export function solve_iteration(f, x0, err, maxIter = 50) {
382
383
  var x = 0;
383
384
  var x2 = x0;
384
- for (var i = 0; i < maxIter; i++) {
385
+ for (let i = 0; i < maxIter; i++) {
385
386
  x = x2;
386
387
  x2 = f(x);
387
388
  if (Math.abs(x2 - x) < err) {
@@ -396,3 +397,34 @@ export function solve_iteration(f, x0, err, maxIter = 50) {
396
397
  * @callback equationCallback
397
398
  * @param {number} x - Equation variable.
398
399
  */
400
+
401
+ /**
402
+ *
403
+ * @param a - First bearing angle
404
+ * @param b - Second bearing angle
405
+ * @returns {number}
406
+ */
407
+ function getAngleDirection(a, b) {
408
+ let a_y = Math.cos(a),
409
+ a_x = Math.sin(a),
410
+ b_y = Math.cos(b),
411
+ b_x = Math.sin(b);
412
+ let c = a_y * b_x - b_y * a_x,
413
+ d = a_x * b_x + a_y * b_y;
414
+ if (c > 0.0) {
415
+ return Math.acos(d);
416
+ }
417
+ return -Math.acos(d);
418
+ }
419
+
420
+ /**
421
+ * Returns angle between two azimuths
422
+ * @param {number} a - First azimuth angle
423
+ * @param {number} b - Second azimuth angle
424
+ * @returns {number}
425
+ */
426
+ export function getAngleBetweenAzimuths(a, b) {
427
+ a = zeroTwoPI(a);
428
+ b = zeroTwoPI(b);
429
+ return ((((a - b) % 360) + 360 + 180) % 360) - 180;
430
+ }
@@ -122,7 +122,7 @@ export function getTileY(lat, zoom) {
122
122
  */
123
123
  export function forwardArray(lonlatArr) {
124
124
  var res = [];
125
- for (var i = 0; i < lonlatArr.length; i++) {
125
+ for (let i = 0; i < lonlatArr.length; i++) {
126
126
  res.push(lonlatArr[i].forwardMercator());
127
127
  }
128
128
  return res;