enumPoint {
N, NE, E, SE, S, SW, W, NW;
static Point parse(double x) {
inti= (int) ((x / 45) + .5);
return values()[i % 8];
}
}
Stringy= Point.parse(x).name();
Note, add 0.5 since North also accounts for x > 337.5.
type
TDir = (N, NE, E, SE, S, SW, W, NW);
const
Dirs: array[TDir] of string = ('North','North East','East','South East','South','South West','West','North West');
var
y: double;
x: string;
begin
...
y := Dirs[TDir(Round(((x-22.5)/45) + 0.5) mod 8)]);
end.
N: -22.5 to +22.5 NE: 22.5 to 67.5 E: 67.5 to 112.5 SE: 112.5 to 157.5 S: 157.5 to 202.5 SW: 202.5 to 247.5 W: 247.5 to 292.5 NW: 292.5 to 337.5
enum Point {
N, NE, E, SE, S, SW, W, NW;
static Point parse(double x) {
int i = (int) ((x / 45) + .5);
return values()[i % 8];
}
}
String y = Point.parse(x).name();
type
TDir = (N, NE, E, SE, S, SW, W, NW);
const
Dirs: array[TDir] of string = ('North','North East','East','South East','South','South West','West','North West');
var
y: double;
x: string;
begin
...
y := Dirs[TDir(Round(((x-22.5)/45) + 0.5) mod 8)]);
end.