DiscreteRotationMath


object DiscreteRotationMath


Utility functions for working with discrete rotations values 0, 90, 180, 270.

Summary

Public functions

Int
fromSurfaceRotation(surfaceRotation: Int)

Get a DiscreteRotation from Surface rotation values.

Unit

Throws an IllegalArgumentException if the given degrees is not one of 0, 90, 180, 270.

Int
round(degrees: Float)

Round degrees to the nearest discrete rotation (0, 90, 180, 270).

Int
round(degrees: Int)

Round degrees to the nearest discrete rotation (0, 90, 180, 270).

Public functions

fromSurfaceRotation

Added in 1.7.0-alpha02
fun fromSurfaceRotation(surfaceRotation: Int): Int

Get a DiscreteRotation from Surface rotation values.

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

requireDiscreteRotation

Added in 1.7.0-alpha02
fun requireDiscreteRotation(degrees: Int): Unit

Throws an IllegalArgumentException if the given degrees is not one of 0, 90, 180, 270.

round

Added in 1.7.0-alpha02
fun round(degrees: Float): Int

Round degrees to the nearest discrete rotation (0, 90, 180, 270).

Negative values are rounded to the nearest positive discrete rotation value (e.g. -90.0f rounds to 270). Boundary values (e.g. 45.0f) are rounded up to the nearest 90-degree increment (e.g. 45.0f rounds to 90).

Example(s):

  • 40.000f => 0°

  • 44.990f => 0°

  • 45.000f => 90°

  • -40.00f => 0° (Equivalent to -40.000f + 360 => round(320.0f) => 0)

  • -50.00f => 270° (Equivalent to -50.000f + 360 => round(310.0f) => 270)

  • -90.00f => 270° (Equivalent to -90.000f + 360 => round(270.0f) => 270)

round

Added in 1.7.0-alpha02
fun round(degrees: Int): Int

Round degrees to the nearest discrete rotation (0, 90, 180, 270).

Negative values are rounded to the nearest positive discrete rotation value (e.g. -90 rounds to 270). Boundary values (e.g. 45) are rounded up to the nearest 90-degree increment (e.g. 45 rounds to 90).

Example(s):

  • 40 => 0°

  • 50 => 90°

  • 45 => 90°

  • -40 => 0° (Equivalent to -40 + 360 => round(320) => 0)

  • -50 => 270° (Equivalent to -50 + 360 => round(310) => 270°)

  • -90 => 270° (Equivalent to -90 + 360 => round(270) => 270°)