|
3 | 3 | * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ |
4 | 4 |
|
5 | 5 | use crate::dom::bindings::codegen::Bindings::DOMPointBinding::DOMPointInit; |
6 | | -use crate::dom::bindings::codegen::Bindings::XRRayBinding::XRRayMethods; |
| 6 | +use crate::dom::bindings::codegen::Bindings::XRRayBinding::{XRRayDirectionInit, XRRayMethods}; |
| 7 | +use crate::dom::bindings::error::{Error, Fallible}; |
7 | 8 | use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; |
8 | 9 | use crate::dom::bindings::root::DomRoot; |
9 | 10 | use crate::dom::bindings::utils::create_typed_array; |
@@ -45,25 +46,35 @@ impl XRRay { |
45 | 46 | pub fn Constructor( |
46 | 47 | window: &Window, |
47 | 48 | origin: &DOMPointInit, |
48 | | - direction: &DOMPointInit, |
49 | | - ) -> DomRoot<Self> { |
| 49 | + direction: &XRRayDirectionInit, |
| 50 | + ) -> Fallible<DomRoot<Self>> { |
| 51 | + if origin.w != 1.0 { |
| 52 | + return Err(Error::Type("Origin w coordinate must be 1".into())); |
| 53 | + } |
| 54 | + if *direction.w != 0.0 { |
| 55 | + return Err(Error::Type("Direction w coordinate must be 0".into())); |
| 56 | + } |
| 57 | + if *direction.x == 0.0 && *direction.y == 0.0 && *direction.z == 0.0 { |
| 58 | + return Err(Error::Type("Direction vector cannot have zero length".into())); |
| 59 | + } |
| 60 | + |
50 | 61 | let origin = Vector3D::new(origin.x as f32, origin.y as f32, origin.z as f32); |
51 | 62 | let direction = |
52 | | - Vector3D::new(direction.x as f32, direction.y as f32, direction.z as f32).normalize(); |
| 63 | + Vector3D::new(*direction.x as f32, *direction.y as f32, *direction.z as f32).normalize(); |
53 | 64 |
|
54 | | - Self::new(&window.global(), Ray { origin, direction }) |
| 65 | + Ok(Self::new(&window.global(), Ray { origin, direction })) |
55 | 66 | } |
56 | 67 |
|
57 | 68 | #[allow(non_snake_case)] |
58 | 69 | /// https://immersive-web.github.io/hit-test/#dom-xrray-xrray-transform |
59 | | - pub fn Constructor_(window: &Window, transform: &XRRigidTransform) -> DomRoot<Self> { |
| 70 | + pub fn Constructor_(window: &Window, transform: &XRRigidTransform) -> Fallible<DomRoot<Self>> { |
60 | 71 | let transform = transform.transform(); |
61 | 72 | let origin = transform.translation; |
62 | 73 | let direction = transform |
63 | 74 | .rotation |
64 | 75 | .transform_vector3d(Vector3D::new(0., 0., -1.)); |
65 | 76 |
|
66 | | - Self::new(&window.global(), Ray { origin, direction }) |
| 77 | + Ok(Self::new(&window.global(), Ray { origin, direction })) |
67 | 78 | } |
68 | 79 | } |
69 | 80 |
|
|
0 commit comments