AngleRange (API Reference)
Class AngleRange
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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a range covering a full circle.AngleRange(double start, double extent) Constructs an AngleRange from the provided start and extent angles. -
Method Summary
Modifier and TypeMethodDescriptiondoubleclosestInRange(double angleClockwiseInDegreesFromNorth) Get the angle that is closest to the given one and in range.booleanstatic AngleRangefromDirectionDegreesClockwise(double center, double extent) 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.static AngleRangefromMinMaxDegreesClockwise(double min, double max) Constructs an AngleRange from the provided minimum and maximum angles.inthashCode()booleaninRange(double angleClockwiseInDegreesFromNorth) Check if a given angle in degrees, clockwise from north is in range or not.doublemax()Get the maximum angle defined by the range in degrees, clockwise from north, normalized to [0,360).
-
Field Details
-
start
public final double startStart angle, running clockwise, in degrees from north. The value is in the range of [0, 360) degrees.
-
extent
public final double extentThe angle range extent, running clockwise, in degrees from start. The value is in the range of [0, 360] degrees.
-
-
Constructor Details
-
AngleRange
public AngleRange(double start, double extent) Constructs an AngleRange from the provided start and extent angles. Corrects values if they exceed the ranges.
- 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.
-
AngleRange
public AngleRange()Constructs a range covering a full circle.
-
-
Method Details
-
equals
-
hashCode
public int hashCode() -
fromMinMaxDegreesClockwise
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.
- 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).
- Returns:
Created AngleRange from the provided minimum and maximum angles.
-
fromDirectionDegreesClockwise
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.
- 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.
- Returns:
Created AngleRange from the provided center angle and the range's extent.
-
inRange
public boolean inRange(double angleClockwiseInDegreesFromNorth) Check if a given angle in degrees, clockwise from north is in range or not.
- Parameters:
angleClockwiseInDegreesFromNorth-An angle in degrees from north. Will be normalized before testing.
- Returns:
True, if an angle is in range,falseotherwise.
-
closestInRange
public double closestInRange(double angleClockwiseInDegreesFromNorth) 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.
- Parameters:
angleClockwiseInDegreesFromNorth-An angle in degrees from north. Will be normalized.
- Returns:
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.
-
max
public double max()Get the maximum angle defined by the range in degrees, clockwise from north, normalized to [0,360).
- Returns:
Maximum angle of the range in degrees, clockwise from north, normalized to [0,360).
-