Commit 9fe8a648 authored by Piotr Bialecki's avatar Piotr Bialecki Committed by Commit Bot

CL followup - run ESLint, throw from math helper

- ran ESLint on webxr-test.js and xr-internal-device-mocking.js
- xr-internal-device-mocking.js now stores the
  `MockRuntime._injectAdditionalFrameData()` before overwriting it with
  its own implementation, and calls the original implementation as the
  first step
- throw instead of console.warn when math helper encounters unexpected
  combinations of .w component

Changes: 
Change-Id: I94c015b5c89cfbc0e1a4b90db6ec44a198f4ce05
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2008073
Commit-Queue: Piotr Bialecki <bialpio@chromium.org>
Commit-Queue: Klaus Weidner <klausw@chromium.org>
Auto-Submit: Piotr Bialecki <bialpio@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732977}
parent 665fc90a
...@@ -23,7 +23,7 @@ class XRMathHelper { ...@@ -23,7 +23,7 @@ class XRMathHelper {
// .w is treated here like an entity type, 1 signifies points, 0 signifies vectors. // .w is treated here like an entity type, 1 signifies points, 0 signifies vectors.
// point - point, point - vector, vector - vector are ok, vector - point is not. // point - point, point - vector, vector - vector are ok, vector - point is not.
if (lhs.w != rhs.w && lhs.w == 0.0) { if (lhs.w != rhs.w && lhs.w == 0.0) {
console.warn("vector - point not allowed: " + toString(lhs) + "-" + toString(rhs)); throw new Error("vector - point not allowed: " + toString(lhs) + "-" + toString(rhs));
} }
return {x : lhs.x - rhs.x, y : lhs.y - rhs.y, z : lhs.z - rhs.z, w : lhs.w - rhs.w}; return {x : lhs.x - rhs.x, y : lhs.y - rhs.y, z : lhs.z - rhs.z, w : lhs.w - rhs.w};
...@@ -31,7 +31,7 @@ class XRMathHelper { ...@@ -31,7 +31,7 @@ class XRMathHelper {
static add(lhs, rhs) { static add(lhs, rhs) {
if (lhs.w == rhs.w && lhs.w == 1.0) { if (lhs.w == rhs.w && lhs.w == 1.0) {
console.warn("point + point not allowed", p1, p2); throw new Error("point + point not allowed", p1, p2);
} }
return {x : lhs.x + rhs.x, y : lhs.y + rhs.y, z : lhs.z + rhs.z, w : lhs.w + rhs.w}; return {x : lhs.x + rhs.x, y : lhs.y + rhs.y, z : lhs.z + rhs.z, w : lhs.w + rhs.w};
...@@ -39,7 +39,7 @@ class XRMathHelper { ...@@ -39,7 +39,7 @@ class XRMathHelper {
static cross(lhs, rhs) { static cross(lhs, rhs) {
if (lhs.w != 0.0 || rhs.w != 0.0) { if (lhs.w != 0.0 || rhs.w != 0.0) {
console.warn("cross product not allowed: " + toString(lhs) + "x" + toString(rhs)); throw new Error("cross product not allowed: " + toString(lhs) + "x" + toString(rhs));
} }
return { return {
...@@ -52,7 +52,7 @@ class XRMathHelper { ...@@ -52,7 +52,7 @@ class XRMathHelper {
static dot(lhs, rhs) { static dot(lhs, rhs) {
if (lhs.w != 0 || rhs.w != 0) { if (lhs.w != 0 || rhs.w != 0) {
console.warn("dot product not allowed: " + toString(lhs) + "x" + toString(rhs)); throw new Error("dot product not allowed: " + toString(lhs) + "x" + toString(rhs));
} }
return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z; return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z;
...@@ -60,7 +60,7 @@ class XRMathHelper { ...@@ -60,7 +60,7 @@ class XRMathHelper {
static mul(scalar, vector) { static mul(scalar, vector) {
if (vector.w != 0) { if (vector.w != 0) {
console.warn("scalar * vector not allowed", scalar, vector); throw new Error("scalar * vector not allowed", scalar, vector);
} }
return {x : vector.x * scalar, y : vector.y * scalar, z : vector.z * scalar, w : vector.w}; return {x : vector.x * scalar, y : vector.y * scalar, z : vector.z * scalar, w : vector.w};
......
...@@ -11,9 +11,9 @@ MockRuntime.prototype.setHitTestResults = function(results) { ...@@ -11,9 +11,9 @@ MockRuntime.prototype.setHitTestResults = function(results) {
// XREnvironmentIntegrationProvider implementation // XREnvironmentIntegrationProvider implementation
MockRuntime.prototype.requestHitTest = function(ray) { MockRuntime.prototype.requestHitTest = function(ray) {
var hit_results = this.hittest_results_; let hit_results = this.hittest_results_;
if (!hit_results) { if (!hit_results) {
var hit = new device.mojom.XRHitResult(); const hit = new device.mojom.XRHitResult();
// No change to the underlying matrix/leaving it null results in identity. // No change to the underlying matrix/leaving it null results in identity.
hit.hitMatrix = new gfx.mojom.Transform(); hit.hitMatrix = new gfx.mojom.Transform();
...@@ -30,7 +30,10 @@ MockRuntime.prototype.getMissingFrameCount = function() { ...@@ -30,7 +30,10 @@ MockRuntime.prototype.getMissingFrameCount = function() {
return this.presentation_provider_.missing_frame_count_; return this.presentation_provider_.missing_frame_count_;
}; };
MockRuntime.prototype._injectAdditionalFrameData_preLightEstimation = MockRuntime.prototype._injectAdditionalFrameData;
MockRuntime.prototype._injectAdditionalFrameData = function(options, frameData) { MockRuntime.prototype._injectAdditionalFrameData = function(options, frameData) {
this._injectAdditionalFrameData_preLightEstimation(options, frameData);
if (!options || !options.includeLightingEstimationData) { if (!options || !options.includeLightingEstimationData) {
return; return;
} }
...@@ -38,7 +41,7 @@ MockRuntime.prototype._injectAdditionalFrameData = function(options, frameData) ...@@ -38,7 +41,7 @@ MockRuntime.prototype._injectAdditionalFrameData = function(options, frameData)
frameData.lightEstimationData = { frameData.lightEstimationData = {
lightProbe: { lightProbe: {
sphericalHarmonics: { sphericalHarmonics: {
coefficients: new Array(9).fill().map((x, i) => { return { red: i, green: i, blue: i }; }), coefficients: new Array(9).fill().map((x, i) => ({ red: i, green: i, blue: i })),
}, },
mainLightDirection: { x: 0, y: 1, z: 0 }, mainLightDirection: { x: 0, y: 1, z: 0 },
mainLightIntensity: { red: 1, green: 1, blue: 1 }, mainLightIntensity: { red: 1, green: 1, blue: 1 },
...@@ -82,7 +85,7 @@ MockXRInputSource.prototype.getInputSourceStateCommon = ...@@ -82,7 +85,7 @@ MockXRInputSource.prototype.getInputSourceStateCommon =
MockXRInputSource.prototype.getInputSourceState; MockXRInputSource.prototype.getInputSourceState;
MockXRInputSource.prototype.getInputSourceState = function() { MockXRInputSource.prototype.getInputSourceState = function() {
let input_state = this.getInputSourceStateCommon(); const input_state = this.getInputSourceStateCommon();
console.log('getInputSourceState this.overlay_pointer_position_=' + JSON.stringify(this.overlay_pointer_position_)); console.log('getInputSourceState this.overlay_pointer_position_=' + JSON.stringify(this.overlay_pointer_position_));
if (this.overlay_pointer_position_) { if (this.overlay_pointer_position_) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment