@wemap/camera 4.0.1 → 4.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/index.js CHANGED
@@ -2,3 +2,4 @@ export { BarcodeFormat } from '@zxing/library/es2015/index.js';
2
2
  export { default as Camera } from './src/Camera.js';
3
3
  export { default as QrCodeScanner } from './src/QrCodeScanner.js';
4
4
  export { default as SharedCameras } from './src/SharedCameras.js';
5
+ export * as CameraUtils from './src/CameraUtils.js';
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "directory": "packages/camera"
12
12
  },
13
13
  "name": "@wemap/camera",
14
- "version": "4.0.1",
14
+ "version": "4.0.2",
15
15
  "bugs": {
16
16
  "url": "https://github.com/wemap/wemap-modules-js/issues"
17
17
  },
@@ -27,5 +27,5 @@
27
27
  "events": "^3.1.0"
28
28
  },
29
29
  "type": "module",
30
- "gitHead": "ba5cebf23d528021d4bd1a3498d51d98ac655fb9"
30
+ "gitHead": "9d9cceb7b596afdb2b2987680edcfffcefa8a637"
31
31
  }
package/src/Camera.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import EventEmitter from 'events';
2
2
 
3
3
  import SharedCameras from './SharedCameras.js';
4
+ import { calcDisplayedFov } from './CameraUtils.js';
4
5
 
5
6
  const GENERIC_HARDWARE_VERTICAL_FOV = 60;
6
7
 
@@ -199,35 +200,14 @@ class Camera extends EventEmitter {
199
200
 
200
201
  _computeFov = () => {
201
202
 
202
- const sourceWidth = this.videoElement.videoWidth;
203
- const sourceHeight = this.videoElement.videoHeight;
204
-
205
- const containerWidth = this.videoContainer.offsetWidth;
206
- const containerHeight = this.videoContainer.offsetHeight;
207
-
208
- const sourceAspect = sourceWidth / sourceHeight;
209
- const screenAspect = containerWidth / containerHeight;
210
-
211
- let fovV = this._hardwareVerticalFov;
212
- let fovH = Camera.convertFov(fovV, sourceAspect);
213
-
214
- if (screenAspect < sourceAspect) {
215
- fovH = Camera.convertFov(fovV, screenAspect);
216
- } else {
217
- fovV = Camera.convertFov(fovH, 1 / screenAspect);
218
- }
219
-
220
- this.fov = {
221
- vertical: fovV,
222
- horizontal: fovH
223
- };
203
+ this.fov = calcDisplayedFov(
204
+ this.videoContainer,
205
+ this.videoElement,
206
+ this._hardwareVerticalFov
207
+ );
224
208
 
225
209
  this.emit('fov.changed', this.fov);
226
210
  }
227
-
228
- static convertFov(angle, aspectRatio) {
229
- return 2 * Math.atan(Math.tan((angle / 180 * Math.PI) / 2) * aspectRatio) * 180 / Math.PI;
230
- }
231
211
  }
232
212
 
233
213
  export default Camera;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @param {number} angle
3
+ * @param {numer} aspectRatio
4
+ * @returns {number}
5
+ */
6
+ export function convertFov(angle, aspectRatio) {
7
+ return 2 * Math.atan(Math.tan((angle / 180 * Math.PI) / 2) * aspectRatio) * 180 / Math.PI;
8
+ }
9
+
10
+ /**
11
+ * @param {HTMLDivElement} videoContainer
12
+ * @param {HTMLVideoElement} videoElement
13
+ * @param {number} hardwareVerticalFov
14
+ * @returns {object}
15
+ */
16
+ export function calcDisplayedFov(videoContainer, videoElement, hardwareVerticalFov) {
17
+
18
+ const sourceWidth = videoElement.videoWidth;
19
+ const sourceHeight = videoElement.videoHeight;
20
+
21
+ const containerWidth = videoContainer.offsetWidth;
22
+ const containerHeight = videoContainer.offsetHeight;
23
+
24
+ const sourceAspect = sourceWidth / sourceHeight;
25
+ const screenAspect = containerWidth / containerHeight;
26
+
27
+ let fovV = hardwareVerticalFov;
28
+ let fovH = convertFov(fovV, sourceAspect);
29
+
30
+ if (screenAspect < sourceAspect) {
31
+ fovH = convertFov(fovV, screenAspect);
32
+ } else {
33
+ fovV = convertFov(fovH, 1 / screenAspect);
34
+ }
35
+
36
+ return {
37
+ vertical: fovV,
38
+ horizontal: fovH
39
+ };
40
+ }