DiscreteRotation
value class DiscreteRotation
A value class representing a rotation constrained to 90-degree increments (0, 90, 180, or 270 degrees).
This class provides utility functions for performing modulo-360 arithmetic on rotations (addition and subtraction), as well as rounding arbitrary rotation values to the nearest 90-degree step.
Summary
Public companion functions |
|
|---|---|
DiscreteRotation |
Creates a |
DiscreteRotation |
fromSurfaceRotation(surfaceRotation: Int)Creates a |
DiscreteRotation |
Rounds |
DiscreteRotation |
Rounds |
Public companion properties |
|
|---|---|
DiscreteRotation |
A |
DiscreteRotation |
A |
DiscreteRotation |
A |
DiscreteRotation |
A |
Public functions |
|
|---|---|
inline operator DiscreteRotation |
Subtracts the specified number of |
inline operator DiscreteRotation |
minus(other: DiscreteRotation)Subtracts another |
inline operator DiscreteRotation |
Adds the specified number of |
inline operator DiscreteRotation |
plus(other: DiscreteRotation)Adds another |
open String |
toString() |
Public companion functions
from
fun from(degrees: Int): DiscreteRotation
Creates a DiscreteRotation from the given integer degrees.
| Parameters | |
|---|---|
degrees: Int |
The rotation in degrees. Must be one of 0, 90, 180, or 270. |
| Returns | |
|---|---|
DiscreteRotation |
A |
| Throws | |
|---|---|
IllegalArgumentException |
If |
fromSurfaceRotation
fun fromSurfaceRotation(surfaceRotation: Int): DiscreteRotation
Creates a DiscreteRotation from a Surface rotation constant.
Rotation values are relative to the device's natural orientation, Surface.ROTATION_0.
| Parameters | |
|---|---|
surfaceRotation: Int |
A |
| Returns | |
|---|---|
DiscreteRotation |
The corresponding |
| Throws | |
|---|---|
IllegalArgumentException |
If the provided |
round
fun round(degrees: Float): DiscreteRotation
Rounds degrees to the nearest DiscreteRotation (0, 90, 180, or 270).
Negative values are normalized and rounded to the nearest positive DiscreteRotation (e.g., -90.0f rounds to 270, and -45.0f rounds to 0). Boundary values (e.g., 45.0f) are rounded up to the nearest 90-degree increment (e.g., 45.0f rounds to 90).
| Parameters | |
|---|---|
degrees: Float |
The rotation in degrees to round. |
| Returns | |
|---|---|
DiscreteRotation |
The rounded |
round
fun round(degrees: Int): DiscreteRotation
Rounds degrees to the nearest DiscreteRotation (0, 90, 180, or 270).
Negative values are normalized and rounded to the nearest positive DiscreteRotation (e.g., -90 rounds to 270, and -45 rounds to 0). Boundary values (e.g., 45) are rounded up to the nearest 90-degree increment (e.g., 45 rounds to 90).
| Parameters | |
|---|---|
degrees: Int |
The rotation in degrees to round. |
| Returns | |
|---|---|
DiscreteRotation |
The rounded |
Public companion properties
Public functions
minus
inline operator fun minus(degrees: Int): DiscreteRotation
Subtracts the specified number of degrees from this rotation.
The result is normalized to the range [0, 360) degrees.
| Parameters | |
|---|---|
degrees: Int |
The degrees to subtract. Must be a valid discrete rotation (0, 90, 180, or 270). |
| Returns | |
|---|---|
DiscreteRotation |
The resulting |
| Throws | |
|---|---|
IllegalArgumentException |
If |
minus
inline operator fun minus(other: DiscreteRotation): DiscreteRotation
Subtracts another DiscreteRotation from this rotation.
The result is normalized to the range [0, 360) degrees.
| Parameters | |
|---|---|
other: DiscreteRotation |
The |
| Returns | |
|---|---|
DiscreteRotation |
The resulting |
plus
inline operator fun plus(degrees: Int): DiscreteRotation
Adds the specified number of degrees to this rotation.
The result is normalized to the range [0, 360) degrees.
| Parameters | |
|---|---|
degrees: Int |
The degrees to add. Must be a valid discrete rotation (0, 90, 180, or 270). |
| Returns | |
|---|---|
DiscreteRotation |
The resulting |
| Throws | |
|---|---|
IllegalArgumentException |
If |
plus
inline operator fun plus(other: DiscreteRotation): DiscreteRotation
Adds another DiscreteRotation to this rotation.
The result is normalized to the range [0, 360) degrees.
| Parameters | |
|---|---|
other: DiscreteRotation |
The |
| Returns | |
|---|---|
DiscreteRotation |
The resulting |
Public properties
degrees
val degrees: Int
The rotation value in degrees. Guaranteed to be one of 0, 90, 180, or 270.