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
from(degrees: Int)

Creates a DiscreteRotation from the given integer degrees.

DiscreteRotation
fromSurfaceRotation(surfaceRotation: Int)

Creates a DiscreteRotation from a Surface rotation constant.

DiscreteRotation
round(degrees: Float)

Rounds degrees to the nearest DiscreteRotation (0, 90, 180, or 270).

DiscreteRotation
round(degrees: Int)

Rounds degrees to the nearest DiscreteRotation (0, 90, 180, or 270).

Public functions

inline operator DiscreteRotation
minus(degrees: Int)

Subtracts the specified number of degrees from this rotation.

inline operator DiscreteRotation

Subtracts another DiscreteRotation from this rotation.

inline operator DiscreteRotation
plus(degrees: Int)

Adds the specified number of degrees to this rotation.

inline operator DiscreteRotation

Adds another DiscreteRotation to this rotation.

open String

Public properties

Int

The rotation value in degrees.

Public companion functions

from

Added in 1.7.0-alpha03
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 DiscreteRotation representing the specified degrees.

Throws
IllegalArgumentException

If degrees is not a valid discrete rotation (0, 90, 180, or 270).

fromSurfaceRotation

Added in 1.7.0-alpha03
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 Surface rotation value. Must be one of the SurfaceRotation constants (e.g., Surface.ROTATION_90).

Returns
DiscreteRotation

The corresponding DiscreteRotation.

Throws
IllegalArgumentException

If the provided surfaceRotation is not valid.

round

Added in 1.7.0-alpha03
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 DiscreteRotation.

round

Added in 1.7.0-alpha03
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 DiscreteRotation.

Public companion properties

ROTATION_0

val ROTATION_0DiscreteRotation

A DiscreteRotation of 0 degrees.

ROTATION_180

val ROTATION_180DiscreteRotation

A DiscreteRotation of 180 degrees.

ROTATION_270

val ROTATION_270DiscreteRotation

A DiscreteRotation of 270 degrees.

ROTATION_90

val ROTATION_90DiscreteRotation

A DiscreteRotation of 90 degrees.

Public functions

minus

Added in 1.7.0-alpha03
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 DiscreteRotation.

Throws
IllegalArgumentException

If degrees is not a valid discrete rotation (0, 90, 180, or 270).

minus

Added in 1.7.0-alpha03
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 DiscreteRotation to subtract.

Returns
DiscreteRotation

The resulting DiscreteRotation.

plus

Added in 1.7.0-alpha03
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 DiscreteRotation.

Throws
IllegalArgumentException

If degrees is not a valid discrete rotation (0, 90, 180, or 270).

plus

Added in 1.7.0-alpha03
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 DiscreteRotation to add.

Returns
DiscreteRotation

The resulting DiscreteRotation.

toString

open fun toString(): String

Public properties

degrees

Added in 1.7.0-alpha03
val degreesInt

The rotation value in degrees. Guaranteed to be one of 0, 90, 180, or 270.