Skip to content

Commit

Permalink
Make poses nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 3, 2019
1 parent 0780fb0 commit 1062249
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions components/script/dom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ pub mod xmlserializer;
pub mod xr;
pub mod xrframe;
pub mod xrinputsource;
pub mod xrinputsourceevent;
pub mod xrpose;
pub mod xrreferencespace;
pub mod xrrenderstate;
Expand Down
12 changes: 10 additions & 2 deletions components/script/dom/xrframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ impl XRFrameMethods for XRFrame {
if !self.active.get() {
return Err(Error::InvalidState);
}
let space = space.get_pose(&self.data);
let relative_to = relative_to.get_pose(&self.data);
let space = if let Some(space) = space.get_pose(&self.data) {
space
} else {
return Ok(None);
};
let relative_to = if let Some(r) = relative_to.get_pose(&self.data) {
r
} else {
return Ok(None);
};
let pose = relative_to.inverse().pre_transform(&space);
Ok(Some(XRPose::new(&self.global(), pose)))
}
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/xrspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ impl XRSpace {
/// The reference origin used is common between all
/// get_pose calls for spaces from the same device, so this can be used to compare
/// with other spaces
pub fn get_pose(&self, base_pose: &Frame) -> ApiPose {
pub fn get_pose(&self, base_pose: &Frame) -> Option<ApiPose> {
if let Some(reference) = self.downcast::<XRReferenceSpace>() {
reference.get_pose(base_pose)
Some(reference.get_pose(base_pose))
} else if let Some(source) = self.input_source.get() {
// XXXManishearth we should be able to request frame information
// for inputs when necessary instead of always loading it
Expand All @@ -72,7 +72,7 @@ impl XRSpace {
.iter()
.find(|i| i.id == id)
.expect("no input found");
cast_transform(frame.target_ray_origin)
Some(cast_transform(frame.target_ray_origin))
} else {
unreachable!()
}
Expand Down

0 comments on commit 1062249

Please sign in to comment.