@openglobus/og 0.16.2 → 0.17.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.
Files changed (181) 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 +0 -4
  11. package/src/og/Extent.js +5 -9
  12. package/src/og/Globe.js +92 -55
  13. package/src/og/ImageCanvas.js +12 -5
  14. package/src/og/Lock.js +44 -48
  15. package/src/og/LonLat.js +0 -4
  16. package/src/og/Object3d.js +1 -1
  17. package/src/og/Stack.js +49 -53
  18. package/src/og/astro/earth.js +112 -116
  19. package/src/og/astro/jd.js +514 -518
  20. package/src/og/astro/orbit.js +119 -123
  21. package/src/og/astro/rotation.js +36 -40
  22. package/src/og/bv/Box.js +77 -81
  23. package/src/og/bv/Sphere.js +57 -61
  24. package/src/og/camera/Camera.js +20 -7
  25. package/src/og/camera/PlanetCamera.js +8 -15
  26. package/src/og/control/Atmosphere.js +0 -4
  27. package/src/og/control/Control.js +9 -8
  28. package/src/og/control/DebugInfo.js +0 -4
  29. package/src/og/control/DrawingSwitcher.js +117 -0
  30. package/src/og/control/EarthCoordinates.js +214 -214
  31. package/src/og/control/GeoImageDragControl.js +0 -4
  32. package/src/og/control/KeyboardNavigation.js +0 -4
  33. package/src/og/control/LayerAnimation.js +0 -4
  34. package/src/og/control/LayerSwitcher.js +2 -4
  35. package/src/og/control/Lighting.js +11 -15
  36. package/src/og/control/MouseNavigation.js +0 -4
  37. package/src/og/control/MouseWheelZoomControl.js +0 -4
  38. package/src/og/control/RulerSwitcher.js +0 -4
  39. package/src/og/control/ScaleControl.js +2 -6
  40. package/src/og/control/ShowFps.js +40 -44
  41. package/src/og/control/SimpleNavigation.js +10 -10
  42. package/src/og/control/SimpleSkyBackground.js +0 -4
  43. package/src/og/control/Sun.js +0 -4
  44. package/src/og/control/ToggleWireframe.js +35 -39
  45. package/src/og/control/ZoomControl.js +0 -4
  46. package/src/og/control/drawing/DrawingControl.js +51 -0
  47. package/src/og/control/drawing/LineStringDrawingScene.js +203 -0
  48. package/src/og/control/drawing/PolygonDrawingScene.js +785 -0
  49. package/src/og/control/elevationProfile/ElevationProfile.js +275 -0
  50. package/src/og/control/index.js +5 -1
  51. package/src/og/control/ruler/Ruler.js +0 -4
  52. package/src/og/control/ruler/RulerScene.js +3 -2
  53. package/src/og/control/selection/Selection.js +0 -4
  54. package/src/og/control/selection/SelectionScene.js +2 -4
  55. package/src/og/control/timeline/TimelineControl.js +4 -4
  56. package/src/og/control/timeline/TimelineModel.js +2 -2
  57. package/src/og/control/timeline/TimelineView.js +1 -0
  58. package/src/og/control/visibleExtent/Segment.js +5 -5
  59. package/src/og/control/visibleExtent/drawnode.js +0 -4
  60. package/src/og/ellipsoid/Ellipsoid.js +205 -275
  61. package/src/og/ellipsoid/wgs84.js +0 -4
  62. package/src/og/entity/BaseBillboard.js +375 -379
  63. package/src/og/entity/Billboard.js +0 -4
  64. package/src/og/entity/BillboardHandler.js +0 -4
  65. package/src/og/entity/Entity.js +22 -22
  66. package/src/og/entity/EntityCollection.js +7 -11
  67. package/src/og/entity/GeoObject.js +0 -4
  68. package/src/og/entity/GeoObjectHandler.js +0 -4
  69. package/src/og/entity/Geometry.js +5 -4
  70. package/src/og/entity/GeometryHandler.js +3 -4
  71. package/src/og/entity/Label.js +0 -4
  72. package/src/og/entity/LabelHandler.js +0 -4
  73. package/src/og/entity/PointCloud.js +0 -4
  74. package/src/og/entity/PointCloudHandler.js +122 -126
  75. package/src/og/entity/Polyline.js +4 -6
  76. package/src/og/entity/PolylineHandler.js +104 -108
  77. package/src/og/entity/Ray.js +29 -29
  78. package/src/og/entity/Strip.js +1 -1
  79. package/src/og/index.js +3 -1
  80. package/src/og/input/KeyboardHandler.js +128 -132
  81. package/src/og/input/MouseHandler.js +94 -98
  82. package/src/og/input/TouchHandler.js +59 -63
  83. package/src/og/input/input.js +44 -48
  84. package/src/og/layer/BaseGeoImage.js +5 -8
  85. package/src/og/layer/CanvasTiles.js +0 -4
  86. package/src/og/layer/GeoImage.js +0 -4
  87. package/src/og/layer/GeoTexture2d.js +0 -4
  88. package/src/og/layer/GeoVideo.js +0 -4
  89. package/src/og/layer/KML.js +2 -3
  90. package/src/og/layer/Layer.js +22 -26
  91. package/src/og/layer/Material.js +0 -4
  92. package/src/og/layer/Vector.js +23 -20
  93. package/src/og/layer/WMS.js +182 -186
  94. package/src/og/layer/XYZ.js +0 -4
  95. package/src/og/light/LightSource.js +0 -4
  96. package/src/og/math/Line2.js +28 -32
  97. package/src/og/math/Mat3.js +152 -156
  98. package/src/og/math/Ray.js +0 -4
  99. package/src/og/math/Vec2.js +0 -4
  100. package/src/og/math/Vec3.js +0 -4
  101. package/src/og/math/Vec4.js +0 -4
  102. package/src/og/math/coder.js +104 -104
  103. package/src/og/math.js +39 -7
  104. package/src/og/proj/EPSG3857.js +13 -13
  105. package/src/og/proj/Proj.js +59 -63
  106. package/src/og/quadTree/EPSG4326QuadTreeStrategy.js +1 -0
  107. package/src/og/quadTree/EarthQuadTreeStrategy.js +1 -0
  108. package/src/og/quadTree/EntityCollectionNode.js +12 -16
  109. package/src/og/quadTree/MarsQuadTreeStrategy.js +1 -0
  110. package/src/og/quadTree/QuadTreeStrategy.js +1 -0
  111. package/src/og/quadTree/Wgs84QuadTreeStrategy.js +1 -0
  112. package/src/og/renderer/Renderer.js +109 -22
  113. package/src/og/renderer/RendererEvents.js +0 -4
  114. package/src/og/scene/Axes.js +74 -78
  115. package/src/og/scene/BaseNode.js +0 -4
  116. package/src/og/scene/Planet.js +114 -112
  117. package/src/og/scene/RenderNode.js +11 -3
  118. package/src/og/scene/SkyBox.js +104 -108
  119. package/src/og/segment/Segment.js +8 -4
  120. package/src/og/segment/SegmentLonLat.js +2 -6
  121. package/src/og/segment/segmentHelper.js +229 -225
  122. package/src/og/shaders/billboard.js +0 -4
  123. package/src/og/shaders/drawnode.js +5 -9
  124. package/src/og/shaders/geoObject.js +0 -4
  125. package/src/og/shaders/label.js +0 -4
  126. package/src/og/shaders/pickingMask.js +0 -4
  127. package/src/og/shaders/pointCloud.js +0 -4
  128. package/src/og/shaders/polyline.js +0 -4
  129. package/src/og/shaders/ray.js +0 -4
  130. package/src/og/shaders/skybox.js +0 -4
  131. package/src/og/terrain/EmptyTerrain.js +0 -4
  132. package/src/og/utils/FontAtlas.js +0 -4
  133. package/src/og/utils/GeoImageCreator.js +1 -2
  134. package/src/og/utils/NormalMapCreator.js +8 -9
  135. package/src/og/utils/VectorTileCreator.js +3 -9
  136. package/src/og/utils/shared.js +20 -1
  137. package/src/og/webgl/Framebuffer.js +0 -4
  138. package/src/og/webgl/Handler.js +45 -19
  139. package/src/og/webgl/Multisample.js +0 -4
  140. package/src/og/webgl/Program.js +0 -4
  141. package/src/og/webgl/ProgramController.js +2 -2
  142. package/types/Clock.d.ts +1 -1
  143. package/types/Extent.d.ts +5 -5
  144. package/types/Globe.d.ts +15 -1
  145. package/types/ImageCanvas.d.ts +5 -0
  146. package/types/bv/Box.d.ts +1 -1
  147. package/types/bv/Sphere.d.ts +3 -3
  148. package/types/camera/Camera.d.ts +3 -2
  149. package/types/camera/PlanetCamera.d.ts +4 -4
  150. package/types/control/DrawingSwitcher.d.ts +13 -0
  151. package/types/control/EarthCoordinates.d.ts +1 -1
  152. package/types/control/Lighting.d.ts +8 -8
  153. package/types/control/drawing/DrawingControl.d.ts +14 -0
  154. package/types/control/drawing/LineStringDrawingScene.d.ts +5 -0
  155. package/types/control/drawing/PolygonDrawingScene.d.ts +99 -0
  156. package/types/control/index.d.ts +3 -1
  157. package/types/control/ruler/RulerScene.d.ts +0 -1
  158. package/types/control/selection/SelectionScene.d.ts +0 -1
  159. package/types/ellipsoid/Ellipsoid.d.ts +50 -63
  160. package/types/entity/Entity.d.ts +3 -2
  161. package/types/entity/Geometry.d.ts +5 -0
  162. package/types/entity/Polyline.d.ts +1 -1
  163. package/types/entity/Ray.d.ts +1 -0
  164. package/types/index.d.ts +1 -0
  165. package/types/layer/BaseGeoImage.d.ts +1 -1
  166. package/types/layer/CanvasTiles.d.ts +1 -1
  167. package/types/layer/Layer.d.ts +1 -1
  168. package/types/layer/Vector.d.ts +1 -0
  169. package/types/math.d.ts +7 -0
  170. package/types/renderer/Renderer.d.ts +7 -1
  171. package/types/scene/Axes.d.ts +0 -1
  172. package/types/scene/Planet.d.ts +26 -24
  173. package/types/scene/RenderNode.d.ts +2 -0
  174. package/types/scene/SkyBox.d.ts +0 -1
  175. package/types/segment/Segment.d.ts +3 -2
  176. package/types/segment/SegmentLonLat.d.ts +0 -1
  177. package/types/utils/GeoImageCreator.d.ts +1 -1
  178. package/types/utils/NormalMapCreator.d.ts +1 -1
  179. package/types/utils/VectorTileCreator.d.ts +2 -2
  180. package/types/utils/shared.d.ts +2 -0
  181. 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";
@@ -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;
@@ -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
  /**
@@ -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
+ }
@@ -1,13 +1,13 @@
1
- /**
2
- * @module og/proj/EPSG3857
3
- */
4
-
5
- "use strict";
6
-
7
- import { Proj, Units } from "./Proj.js";
8
-
9
- /**
10
- * EPSG:3857 projection object.
11
- * @type {Proj}
12
- */
13
- export const EPSG3857 = new Proj({ code: "epsg:3857", units: Units.METERS });
1
+ /**
2
+ * @module og/proj/EPSG3857
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import { Proj, Units } from "./Proj.js";
8
+
9
+ /**
10
+ * EPSG:3857 projection object.
11
+ * @type {Proj}
12
+ */
13
+ export const EPSG3857 = new Proj({ code: "epsg:3857", units: Units.METERS });