1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.xr.runtime.math
18 
19 /**
20  * Represents a ray in 3D space. A ray is defined by an origin point and a direction vector.
21  *
22  * @property origin the origin of the ray.
23  * @property direction the direction of the ray.
24  */
25 public class Ray(
26     public val origin: Vector3 = Vector3(),
27     public val direction: Vector3 = Vector3(),
28 ) {
29     /** Creates a new Ray with the same values as the [other] ray. */
30     public constructor(other: Ray) : this(other.origin, other.direction)
31 
32     /** Returns true if this ray is equal to the [other] ray. */
equalsnull33     override fun equals(other: Any?): Boolean {
34         if (this === other) return true
35         if (other !is Ray) return false
36 
37         return this.origin == other.origin && this.direction == other.direction
38     }
39 
hashCodenull40     override fun hashCode(): Int = 31 * origin.hashCode() + direction.hashCode()
41 
42     override fun toString(): String = "[origin=$origin, direction=$direction]"
43 }
44