Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
char y {"NESW"[int((x / 90.) + .5) % 4]};
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();
int i = (int) ((x / 90.) + .5) % 4;
char y = "NESW".charAt(i);
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.
y = 'NESW'[int((x / 90) + .5) % 4]
y = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][int((x / 45) + 0.5) % 8]
class Compass:
def __init__(self, modulus=360, n=32):
self.args = modulus, n
def get_radii(self, value):
modulus, n = self.args
value /= (theta := modulus / n)
index = int(value + .5) % n
n = index * theta or modulus
d = theta / 2
return index, n - d, n % modulus + d
compass = Compass()
y = compass.get_radii(x)
cardinals = 'NESW'
inter_cardinals = 'NE', 'SE', 'SW', 'NW'
a = []
for index, c in enumerate(cardinals):
p = index - 1
cp = cardinals[p]
cn = cardinals[(index + 1) % 4]
icp = inter_cardinals[p]
icn = inter_cardinals[index]
values = [
icp + 'b' + c,
c + icp,
c + 'b' + cp,
c,
c + 'b' + cn,
c + icn,
icn + 'b' + c,
icn
]
a.extend(values)
array = a[3:] + a[:3]
i = int(x / 11.25 + .5) % 32
y = array[i]
winds = %w(N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW)
wind_count = winds.size
y = winds[ x * wind_count / 360.0 + 0.5 % wind_count ]