1 /* 2 * Copyright (C) 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.ink.geometry 18 19 import androidx.annotation.RestrictTo 20 21 /** 22 * An immutable triangle, defined by its three corners [p0], [p1] and [p2] in order. This object is 23 * immutable, so it is inherently thread-safe. See [MutableTriangle] for the mutable version. 24 */ 25 public class ImmutableTriangle(p0: Vec, p1: Vec, p2: Vec) : Triangle() { 26 27 @Suppress("Immutable") override val p0: Vec = p0.asImmutable() 28 @Suppress("Immutable") override val p1: Vec = p1.asImmutable() 29 @Suppress("Immutable") override val p2: Vec = p2.asImmutable() 30 asImmutablenull31 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) override fun asImmutable(): ImmutableTriangle = this 32 33 /** 34 * Equality for [ImmutableTriangle] is defined using the order in which [p0], [p1] and [p2] are 35 * defined. Rotated/flipped triangles with out-of-order vertices are not considered equal. 36 */ 37 override fun equals(other: Any?): Boolean = 38 other === this || (other is Triangle && areEquivalent(this, other)) 39 40 // NOMUTANTS -- not testing exact hashCode values, just that equality implies same hashCode. 41 override fun hashCode(): Int = hash(this) 42 43 override fun toString(): String = "Immutable${string(this)}" 44 } 45