Commit 91ebbb8c authored by Alex Cooper's avatar Alex Cooper Committed by Commit Bot

Update XRRigidTransform Constructor checks

This addresses feedback submitted to crrev.com/c/1725319 after it was
submitted.  Mainly around using exact equality for whole numbers and
the math around a length of zero.

Bug: 977703
Change-Id: Ia43f204a9f754077cda6bd74b2e901f724c7ee9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1727571
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Klaus Weidner <klausw@chromium.org>
Auto-Submit: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682538}
parent 7db18881
...@@ -12,12 +12,6 @@ ...@@ -12,12 +12,6 @@
#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/transforms/transformation_matrix.h" #include "third_party/blink/renderer/platform/transforms/transformation_matrix.h"
namespace {
bool IsWithinEpsilon(double a, double b) {
return std::abs(a - b) < std::numeric_limits<double>::epsilon();
}
} // namespace
namespace blink { namespace blink {
// makes a deep copy of transformationMatrix // makes a deep copy of transformationMatrix
...@@ -68,16 +62,21 @@ XRRigidTransform::XRRigidTransform(DOMPointInit* position, ...@@ -68,16 +62,21 @@ XRRigidTransform::XRRigidTransform(DOMPointInit* position,
XRRigidTransform* XRRigidTransform::Create(DOMPointInit* position, XRRigidTransform* XRRigidTransform::Create(DOMPointInit* position,
DOMPointInit* orientation, DOMPointInit* orientation,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (position && !IsWithinEpsilon(1.0, position->w())) { if (position && position->w() != 1.0) {
exception_state.ThrowTypeError("W component of position must be 1.0"); exception_state.ThrowTypeError("W component of position must be 1.0");
return nullptr; return nullptr;
} }
if (orientation) { if (orientation) {
if (IsWithinEpsilon(orientation->x(), 0.0) && double x = orientation->x();
IsWithinEpsilon(orientation->y(), 0.0) && double y = orientation->y();
IsWithinEpsilon(orientation->z(), 0.0) && double z = orientation->z();
IsWithinEpsilon(orientation->w(), 0.0)) { double w = orientation->w();
double sq_len = x * x + y * y + z * z + w * w;
// The only way for the result of a square root to be 0 is if the squared
// number is 0, so save the square root operation and just compare to 0 now.
if (sq_len == 0.0) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
"Orientation's length cannot be 0"); "Orientation's length cannot be 0");
return nullptr; return nullptr;
......
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