|
18 | 18 | { |
19 | 19 | // Check defaults - should be 0,0,0,1 for origin and 0,0,-1,0 for direction, |
20 | 20 | // identity matrix for the transform: |
21 | | - let xrRay = new XRRay(); |
| 21 | + let xrRay1 = new XRRay(); |
| 22 | + let xrRay2 = new XRRay({}); |
| 23 | + let xrRay3 = new XRRay({}, {}); |
| 24 | + |
22 | 25 | assert_point_approx_equals( |
23 | | - xrRay.origin, {x : 0.0, y : 0.0, z : 0.0, w : 1.0}, |
| 26 | + xrRay1.origin, {x : 0.0, y : 0.0, z : 0.0, w : 1.0}, |
24 | 27 | FLOAT_EPSILON, "origin-default:"); |
25 | 28 | assert_point_approx_equals( |
26 | | - xrRay.direction, {x : 0.0, y : 0.0, z : -1.0, w : 0.0}, |
| 29 | + xrRay1.direction, {x : 0.0, y : 0.0, z : -1.0, w : 0.0}, |
27 | 30 | FLOAT_EPSILON, "direction-default:"); |
28 | 31 | assert_matrix_approx_equals( |
29 | | - xrRay.matrix, IDENTITY_MATRIX, |
| 32 | + xrRay1.matrix, IDENTITY_MATRIX, |
30 | 33 | FLOAT_EPSILON, "matrix-default:"); |
| 34 | + |
| 35 | + assert_ray_approx_equals(xrRay1, xrRay2, FLOAT_EPSILON, "ray1-ray2-default:"); |
| 36 | + assert_ray_approx_equals(xrRay2, xrRay3, FLOAT_EPSILON, "ray2-ray3-default:"); |
31 | 37 | } |
32 | 38 |
|
33 | 39 | { |
34 | 40 | // Check custom value for origin, default for direction: |
35 | 41 | let originDict = {x : 11.0, y : 12.0, z : 13.0, w : 1.0}; |
| 42 | + let xrRay1 = new XRRay(originDict); |
36 | 43 | let xrRay2 = new XRRay(DOMPoint.fromPoint(originDict)); |
37 | 44 | let xrRay3 = new XRRay(DOMPointReadOnly.fromPoint(originDict)); |
38 | 45 | let matrix1 = [ 1, 0, 0, 0, |
|
41 | 48 | 11, 12, 13, 1]; |
42 | 49 |
|
43 | 50 | assert_point_approx_equals( |
44 | | - xrRay2.origin, originDict, |
| 51 | + xrRay1.origin, originDict, |
45 | 52 | FLOAT_EPSILON, "origin-custom-direction-default:"); |
46 | 53 | assert_point_approx_equals( |
47 | | - xrRay2.direction, {x : 0.0, y : 0.0, z : -1.0, w : 0.0}, |
| 54 | + xrRay1.direction, {x : 0.0, y : 0.0, z : -1.0, w : 0.0}, |
48 | 55 | FLOAT_EPSILON, "direction-custom-direction-default:"); |
49 | 56 | assert_matrix_approx_equals( |
50 | | - xrRay2.matrix, matrix1, |
| 57 | + xrRay1.matrix, matrix1, |
51 | 58 | FLOAT_EPSILON, "matrix-custom-direction-default:"); |
52 | 59 |
|
| 60 | + assert_ray_approx_equals(xrRay1, xrRay2, FLOAT_EPSILON, "ray1-ray2-direction-default:"); |
53 | 61 | assert_ray_approx_equals(xrRay2, xrRay3, FLOAT_EPSILON, "ray2-ray3-direction-default:"); |
54 | 62 | } |
55 | 63 |
|
|
67 | 75 | -1, 0, 0, 0, |
68 | 76 | 10, 10, 10, 1]; |
69 | 77 |
|
| 78 | + let xrRay1 = new XRRay( |
| 79 | + originDict, |
| 80 | + directionDict); |
| 81 | + |
70 | 82 | let xrRay2 = new XRRay( |
71 | 83 | DOMPoint.fromPoint(originDict), |
72 | 84 | DOMPoint.fromPoint(directionDict)); |
|
76 | 88 | DOMPointReadOnly.fromPoint(directionDict)); |
77 | 89 |
|
78 | 90 | assert_point_approx_equals( |
79 | | - xrRay2.origin, originDict, |
| 91 | + xrRay1.origin, originDict, |
80 | 92 | FLOAT_EPSILON, "origin-custom:"); |
81 | 93 | assert_point_approx_equals( |
82 | | - xrRay2.direction, directionNorm, |
| 94 | + xrRay1.direction, directionNorm, |
83 | 95 | FLOAT_EPSILON, "direction-custom:"); |
84 | 96 | assert_matrix_approx_equals( |
85 | | - xrRay2.matrix, matrix1, |
| 97 | + xrRay1.matrix, matrix1, |
86 | 98 | FLOAT_EPSILON, "matrix-custom:"); |
87 | 99 |
|
| 100 | + assert_ray_approx_equals(xrRay1, xrRay2, FLOAT_EPSILON, "ray1-ray2:"); |
88 | 101 | assert_ray_approx_equals(xrRay2, xrRay3, FLOAT_EPSILON, "ray2-ray3:"); |
89 | 102 | } |
90 | 103 |
|
|
108 | 121 | DOMPoint.fromPoint(directionDict) |
109 | 122 | ), "Constructor should throw for non-1 origin w coordinate"); |
110 | 123 | } |
| 124 | + |
111 | 125 | // |
112 | 126 | // Constructor 2 - from rigid transform. |
113 | 127 | // |
|
122 | 136 | 0.707, 0, -0.707, 0, |
123 | 137 | 10., 10, 10., 1]; |
124 | 138 |
|
125 | | - let xrRay4 = new XRRay( |
| 139 | + let xrRay = new XRRay( |
126 | 140 | new XRRigidTransform( |
127 | 141 | DOMPoint.fromPoint(originDict), |
128 | 142 | DOMPoint.fromPoint(directionQuaternionDict))); |
129 | 143 |
|
130 | 144 | assert_point_approx_equals( |
131 | | - xrRay4.origin, originDict, |
| 145 | + xrRay.origin, originDict, |
132 | 146 | FLOAT_EPSILON, "origin-custom-rigid:"); |
133 | 147 | assert_point_approx_equals( |
134 | | - xrRay4.direction, directionNorm2, |
| 148 | + xrRay.direction, directionNorm2, |
135 | 149 | FLOAT_EPSILON, "direction-custom-rigid:"); |
136 | 150 |
|
137 | 151 | assert_matrix_approx_equals( |
138 | | - xrRay4.matrix, matrix2, |
| 152 | + xrRay.matrix, matrix2, |
139 | 153 | FLOAT_EPSILON, "matrix-custom-rigid:"); |
140 | 154 | } |
141 | 155 | }; |
|
0 commit comments