# DiscreteRotation

Artifact: [androidx.camera:camera-common](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/common/DiscreteRotation.kt+class:androidx.camera.common.DiscreteRotation) Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

*** ** * ** ***


```
value public final class DiscreteRotation
```

<br />

*** ** * ** ***

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

| ### Nested types |
|---|
| `public static class https://developer.android.com/reference/androidx/camera/common/DiscreteRotation.Companion` |

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#from(kotlin.Int)(int degrees)` Creates a `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` from the given integer `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation.Companion#from(kotlin.Int)`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#fromSurfaceRotation(kotlin.Int)(int surfaceRotation)` Creates a `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` from a `https://developer.android.com/reference/android/view/Surface.html` rotation constant. |
| `final int` | `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#getDegrees()()` The rotation value in degrees. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#minus(kotlin.Int)(int degrees)` Subtracts the specified number of `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#minus(kotlin.Int)` from this rotation. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#minus(androidx.camera.common.DiscreteRotation)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation other)` Subtracts another `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` from this rotation. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#plus(kotlin.Int)(int degrees)` Adds the specified number of `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#plus(kotlin.Int)` to this rotation. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#plus(androidx.camera.common.DiscreteRotation)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation other)` Adds another `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` to this rotation. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#round(kotlin.Float)(float degrees)` Rounds `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation.Companion#round(kotlin.Float)` to the nearest `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` (0, 90, 180, or 270). |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#round(kotlin.Int)(int degrees)` Rounds `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation.Companion#round(kotlin.Int)` to the nearest `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` (0, 90, 180, or 270). |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#toString()()` |

## Public methods

### from

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public static final @NonNull DiscreteRotation from(int degrees)
```

Creates a `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` from the given integer `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation.Companion#from(kotlin.Int)`.

| Parameters |
|---|---|
| `int degrees` | The rotation in degrees. Must be one of 0, 90, 180, or 270. Value is one of the following: - `0` - `90` - `180` - `270` <br /> |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | A `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` representing the specified degrees. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation.Companion#from(kotlin.Int)` is not a valid discrete rotation (0, 90, 180, or 270). |

### fromSurfaceRotation

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public static final @NonNull DiscreteRotation fromSurfaceRotation(int surfaceRotation)
```

Creates a `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` from a `https://developer.android.com/reference/android/view/Surface.html` rotation constant.

Rotation values are relative to the device's natural orientation, `https://developer.android.com/reference/android/view/Surface.html#ROTATION_0`.

| Parameters |
|---|---|
| `int surfaceRotation` | A `https://developer.android.com/reference/android/view/Surface.html` rotation value. Must be one of the `https://developer.android.com/reference/androidx/camera/common/SurfaceRotation` constants (e.g., `https://developer.android.com/reference/android/view/Surface.html#ROTATION_90`). Value is one of the following: - `0` - `1` - `2` - `3` <br /> |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | The corresponding `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If the provided `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation.Companion#fromSurfaceRotation(kotlin.Int)` is not valid. |

### getDegrees

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public final int getDegrees()
```

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

Value is one of the following:

- `0`
- `90`
- `180`
- `270`

<br />

### minus

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public final @NonNull DiscreteRotation minus(int degrees)
```

Subtracts the specified number of `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#minus(kotlin.Int)` from this rotation.

The result is normalized to the range `[0, 360)` degrees.

| Parameters |
|---|---|
| `int degrees` | The degrees to subtract. Must be a valid discrete rotation (0, 90, 180, or 270). Value is one of the following: - `0` - `90` - `180` - `270` <br /> |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | The resulting `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#minus(kotlin.Int)` is not a valid discrete rotation (0, 90, 180, or 270). |

### minus

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public final @NonNull DiscreteRotation minus(@NonNull DiscreteRotation other)
```

Subtracts another `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` from this rotation.

The result is normalized to the range `[0, 360)` degrees.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation other` | The `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` to subtract. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | The resulting `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation`. |

### plus

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public final @NonNull DiscreteRotation plus(int degrees)
```

Adds the specified number of `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#plus(kotlin.Int)` to this rotation.

The result is normalized to the range `[0, 360)` degrees.

| Parameters |
|---|---|
| `int degrees` | The degrees to add. Must be a valid discrete rotation (0, 90, 180, or 270). Value is one of the following: - `0` - `90` - `180` - `270` <br /> |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | The resulting `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation#plus(kotlin.Int)` is not a valid discrete rotation (0, 90, 180, or 270). |

### plus

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public final @NonNull DiscreteRotation plus(@NonNull DiscreteRotation other)
```

Adds another `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` to this rotation.

The result is normalized to the range `[0, 360)` degrees.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation other` | The `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` to add. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | The resulting `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation`. |

### round

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public static final @NonNull DiscreteRotation round(float degrees)
```

Rounds `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation.Companion#round(kotlin.Float)` to the nearest `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` (0, 90, 180, or 270).

Negative values are normalized and rounded to the nearest positive `https://developer.android.com/reference/androidx/camera/common/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | The rounded `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation`. |

### round

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public static final @NonNull DiscreteRotation round(int degrees)
```

Rounds `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation.Companion#round(kotlin.Int)` to the nearest `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` (0, 90, 180, or 270).

Negative values are normalized and rounded to the nearest positive `https://developer.android.com/reference/androidx/camera/common/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DiscreteRotation` | The rounded `https://developer.android.com/reference/androidx/camera/common/DiscreteRotation`. |

### toString

```
public @NonNull String toString()
```