@openglobus/og 0.10.4 → 0.11.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 (172) hide show
  1. package/css/og.css +1 -1
  2. package/package.json +11 -9
  3. package/src/og/Extent.js +274 -273
  4. package/src/og/Globe.js +11 -3
  5. package/src/og/LonLat.js +152 -146
  6. package/src/og/Popup.js +2 -1
  7. package/src/og/camera/PlanetCamera.js +112 -38
  8. package/src/og/control/EarthNavigation.js +259 -0
  9. package/src/og/control/MouseNavigation.js +68 -40
  10. package/src/og/entity/EntityCollection.js +1 -1
  11. package/src/og/entity/LabelHandler.js +366 -74
  12. package/src/og/entity/Polyline.js +3 -2
  13. package/src/og/layer/CanvasTiles.js +32 -30
  14. package/src/og/layer/KML.js +159 -0
  15. package/src/og/layer/Vector.js +5 -0
  16. package/src/og/layer/index.js +2 -1
  17. package/src/og/math/Vec2.js +448 -448
  18. package/src/og/math/Vec3.js +759 -757
  19. package/src/og/math/Vec4.js +216 -215
  20. package/src/og/quadTree/Node.js +67 -13
  21. package/src/og/renderer/RendererEvents.js +21 -16
  22. package/src/og/scene/Planet.js +25 -10
  23. package/src/og/segment/Segment.js +3 -3
  24. package/src/og/segment/SegmentLonLat.js +7 -0
  25. package/src/og/terrain/GlobusTerrain.js +4 -0
  26. package/src/og/utils/FontAtlas.js +1 -0
  27. package/src/og/utils/GeoImageCreator.js +123 -121
  28. package/src/og/utils/Loader.js +81 -80
  29. package/src/og/utils/NormalMapCreator.js +320 -318
  30. package/src/og/utils/VectorTileCreator.js +251 -250
  31. package/src/og/webgl/Framebuffer.js +265 -264
  32. package/src/og/webgl/Handler.js +1022 -1001
  33. package/src/og/webgl/Multisample.js +169 -168
  34. package/src/og/webgl/ProgramController.js +113 -112
  35. package/types/Clock.d.ts +90 -0
  36. package/types/Deferred.d.ts +6 -0
  37. package/types/Events.d.ts +73 -0
  38. package/types/Extent.d.ts +162 -0
  39. package/types/Globe.d.ts +80 -0
  40. package/types/ImageCanvas.d.ts +121 -0
  41. package/types/Lock.d.ts +12 -0
  42. package/types/LonLat.d.ts +108 -0
  43. package/types/Popup.d.ts +38 -0
  44. package/types/QueueArray.d.ts +15 -0
  45. package/types/Rectangle.d.ts +74 -0
  46. package/types/Stack.d.ts +15 -0
  47. package/types/ajax.d.ts +24 -0
  48. package/types/arial.d.ts +48 -0
  49. package/types/astro/astro.d.ts +38 -0
  50. package/types/astro/earth.d.ts +6 -0
  51. package/types/astro/jd.d.ts +254 -0
  52. package/types/bv/Box.d.ts +25 -0
  53. package/types/bv/Sphere.d.ts +32 -0
  54. package/types/bv/index.d.ts +3 -0
  55. package/types/camera/Camera.d.ts +303 -0
  56. package/types/camera/Frustum.d.ts +129 -0
  57. package/types/camera/PlanetCamera.d.ts +222 -0
  58. package/types/camera/index.d.ts +3 -0
  59. package/types/cons.d.ts +40 -0
  60. package/types/control/CompassButton.d.ts +17 -0
  61. package/types/control/Control.d.ts +101 -0
  62. package/types/control/DebugInfo.d.ts +16 -0
  63. package/types/control/EarthCoordinates.d.ts +47 -0
  64. package/types/control/GeoImageDragControl.d.ts +6 -0
  65. package/types/control/KeyboardNavigation.d.ts +22 -0
  66. package/types/control/LayerSwitcher.d.ts +23 -0
  67. package/types/control/Lighting.d.ts +16 -0
  68. package/types/control/ScaleControl.d.ts +22 -0
  69. package/types/control/ShowFps.d.ts +12 -0
  70. package/types/control/SimpleNavigation.d.ts +28 -0
  71. package/types/control/Sun.d.ts +52 -0
  72. package/types/control/ToggleWireframe.d.ts +12 -0
  73. package/types/control/ZoomControl.d.ts +28 -0
  74. package/types/control/index.d.ts +15 -0
  75. package/types/ellipsoid/Ellipsoid.d.ts +142 -0
  76. package/types/ellipsoid/index.d.ts +3 -0
  77. package/types/ellipsoid/wgs84.d.ts +5 -0
  78. package/types/entity/BaseBillboard.d.ts +208 -0
  79. package/types/entity/Billboard.d.ts +94 -0
  80. package/types/entity/BillboardHandler.d.ts +74 -0
  81. package/types/entity/Entity.d.ts +330 -0
  82. package/types/entity/EntityCollection.d.ts +303 -0
  83. package/types/entity/Geometry.d.ts +72 -0
  84. package/types/entity/GeometryHandler.d.ts +76 -0
  85. package/types/entity/Label.d.ts +194 -0
  86. package/types/entity/LabelHandler.d.ts +24 -0
  87. package/types/entity/PointCloud.d.ts +174 -0
  88. package/types/entity/PointCloudHandler.d.ts +38 -0
  89. package/types/entity/Polyline.d.ts +303 -0
  90. package/types/entity/PolylineHandler.d.ts +18 -0
  91. package/types/entity/Ray.d.ts +123 -0
  92. package/types/entity/RayHandler.d.ts +67 -0
  93. package/types/entity/ShapeHandler.d.ts +22 -0
  94. package/types/entity/Strip.d.ts +118 -0
  95. package/types/entity/StripHandler.d.ts +38 -0
  96. package/types/entity/index.d.ts +8 -0
  97. package/types/index.core.d.ts +65 -0
  98. package/types/index.d.ts +45 -0
  99. package/types/index.webgl.d.ts +7 -0
  100. package/types/inherits.d.ts +4 -0
  101. package/types/input/input.d.ts +34 -0
  102. package/types/layer/BaseGeoImage.d.ts +106 -0
  103. package/types/layer/CanvasTiles.d.ts +75 -0
  104. package/types/layer/GeoImage.d.ts +65 -0
  105. package/types/layer/GeoTexture2d.d.ts +8 -0
  106. package/types/layer/GeoVideo.d.ts +80 -0
  107. package/types/layer/KML.d.ts +58 -0
  108. package/types/layer/WMS.d.ts +66 -0
  109. package/types/layer/XYZ.d.ts +126 -0
  110. package/types/layer/index.d.ts +10 -0
  111. package/types/light/LightSource.d.ts +177 -0
  112. package/types/math/Mat3.d.ts +53 -0
  113. package/types/math/Mat4.d.ts +157 -0
  114. package/types/math/Plane.d.ts +17 -0
  115. package/types/math/Vec2.d.ts +308 -0
  116. package/types/math/Vec3.d.ts +459 -0
  117. package/types/math/Vec4.d.ts +161 -0
  118. package/types/math/coder.d.ts +42 -0
  119. package/types/math/index.d.ts +11 -0
  120. package/types/math.d.ts +261 -0
  121. package/types/mercator.d.ts +92 -0
  122. package/types/proj/EPSG3857.d.ts +5 -0
  123. package/types/proj/EPSG4326.d.ts +5 -0
  124. package/types/quadTree/quadTree.d.ts +40 -0
  125. package/types/renderer/RendererEvents.d.ts +230 -0
  126. package/types/res/images.d.ts +3 -0
  127. package/types/scene/Axes.d.ts +11 -0
  128. package/types/scene/BaseNode.d.ts +60 -0
  129. package/types/scene/Planet.d.ts +572 -0
  130. package/types/scene/RenderNode.d.ts +143 -0
  131. package/types/scene/SkyBox.d.ts +10 -0
  132. package/types/scene/index.d.ts +4 -0
  133. package/types/segment/segmentHelper.d.ts +13 -0
  134. package/types/shaders/billboard.d.ts +3 -0
  135. package/types/shaders/depth.d.ts +2 -0
  136. package/types/shaders/drawnode.d.ts +7 -0
  137. package/types/shaders/label.d.ts +4 -0
  138. package/types/shaders/pointCloud.d.ts +2 -0
  139. package/types/shaders/polyline.d.ts +3 -0
  140. package/types/shaders/ray.d.ts +2 -0
  141. package/types/shaders/screenFrame.d.ts +2 -0
  142. package/types/shaders/shape.d.ts +4 -0
  143. package/types/shaders/skybox.d.ts +2 -0
  144. package/types/shaders/toneMapping.d.ts +2 -0
  145. package/types/shapes/BaseShape.d.ts +247 -0
  146. package/types/shapes/Sphere.d.ts +41 -0
  147. package/types/terrain/BilTerrain.d.ts +8 -0
  148. package/types/terrain/EmptyTerrain.d.ts +72 -0
  149. package/types/terrain/Geoid.d.ts +26 -0
  150. package/types/terrain/GlobusTerrain.d.ts +153 -0
  151. package/types/terrain/MapboxTerrain.d.ts +8 -0
  152. package/types/terrain/index.d.ts +5 -0
  153. package/types/utils/FontAtlas.d.ts +14 -0
  154. package/types/utils/GeoImageCreator.d.ts +29 -0
  155. package/types/utils/ImagesCacheManager.d.ts +10 -0
  156. package/types/utils/Loader.d.ts +25 -0
  157. package/types/utils/NormalMapCreator.d.ts +39 -0
  158. package/types/utils/PlainSegmentWorker.d.ts +10 -0
  159. package/types/utils/TerrainWorker.d.ts +9 -0
  160. package/types/utils/TextureAtlas.d.ts +111 -0
  161. package/types/utils/VectorTileCreator.d.ts +16 -0
  162. package/types/utils/colorTable.d.ts +143 -0
  163. package/types/utils/earcut.d.ts +6 -0
  164. package/types/utils/shared.d.ts +230 -0
  165. package/types/webgl/Framebuffer.d.ts +135 -0
  166. package/types/webgl/Handler.d.ts +372 -0
  167. package/types/webgl/Multisample.d.ts +89 -0
  168. package/types/webgl/Program.d.ts +155 -0
  169. package/types/webgl/ProgramController.d.ts +84 -0
  170. package/types/webgl/callbacks.d.ts +1 -0
  171. package/types/webgl/index.d.ts +6 -0
  172. package/types/webgl/types.d.ts +2 -0
@@ -12,503 +12,503 @@ import { Vec3 } from './Vec3.js';
12
12
  * @param {number} [x] - First value.
13
13
  * @param {number} [y] - Second value.
14
14
  */
15
- const Vec2 = function (x, y) {
15
+ export class Vec2 {
16
+
17
+ constructor(x, y) {
18
+
19
+ /**
20
+ * @public
21
+ * @type {number}
22
+ */
23
+ this.x = x || 0.0;
24
+
25
+ /**
26
+ * @public
27
+ * @type {number}
28
+ */
29
+ this.y = y || 0.0;
30
+ };
31
+ /** @const */
32
+ static get UP() { return new Vec2(0, 1) };
33
+ /** @const */
34
+ static get DOWN() { return new Vec2(0, -1) };
35
+ /** @const */
36
+ static get RIGHT() { return new Vec2(1, 0) };
37
+ /** @const */
38
+ static get LEFT() { return new Vec2(-1, 0) };
39
+ /** @const */
40
+ static get ZERO() { return new Vec2() };
16
41
 
17
42
  /**
18
- * @public
19
- * @type {number}
43
+ * Returns summary vector.
44
+ * @static
45
+ * @param {og.math.Vec2} a - First vector.
46
+ * @param {og.math.Vec2} b - Second vector.
47
+ * @returns {og.math.Vec2} - Summary vector.
20
48
  */
21
- this.x = x || 0.0;
49
+ static add(a, b) {
50
+ var res = new Vec2(a.x, a.y);
51
+ res.addA(b);
52
+ return res;
53
+ };
22
54
 
23
55
  /**
24
- * @public
25
- * @type {number}
56
+ * Returns two vectors subtraction.
57
+ * @static
58
+ * @param {og.math.Vec2} a - First vector.
59
+ * @param {og.math.Vec2} b - Second vector.
60
+ * @returns {og.math.Vec2} - Vectors subtraction.
26
61
  */
27
- this.y = y || 0.0;
28
- };
62
+ static sub(a, b) {
63
+ var res = new Vec2(a.x, a.y);
64
+ res.subA(b);
65
+ return res;
66
+ };
29
67
 
30
- /**
31
- * Vector 2d object creator.
32
- * @function
33
- * @param {number} [x] - First cvalue.
34
- * @param {number} [y] - Second value.
35
- * @returns {og.math.Vec2}
36
- */
37
- export function vec2(x, y) {
38
- return new Vec2(x, y);
39
- };
40
-
41
- /** @const */
42
- Vec2.UP = new Vec2(0, 1);
43
- /** @const */
44
- Vec2.DOWN = new Vec2(0, -1);
45
- /** @const */
46
- Vec2.RIGHT = new Vec2(1, 0);
47
- /** @const */
48
- Vec2.LEFT = new Vec2(-1, 0);
49
- /** @const */
50
- Vec2.ZERO = new Vec2();
51
-
52
- /**
53
- * Returns summary vector.
54
- * @static
55
- * @param {og.math.Vec2} a - First vector.
56
- * @param {og.math.Vec2} b - Second vector.
57
- * @returns {og.math.Vec2} - Summary vector.
58
- */
59
- Vec2.add = function (a, b) {
60
- var res = new Vec2(a.x, a.y);
61
- res.addA(b);
62
- return res;
63
- };
64
-
65
- /**
66
- * Returns two vectors subtraction.
67
- * @static
68
- * @param {og.math.Vec2} a - First vector.
69
- * @param {og.math.Vec2} b - Second vector.
70
- * @returns {og.math.Vec2} - Vectors subtraction.
71
- */
72
- Vec2.sub = function (a, b) {
73
- var res = new Vec2(a.x, a.y);
74
- res.subA(b);
75
- return res;
76
- };
77
-
78
- /**
79
- * Returns scaled vector.
80
- * @static
81
- * @param {og.math.Vec2} a - Input vector.
82
- * @param {number} scale - Scale value.
83
- * @returns {og.math.Vec2}
84
- */
85
- Vec2.scale = function (a, scale) {
86
- var res = new Vec2(a.x, a.y);
87
- res.scale(scale);
88
- return res;
89
- };
68
+ /**
69
+ * Returns scaled vector.
70
+ * @static
71
+ * @param {og.math.Vec2} a - Input vector.
72
+ * @param {number} scale - Scale value.
73
+ * @returns {og.math.Vec2}
74
+ */
75
+ static scale(a, scale) {
76
+ var res = new Vec2(a.x, a.y);
77
+ res.scale(scale);
78
+ return res;
79
+ };
90
80
 
91
- /**
92
- * Returns two vectors production.
93
- * @static
94
- * @param {og.math.Vec2} a - First vector.
95
- * @param {og.math.Vec2} b - Second vector.
96
- * @returns {og.math.Vec2}
97
- */
98
- Vec2.mul = function (a, b) {
99
- var res = new Vec2(a.x, a.y);
100
- res.mulA(b);
101
- return res;
102
- };
81
+ /**
82
+ * Returns two vectors production.
83
+ * @static
84
+ * @param {og.math.Vec2} a - First vector.
85
+ * @param {og.math.Vec2} b - Second vector.
86
+ * @returns {og.math.Vec2}
87
+ */
88
+ static mul(a, b) {
89
+ var res = new Vec2(a.x, a.y);
90
+ res.mulA(b);
91
+ return res;
92
+ };
103
93
 
104
- /**
105
- * Returns vector components division product one to another.
106
- * @static
107
- * @param {og.math.Vec2} a - First vector.
108
- * @param {og.math.Vec2} b - Second vector.
109
- * @returns {og.math.Vec2}
110
- */
111
- Vec2.div = function (a, b) {
112
- var res = new Vec2(a.x, a.y);
113
- res.divA(b);
114
- return res;
115
- };
94
+ /**
95
+ * Returns vector components division product one to another.
96
+ * @static
97
+ * @param {og.math.Vec2} a - First vector.
98
+ * @param {og.math.Vec2} b - Second vector.
99
+ * @returns {og.math.Vec2}
100
+ */
101
+ static div(a, b) {
102
+ var res = new Vec2(a.x, a.y);
103
+ res.divA(b);
104
+ return res;
105
+ };
116
106
 
117
- /**
118
- * Get projection of the first vector to the second.
119
- * @static
120
- * @param {og.math.Vec2} b - First vector.
121
- * @param {og.math.Vec2} a - Second vector.
122
- * @returns {og.math.Vec2}
123
- */
124
- Vec2.proj_b_to_a = function (b, a) {
125
- return a.scaleTo(a.dot(b) / a.dot(a));
126
- };
107
+ /**
108
+ * Get projection of the first vector to the second.
109
+ * @static
110
+ * @param {og.math.Vec2} b - First vector.
111
+ * @param {og.math.Vec2} a - Second vector.
112
+ * @returns {og.math.Vec2}
113
+ */
114
+ static proj_b_to_a(b, a) {
115
+ return a.scaleTo(a.dot(b) / a.dot(a));
116
+ };
127
117
 
128
- /**
129
- * Gets angle between two vectors.
130
- * @static
131
- * @param {og.math.Vec2} a - First vector.
132
- * @param {og.math.Vec2} b - Second vector.
133
- * @returns {number}
134
- */
135
- Vec2.angle = function (a, b) {
136
- return Math.acos(a.dot(b) / Math.sqrt(a.length2() * b.length2()));
137
- };
118
+ /**
119
+ * Gets angle between two vectors.
120
+ * @static
121
+ * @param {og.math.Vec2} a - First vector.
122
+ * @param {og.math.Vec2} b - Second vector.
123
+ * @returns {number}
124
+ */
125
+ static angle(a, b) {
126
+ return Math.acos(a.dot(b) / Math.sqrt(a.length2() * b.length2()));
127
+ };
138
128
 
139
- /**
140
- * Makes vectors normalized and orthogonal to each other.
141
- * @static
142
- * @param {og.math.Vec2} normal - Normal vector.
143
- * @param {og.math.Vec2} tangent - Tangent vector.
144
- * @returns {og.math.Vec2}
145
- */
146
- Vec2.orthoNormalize = function (normal, tangent) {
147
- normal = normal.norm();
148
- normal.scale(tangent.dot(normal));
149
- return tangent.sub(normal).normalize();
150
- };
129
+ /**
130
+ * Makes vectors normalized and orthogonal to each other.
131
+ * @static
132
+ * @param {og.math.Vec2} normal - Normal vector.
133
+ * @param {og.math.Vec2} tangent - Tangent vector.
134
+ * @returns {og.math.Vec2}
135
+ */
136
+ static orthoNormalize(normal, tangent) {
137
+ normal = normal.norm();
138
+ normal.scale(tangent.dot(normal));
139
+ return tangent.sub(normal).normalize();
140
+ };
151
141
 
152
- /**
153
- * Converts to 3d vector, third value is 0.0.
154
- * @public
155
- * @returns {og.Vec3}
156
- */
157
- Vec2.prototype.toVector3 = function () {
158
- return new Vec3(this.x, this.y, 0);
159
- };
142
+ /**
143
+ * Converts to 3d vector, third value is 0.0.
144
+ * @public
145
+ * @returns {og.Vec3}
146
+ */
147
+ toVector3() {
148
+ return new Vec3(this.x, this.y, 0);
149
+ };
160
150
 
161
- /**
162
- * Returns clone vector.
163
- * @public
164
- * @returns {og.math.Vec2}
165
- */
166
- Vec2.prototype.clone = function () {
167
- return new Vec2(this.x, this.y);
168
- };
151
+ /**
152
+ * Returns clone vector.
153
+ * @public
154
+ * @returns {og.math.Vec2}
155
+ */
156
+ clone() {
157
+ return new Vec2(this.x, this.y);
158
+ };
169
159
 
170
- /**
171
- * Compares with vector. Returns true if it equals another.
172
- * @public
173
- * @param {og.math.Vec2} p - Vector to compare.
174
- * @returns {boolean}
175
- */
176
- Vec2.prototype.equal = function (p) {
177
- return this.x === p.x && this.y === p.y;
178
- };
160
+ /**
161
+ * Compares with vector. Returns true if it equals another.
162
+ * @public
163
+ * @param {og.math.Vec2} p - Vector to compare.
164
+ * @returns {boolean}
165
+ */
166
+ equal(p) {
167
+ return this.x === p.x && this.y === p.y;
168
+ };
179
169
 
180
- /**
181
- * Copy input vector's values.
182
- * @param {og.math.Vec2} point2 - Vector to copy.
183
- * @returns {og.math.Vec2}
184
- */
185
- Vec2.prototype.copy = function (point2) {
186
- this.x = point2.x;
187
- this.y = point2.y;
188
- return this;
189
- };
170
+ /**
171
+ * Copy input vector's values.
172
+ * @param {og.math.Vec2} point2 - Vector to copy.
173
+ * @returns {og.math.Vec2}
174
+ */
175
+ copy(point2) {
176
+ this.x = point2.x;
177
+ this.y = point2.y;
178
+ return this;
179
+ };
190
180
 
191
- /**
192
- * Gets vector's length.
193
- * @public
194
- * @returns {number}
195
- */
196
- Vec2.prototype.length = function () {
197
- return Math.sqrt(this.x * this.x + this.y * this.y);
198
- };
181
+ /**
182
+ * Gets vector's length.
183
+ * @public
184
+ * @returns {number}
185
+ */
186
+ length() {
187
+ return Math.sqrt(this.x * this.x + this.y * this.y);
188
+ };
199
189
 
200
- /**
201
- * Returns squared vector's length.
202
- * @public
203
- * @returns {number}
204
- */
205
- Vec2.prototype.length2 = function () {
206
- return this.x * this.x + this.y * this.y;
207
- };
190
+ /**
191
+ * Returns squared vector's length.
192
+ * @public
193
+ * @returns {number}
194
+ */
195
+ length2() {
196
+ return this.x * this.x + this.y * this.y;
197
+ };
208
198
 
209
- /**
210
- * Adds vector to the current.
211
- * @public
212
- * @param {og.math.Vec2}
213
- * @returns {og.math.Vec2}
214
- */
215
- Vec2.prototype.addA = function (v) {
216
- this.x += v.x;
217
- this.y += v.y;
218
- return this;
219
- };
199
+ /**
200
+ * Adds vector to the current.
201
+ * @public
202
+ * @param {og.math.Vec2}
203
+ * @returns {og.math.Vec2}
204
+ */
205
+ addA(v) {
206
+ this.x += v.x;
207
+ this.y += v.y;
208
+ return this;
209
+ };
220
210
 
221
- /**
222
- * Summarize two vectors.
223
- * @public
224
- * @param {og.math.Vec2}
225
- * @returns {og.math.Vec2}
226
- */
227
- Vec2.prototype.add = function (v) {
228
- return new Vec2(this.x + v.x, this.y + v.y);
229
- };
211
+ /**
212
+ * Summarize two vectors.
213
+ * @public
214
+ * @param {og.math.Vec2}
215
+ * @returns {og.math.Vec2}
216
+ */
217
+ add(v) {
218
+ return new Vec2(this.x + v.x, this.y + v.y);
219
+ };
230
220
 
231
- /**
232
- * Subtract vector from the current where results saved on the current instance.
233
- * @public
234
- * @param {og.math.Vec2} v - Subtract vector.
235
- * @returns {og.math.Vec2}
236
- */
237
- Vec2.prototype.subA = function (v) {
238
- this.x -= v.x;
239
- this.y -= v.y;
240
- return this;
241
- };
221
+ /**
222
+ * Subtract vector from the current where results saved on the current instance.
223
+ * @public
224
+ * @param {og.math.Vec2} v - Subtract vector.
225
+ * @returns {og.math.Vec2}
226
+ */
227
+ subA(v) {
228
+ this.x -= v.x;
229
+ this.y -= v.y;
230
+ return this;
231
+ };
242
232
 
243
- /**
244
- * Subtract vector from the current.
245
- * @public
246
- * @param {og.math.Vec2} v - Subtract vector.
247
- * @returns {og.math.Vec2}
248
- */
249
- Vec2.prototype.sub = function (v) {
250
- return new Vec2(this.x - v.x, this.y - v.y);
251
- };
233
+ /**
234
+ * Subtract vector from the current.
235
+ * @public
236
+ * @param {og.math.Vec2} v - Subtract vector.
237
+ * @returns {og.math.Vec2}
238
+ */
239
+ sub(v) {
240
+ return new Vec2(this.x - v.x, this.y - v.y);
241
+ };
252
242
 
253
- /**
254
- * Scale current vector.
255
- * @public
256
- * @param {number} scale - Scale value.
257
- * @returns {og.math.Vec2}
258
- */
259
- Vec2.prototype.scale = function (scale) {
260
- this.x *= scale;
261
- this.y *= scale;
262
- return this;
263
- };
243
+ /**
244
+ * Scale current vector.
245
+ * @public
246
+ * @param {number} scale - Scale value.
247
+ * @returns {og.math.Vec2}
248
+ */
249
+ scale(scale) {
250
+ this.x *= scale;
251
+ this.y *= scale;
252
+ return this;
253
+ };
264
254
 
265
- /**
266
- * Scale current vector to another instance.
267
- * @public
268
- * @param {number} scale - Scale value.
269
- * @returns {og.math.Vec2}
270
- */
271
- Vec2.prototype.scaleTo = function (scale) {
272
- return new Vec2(this.x * scale, this.y * scale);
273
- };
255
+ /**
256
+ * Scale current vector to another instance.
257
+ * @public
258
+ * @param {number} scale - Scale value.
259
+ * @returns {og.math.Vec2}
260
+ */
261
+ scaleTo(scale) {
262
+ return new Vec2(this.x * scale, this.y * scale);
263
+ };
274
264
 
275
- /**
276
- * Multiply current vector object to another and store result in the current instance.
277
- * @public
278
- * @param {og.math.Vec2} vec - Multiply vector.
279
- * @returns {og.math.Vec2}
280
- */
281
- Vec2.prototype.mulA = function (vec) {
282
- this.x *= vec.x;
283
- this.y *= vec.y;
284
- return this;
285
- };
265
+ /**
266
+ * Multiply current vector object to another and store result in the current instance.
267
+ * @public
268
+ * @param {og.math.Vec2} vec - Multiply vector.
269
+ * @returns {og.math.Vec2}
270
+ */
271
+ mulA(vec) {
272
+ this.x *= vec.x;
273
+ this.y *= vec.y;
274
+ return this;
275
+ };
286
276
 
287
- /**
288
- * Multiply current vector object to another and returns new vector instance.
289
- * @public
290
- * @param {og.math.Vec2} vec - Multiply vector.
291
- * @returns {og.math.Vec2}
292
- */
293
- Vec2.prototype.mul = function (vec) {
294
- return new Vec2(this.x * vec.x, this.y * vec.y);
295
- };
277
+ /**
278
+ * Multiply current vector object to another and returns new vector instance.
279
+ * @public
280
+ * @param {og.math.Vec2} vec - Multiply vector.
281
+ * @returns {og.math.Vec2}
282
+ */
283
+ mul(vec) {
284
+ return new Vec2(this.x * vec.x, this.y * vec.y);
285
+ };
296
286
 
297
- /**
298
- * Divide current vector's components to another. Results stores in the current vector object.
299
- * @public
300
- * @param {og.math.Vec2}
301
- * @returns {og.math.Vec2}
302
- */
303
- Vec2.prototype.divA = function (vec) {
304
- this.x /= vec.x;
305
- this.y /= vec.y;
306
- return this;
307
- };
287
+ /**
288
+ * Divide current vector's components to another. Results stores in the current vector object.
289
+ * @public
290
+ * @param {og.math.Vec2}
291
+ * @returns {og.math.Vec2}
292
+ */
293
+ divA(vec) {
294
+ this.x /= vec.x;
295
+ this.y /= vec.y;
296
+ return this;
297
+ };
308
298
 
309
- /**
310
- * Gets vectors dot production.
311
- * @public
312
- * @param {og.math.Vec2} v - Another vector.
313
- * @returns {number}
314
- */
315
- Vec2.prototype.dot = function (v) {
316
- return v.x * this.x + v.y * this.y;
317
- };
299
+ /**
300
+ * Gets vectors dot production.
301
+ * @public
302
+ * @param {og.math.Vec2} v - Another vector.
303
+ * @returns {number}
304
+ */
305
+ dot(v) {
306
+ return v.x * this.x + v.y * this.y;
307
+ };
318
308
 
319
- /**
320
- * Gets vectors dot production.
321
- * @public
322
- * @param {Array.<number,number>} arr - Array vector.
323
- * @returns {number}
324
- */
325
- Vec2.prototype.dotArr = function (arr) {
326
- return arr[0] * this.x + arr[1] * this.y;
327
- };
309
+ /**
310
+ * Gets vectors dot production.
311
+ * @public
312
+ * @param {Array.<number,number>} arr - Array vector.
313
+ * @returns {number}
314
+ */
315
+ dotArr(arr) {
316
+ return arr[0] * this.x + arr[1] * this.y;
317
+ };
328
318
 
329
- /**
330
- * Gets vectors cross production.
331
- * @public
332
- * @param {og.math.Vec2} v - Another vector.
333
- * @returns {og.math.Vec2}
334
- */
335
- Vec2.prototype.cross = function (v) {
336
- return this.x * v.y - this.y * v.x;
337
- };
319
+ /**
320
+ * Gets vectors cross production.
321
+ * @public
322
+ * @param {og.math.Vec2} v - Another vector.
323
+ * @returns {og.math.Vec2}
324
+ */
325
+ cross(v) {
326
+ return this.x * v.y - this.y * v.x;
327
+ };
338
328
 
339
- /**
340
- * Sets vector to zero.
341
- * @public
342
- * @returns {og.math.Vec2}
343
- */
344
- Vec2.prototype.clear = function () {
345
- this.x = this.y = 0;
346
- return this;
347
- };
329
+ /**
330
+ * Sets vector to zero.
331
+ * @public
332
+ * @returns {og.math.Vec2}
333
+ */
334
+ clear() {
335
+ this.x = this.y = 0;
336
+ return this;
337
+ };
348
338
 
349
- /**
350
- * Returns normalized vector.
351
- * @public
352
- * @returns {og.math.Vec2}
353
- */
354
- Vec2.prototype.normal = function () {
355
- var res = new Vec2();
356
- res.copy(this);
339
+ /**
340
+ * Returns normalized vector.
341
+ * @public
342
+ * @returns {og.math.Vec2}
343
+ */
344
+ normal() {
345
+ var res = new Vec2();
346
+ res.copy(this);
357
347
 
358
- var length = 1.0 / res.length();
348
+ var length = 1.0 / res.length();
359
349
 
360
- res.x *= length;
361
- res.y *= length;
350
+ res.x *= length;
351
+ res.y *= length;
362
352
 
363
- return res;
364
- };
353
+ return res;
354
+ };
365
355
 
366
- /**
367
- * Normalize current vector.
368
- * @public
369
- * @returns {og.math.Vec2}
370
- */
371
- Vec2.prototype.normalize = function () {
372
- var length = 1.0 / this.length();
356
+ /**
357
+ * Normalize current vector.
358
+ * @public
359
+ * @returns {og.math.Vec2}
360
+ */
361
+ normalize() {
362
+ var length = 1.0 / this.length();
373
363
 
374
- this.x *= length;
375
- this.y *= length;
364
+ this.x *= length;
365
+ this.y *= length;
376
366
 
377
- return this;
378
- };
367
+ return this;
368
+ };
379
369
 
380
- /**
381
- * Converts vector to a number array.
382
- * @public
383
- * @returns {Array.<number,number>}
384
- */
385
- Vec2.prototype.toVec = function () {
386
- return [this.x, this.y];
387
- };
370
+ /**
371
+ * Converts vector to a number array.
372
+ * @public
373
+ * @returns {Array.<number,number>}
374
+ */
375
+ toVec() {
376
+ return [this.x, this.y];
377
+ };
388
378
 
389
- /**
390
- * Gets distance to point.
391
- * @public
392
- * @param {og.math.Vec2} p - Distant point.
393
- * @returns {number}
394
- */
395
- Vec2.prototype.distance = function (p) {
396
- var vec = Vec2.sub(this, p);
397
- return vec.length();
398
- };
379
+ /**
380
+ * Gets distance to point.
381
+ * @public
382
+ * @param {og.math.Vec2} p - Distant point.
383
+ * @returns {number}
384
+ */
385
+ distance(p) {
386
+ var vec = Vec2.sub(this, p);
387
+ return vec.length();
388
+ };
399
389
 
400
- /**
401
- * Sets vector's values.
402
- * @public
403
- * @param {number} x - Value X.
404
- * @param {number} y - Value Y.
405
- * @returns {og.math.Vec2}
406
- */
407
- Vec2.prototype.set = function (x, y) {
408
- this.x = x;
409
- this.y = y;
410
- return this;
411
- };
390
+ /**
391
+ * Sets vector's values.
392
+ * @public
393
+ * @param {number} x - Value X.
394
+ * @param {number} y - Value Y.
395
+ * @returns {og.math.Vec2}
396
+ */
397
+ set(x, y) {
398
+ this.x = x;
399
+ this.y = y;
400
+ return this;
401
+ };
412
402
 
413
- /**
414
- * Negate current vector.
415
- * @public
416
- * @returns {og.math.Vec2}
417
- */
418
- Vec2.prototype.negate = function () {
419
- this.x = -this.x;
420
- this.y = -this.y;
421
- return this;
422
- };
403
+ /**
404
+ * Negate current vector.
405
+ * @public
406
+ * @returns {og.math.Vec2}
407
+ */
408
+ negate() {
409
+ this.x = -this.x;
410
+ this.y = -this.y;
411
+ return this;
412
+ };
423
413
 
424
- /**
425
- * Negate current vector to another instance.
426
- * @public
427
- * @returns {og.math.Vec2}
428
- */
429
- Vec2.prototype.negateTo = function () {
430
- return new Vec2(-this.x, -this.y);
431
- };
414
+ /**
415
+ * Negate current vector to another instance.
416
+ * @public
417
+ * @returns {og.math.Vec2}
418
+ */
419
+ negateTo() {
420
+ return new Vec2(-this.x, -this.y);
421
+ };
432
422
 
433
- /**
434
- * Gets projected point coordinates of the current vector on the ray.
435
- * @public
436
- * @param {og.math.Vec2} pos - Ray position.
437
- * @param {og.math.Vec2} direction - Ray direction.
438
- * @returns {og.math.Vec2}
439
- */
440
- Vec2.prototype.projToRay = function (pos, direction) {
441
- var v = Vec2.proj_b_to_a(Vec2.sub(this, pos), direction);
442
- v.add(pos);
443
- return v;
444
- };
423
+ /**
424
+ * Gets projected point coordinates of the current vector on the ray.
425
+ * @public
426
+ * @param {og.math.Vec2} pos - Ray position.
427
+ * @param {og.math.Vec2} direction - Ray direction.
428
+ * @returns {og.math.Vec2}
429
+ */
430
+ projToRay(pos, direction) {
431
+ var v = Vec2.proj_b_to_a(Vec2.sub(this, pos), direction);
432
+ v.add(pos);
433
+ return v;
434
+ };
445
435
 
446
- /**
447
- * Gets angle between two vectors.
448
- * @public
449
- * @param {og.math.Vec2} a - Another vector.
450
- * @returns {number}
451
- */
452
- Vec2.prototype.angle = function (a) {
453
- return Vec2.angle(this, a);
454
- };
436
+ /**
437
+ * Gets angle between two vectors.
438
+ * @public
439
+ * @param {og.math.Vec2} a - Another vector.
440
+ * @returns {number}
441
+ */
442
+ angle(a) {
443
+ return Vec2.angle(this, a);
444
+ };
455
445
 
456
- /**
457
- * Returns two vectors linear interpolation.
458
- * @public
459
- * @param {og.math.Vec2} v2 - End vector.
460
- * @param {number} l - Interpolate value.
461
- * @returns {og.math.Vec2}
462
- */
463
- Vec2.prototype.lerp = function (v1, v2, l) {
464
- var res = Vec2.clone(this);
465
- if (l <= 0.0) {
466
- res.copy(v1);
467
- } else if (l >= 1.0) {
468
- res.copy(v2);
469
- } else {
470
- res = Vec2.add(v1, Vec2.sub(v2, v1).scale(l));
471
- }
472
- return res;
473
- };
446
+ /**
447
+ * Returns two vectors linear interpolation.
448
+ * @public
449
+ * @param {og.math.Vec2} v2 - End vector.
450
+ * @param {number} l - Interpolate value.
451
+ * @returns {og.math.Vec2}
452
+ */
453
+ lerp(v1, v2, l) {
454
+ var res = Vec2.clone(this);
455
+ if (l <= 0.0) {
456
+ res.copy(v1);
457
+ } else if (l >= 1.0) {
458
+ res.copy(v2);
459
+ } else {
460
+ res = Vec2.add(v1, Vec2.sub(v2, v1).scale(l));
461
+ }
462
+ return res;
463
+ };
464
+
465
+ static get LERP_DELTA() { return 1e-6 };
474
466
 
475
- Vec2.LERP_DELTA = 1e-6;
467
+ /**
468
+ * Spherically interpolates between two vectors.
469
+ * Interpolates between current and v2 vector by amount t. The difference between this and linear interpolation (aka, "lerp") is that
470
+ * the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated
471
+ * by the angle and its magnitude is interpolated between the magnitudes of from and to.
472
+ * @public
473
+ * @param {og.math.Vec2} v2 -
474
+ * @param {number} t - The parameter t is clamped to the range [0, 1].
475
+ * @returns {og.math.Vec2}
476
+ */
477
+ slerp(v2, t) {
478
+ var res = new Vec2();
479
+
480
+ if (t <= 0.0) {
481
+ res.copy(this);
482
+ return;
483
+ } else if (t >= 1.0) {
484
+ res.copy(v2);
485
+ return;
486
+ }
487
+
488
+ var omega, sinom, scale0, scale1;
489
+ var cosom = this.dot(v2);
490
+
491
+ if ((1.0 - cosom) > Vec2.LERP_DELTA) {
492
+ omega = Math.acos(cosom);
493
+ sinom = Math.sin(omega);
494
+ scale0 = Math.sin((1.0 - t) * omega) / sinom;
495
+ scale1 = Math.sin(t * omega) / sinom;
496
+ } else {
497
+ scale0 = 1.0 - t;
498
+ scale1 = t;
499
+ }
500
+
501
+ return Vec2.add(this.scale(scale0), v2.scale(scale1));
502
+ };
503
+ }
476
504
 
477
505
  /**
478
- * Spherically interpolates between two vectors.
479
- * Interpolates between current and v2 vector by amount t. The difference between this and linear interpolation (aka, "lerp") is that
480
- * the vectors are treated as directions rather than points in space. The direction of the returned vector is interpolated
481
- * by the angle and its magnitude is interpolated between the magnitudes of from and to.
482
- * @public
483
- * @param {og.math.Vec2} v2 -
484
- * @param {number} t - The parameter t is clamped to the range [0, 1].
506
+ * Vector 2d object creator.
507
+ * @function
508
+ * @param {number} [x] - First cvalue.
509
+ * @param {number} [y] - Second value.
485
510
  * @returns {og.math.Vec2}
486
511
  */
487
- Vec2.prototype.slerp = function (v2, t) {
488
- var res = new Vec2();
489
-
490
- if (t <= 0.0) {
491
- res.copy(this);
492
- return;
493
- } else if (t >= 1.0) {
494
- res.copy(v2);
495
- return;
496
- }
497
-
498
- var omega, sinom, scale0, scale1;
499
- var cosom = this.dot(v2);
500
-
501
- if ((1.0 - cosom) > Vec2.LERP_DELTA) {
502
- omega = Math.acos(cosom);
503
- sinom = Math.sin(omega);
504
- scale0 = Math.sin((1.0 - t) * omega) / sinom;
505
- scale1 = Math.sin(t * omega) / sinom;
506
- } else {
507
- scale0 = 1.0 - t;
508
- scale1 = t;
509
- }
510
-
511
- return Vec2.add(this.scale(scale0), v2.scale(scale1));
512
+ export function vec2(x, y) {
513
+ return new Vec2(x, y);
512
514
  };
513
-
514
- export { Vec2 };