Skip to content

Commit 09bf18a

Browse files
authored
Update XRRay vector constructor to use correct webidl semantics (#85)
* Fix webidl for XRRay * Update XRRay vector constructor to use correct webidl semantics Fixes #84 This adds a new initializer type so that the defaults work correctly. * Throw error for non-1 w coordinate for XRRay constructor's position * Throw on nonzero direction.w
1 parent a9aca35 commit 09bf18a

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

index.bs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,20 @@ When the <dfn method for="XRFrame">getHitTestResultsForTransientInput(|hitTestSo
542542
Geometric primitives {#geometric-primitives}
543543
====================
544544

545+
XRRayDirectionInit {#xr-ray-direction-init-dictionary}
546+
--------------------
547+
548+
An {{XRRayDirectionInit}} dictionary represents a direction vector to be passed to the {{XRRay(origin, direction)}} constructor.
549+
550+
<script type="idl">
551+
dictionary XRRayDirectionInit {
552+
double x = 0;
553+
double y = 0;
554+
double z = -1;
555+
double w = 0;
556+
};
557+
</script>
558+
545559
XRRay {#xrray-interface}
546560
-----
547561

@@ -550,10 +564,10 @@ An {{XRRay}} is a geometric ray described by an {{XRRay/origin}} point and {{XRR
550564
An {{XRRay}} contains a <dfn for=XRRay>matrix</dfn> which is a [=/matrix=].
551565

552566
<script type="idl">
553-
[SecureContext, Exposed=Window,
554-
Constructor(optional DOMPointInit origin, optional DOMPointInit direction),
555-
Constructor(XRRigidTransform transform)]
567+
[SecureContext, Exposed=Window]
556568
interface XRRay {
569+
constructor(optional DOMPointInit origin = {}, optional XRRayDirectionInit direction = {});
570+
constructor(XRRigidTransform transform);
557571
[SameObject] readonly attribute DOMPointReadOnly origin;
558572
[SameObject] readonly attribute DOMPointReadOnly direction;
559573
[SameObject] readonly attribute Float32Array matrix;
@@ -567,8 +581,11 @@ The <dfn constructor for="XRRay">XRRay(|origin|, |direction|)</dfn> constructor
567581
1. Let |ray| be a new {{XRRay}}.
568582
1. Initialize |ray|'s {{XRRay/origin}} to <code>{ x: 0.0, y: 0.0, z: 0.0, w: 1.0 }</code>.
569583
1. Initialize |ray|'s {{XRRay/direction}} to <code>{ x: 0.0, y: 0.0, z: -1.0, w: 0.0 }</code>.
570-
1. If |origin| was set, initialize |ray|'s {{XRRay/origin}}’s {{DOMPointReadOnly/x}} value to |origin|'s x dictionary member, {{DOMPointReadOnly/y}} value to |origin|'s y dictionary member, and {{DOMPointReadOnly/z}} value to |origin|'s z dictionary member.
571-
1. If |direction| was set, initialize |ray|'s {{XRRay/direction}}’s {{DOMPointReadOnly/x}} value to |direction|'s x dictionary member, {{DOMPointReadOnly/y}} value to |direction|'s y dictionary member, and {{DOMPointReadOnly/z}} value to |direction|'s z dictionary member.
584+
1. If all of |direction|'s {{XRRayDirectionInit/x}}, {{XRRayDirectionInit/y}}, and {{XRRayDirectionInit/z}} are zero, throw a {{TypeError}} and abort these steps.
585+
1. If |direction|'s {{XRRayDirectionInit/w}} is not 0.0, throw a {{TypeError}} and abort these steps.
586+
1. If |origin|'s {{DOMPointInit/w}} is not 1.0, throw a {{TypeError}} and abort these steps.
587+
1. Initialize |ray|'s {{XRRay/origin}}’s {{DOMPointReadOnly/x}} value to |origin|'s {{DOMPointInit/x}}, {{DOMPointReadOnly/y}} value to |origin|'s {{DOMPointInit/y}}, and {{DOMPointReadOnly/z}} value to |origin|'s {{DOMPointInit/z}}.
588+
1. Initialize |ray|'s {{XRRay/direction}}’s {{DOMPointReadOnly/x}} value to |direction|'s {{XRRayDirectionInit/x}}, {{DOMPointReadOnly/y}} value to |direction|'s {{XRRayDirectionInit/y}}, and {{DOMPointReadOnly/z}} value to |direction|'s {{XRRayDirectionInit/z}}.
572589
1. [=Normalize=] the {{DOMPointReadOnly/x}}, {{DOMPointReadOnly/y}}, and {{DOMPointReadOnly/z}} components of |ray|'s {{XRRay/direction}}.
573590
1. Initialize |ray|'s [=XRRay/matrix=] to <code>null</code>.
574591
1. Return |ray|.

0 commit comments

Comments
 (0)