DiscreteRotation.Companion


public static class DiscreteRotation.Companion


Summary

Public methods

static final @NonNull DiscreteRotation
from(int degrees)

Creates a DiscreteRotation from the given integer degrees.

static final @NonNull DiscreteRotation
fromSurfaceRotation(int surfaceRotation)

Creates a DiscreteRotation from a Surface rotation constant.

static final @NonNull DiscreteRotation
round(float degrees)

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

static final @NonNull DiscreteRotation
round(int degrees)

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

Public methods

from

Added in 1.7.0-alpha03
public static final @NonNull DiscreteRotation from(int degrees)

Creates a DiscreteRotation from the given integer degrees.

Parameters
int degrees

The rotation in degrees. Must be one of 0, 90, 180, or 270.

Returns
@NonNull 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
public static final @NonNull DiscreteRotation fromSurfaceRotation(int surfaceRotation)

Creates a DiscreteRotation from a Surface rotation constant.

Rotation values are relative to the device's natural orientation, Surface.ROTATION_0.

Parameters
int surfaceRotation

A Surface rotation value. Must be one of the SurfaceRotation constants (e.g., Surface.ROTATION_90).

Returns
@NonNull DiscreteRotation

The corresponding DiscreteRotation.

Throws
IllegalArgumentException

If the provided surfaceRotation is not valid.

round

Added in 1.7.0-alpha03
public static final @NonNull DiscreteRotation round(float degrees)

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
float degrees

The rotation in degrees to round.

Returns
@NonNull DiscreteRotation

The rounded DiscreteRotation.

round

Added in 1.7.0-alpha03
public static final @NonNull DiscreteRotation round(int degrees)

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
int degrees

The rotation in degrees to round.

Returns
@NonNull DiscreteRotation

The rounded DiscreteRotation.