51 lines
1.5 KiB
Dart
51 lines
1.5 KiB
Dart
enum AngleUnit {
|
|
degrees, // 0° - 360°
|
|
mils, // 0 - 6400 NATO Mils (₥)
|
|
dual, // Both: 045° (0800 ₥)
|
|
}
|
|
|
|
extension AngleUnitExtension on AngleUnit {
|
|
String formatHeading(double deg, {bool includeLabel = false}) {
|
|
return AngleFormatter.format(deg, this, includeLabel: includeLabel);
|
|
}
|
|
}
|
|
|
|
class AngleFormatter {
|
|
static const double degToMilsNato = 17.7777777778; // 6400 mils / 360 deg
|
|
|
|
static double toMils(double deg) {
|
|
return (deg * degToMilsNato) % 6400;
|
|
}
|
|
|
|
static double fromMils(double mils) {
|
|
return (mils / degToMilsNato) % 360;
|
|
}
|
|
|
|
static String format(double deg, AngleUnit unit, {bool includeLabel = true}) {
|
|
final cleanDeg = (deg % 360 + 360) % 360;
|
|
final milsVal = (cleanDeg * degToMilsNato).round() % 6400;
|
|
final degStr = '${cleanDeg.toStringAsFixed(1)}°';
|
|
final milsStr = '${milsVal.toString().padLeft(4, '0')} ₥';
|
|
|
|
switch (unit) {
|
|
case AngleUnit.degrees:
|
|
return includeLabel ? 'الاتجاه: $degStr' : degStr;
|
|
case AngleUnit.mils:
|
|
return includeLabel ? 'الاتجاه: $milsStr' : milsStr;
|
|
case AngleUnit.dual:
|
|
return includeLabel ? 'الاتجاه: $degStr ($milsStr)' : '$degStr ($milsStr)';
|
|
}
|
|
}
|
|
|
|
static String unitLabel(AngleUnit unit) {
|
|
switch (unit) {
|
|
case AngleUnit.degrees:
|
|
return 'الدرجات (Degrees °)';
|
|
case AngleUnit.mils:
|
|
return 'الميل العسكري (NATO Mils ₥)';
|
|
case AngleUnit.dual:
|
|
return 'عرض مزدوج (درجات + ميل)';
|
|
}
|
|
}
|
|
}
|