AngleRange

public struct AngleRange : Hashable

Represents angle ranges as a circular sector by using an absolute start angle and a relative range angle called extent. They both define a sector on a circle. All angles are in degrees and are clockwise-oriented. By default, the AngleRange represents the entire circle, the value is in the range of [0, 360]. Values will be corrected during construction using normalization for the start angle and clamping for the extent angle, ensuring a valid range for all possible inputs.

  • Start angle, running clockwise, in degrees from north. The value is in the range of [0, 360) degrees.

    Declaration

    Swift

    public let start: Double
  • The angle range extent, running clockwise, in degrees from start. The value is in the range of [0, 360] degrees.

    Declaration

    Swift

    public let extent: Double
  • Constructs an AngleRange from the provided start and extent angles. Corrects values if they exceed the ranges.

    Declaration

    Swift

    public init(start: Double, extent: Double)

    Parameters

    start

    Start angle, running clockwise, in degrees from north. The value will be normalized to [0.0, 360.0).

    extent

    The range’s extent, running clockwise, in degrees from start. The value will be clamped to the range of [0, 360] degrees.

  • Constructs a range covering a full circle.

    Declaration

    Swift

    public init()
  • Constructs an AngleRange from the provided minimum and maximum angles. Corrects values if they exceed the ranges. The angles are always interpreted in clockwise orientation.

    Declaration

    Swift

    public static func fromMinMaxDegreesClockwise(min: Double, max: Double) -> AngleRange

    Parameters

    min

    Angle where to start the circular sector, running clockwise, in degrees from north. The value will be normalized to [0.0, 360.0).

    max

    Angle where the circular sector ends, running clockwise, in degrees from north. The value will be normalized to [0.0, 360.0).

    Return Value

    Created AngleRange from the provided minimum and maximum angles.

  • Constructs an AngleRange from the provided center angle defining the direction and an angular width to extent the range by 50% clockwise and 50% counter-clockwise from its center angle. Corrects values if they exceed the ranges. Example: direction = 90, extent = 10 means the circle sector is pointing east, with an extent of 5 degrees north-wards and 5 degrees south-wards.

    Declaration

    Swift

    public static func fromDirectionDegreesClockwise(center: Double, extent: Double) -> AngleRange

    Parameters

    center

    Start angle, running clockwise, in degrees from north. The value will be normalized to [0.0, 360.0).

    extent

    The range’s extent, running clockwise, in degrees from start. The value will be clamped to the range of [0, 360] degrees.

    Return Value

    Created AngleRange from the provided center angle and the range’s extent.

  • Check if a given angle in degrees, clockwise from north is in range or not.

    Declaration

    Swift

    public func inRange(angleClockwiseInDegreesFromNorth: Double) -> Bool

    Parameters

    angleClockwiseInDegreesFromNorth

    An angle in degrees from north. Will be normalized before testing.

    Return Value

    True, if an angle is in range, false otherwise.

  • Get the angle that is closest to the given one and in range. If the angle to both ends of the range is the same, the value in the clockwise direction is returned. If the given angle is in range already, it will be returned as normalized angle.

    Declaration

    Swift

    public func closestInRange(angleClockwiseInDegreesFromNorth: Double) -> Double

    Parameters

    angleClockwiseInDegreesFromNorth

    An angle in degrees from north. Will be normalized.

    Return Value

    The closest, normalized in-range angle in degrees, clockwise from north. If the given angle is in range already, the given angle will be returned as normalized angle in degree, clockwise from north.

  • Get the maximum angle defined by the range in degrees, clockwise from north, normalized to [0,360).

    Declaration

    Swift

    public func max() -> Double

    Return Value

    Maximum angle of the range in degrees, clockwise from north, normalized to [0,360).