# DiscreteRotation.Companion

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.Companion) Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

*** ** * ** ***


```
public static class DiscreteRotation.Companion
```

<br />

*** ** * ** ***

## Summary

| ### 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. |
| `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). |

## 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. |

### 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`. |