Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7c89e8a36b6b
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 45e35c54b555
Choose a head ref
  • 5 commits
  • 3 files changed
  • 1 contributor

Commits on Nov 29, 2019

  1. Copy the full SHA
    8dd6853 View commit details
  2. A helper.

    eggrobin committed Nov 29, 2019
    Copy the full SHA
    dfcc48c View commit details
  3. more bugs!

    eggrobin committed Nov 29, 2019
    Copy the full SHA
    e2092ab View commit details
  4. more N

    eggrobin committed Nov 29, 2019
    Copy the full SHA
    0802e14 View commit details
  5. Merge pull request #2381 from eggrobin/grouping-mark

    Grouping mark
    eggrobin authored Nov 29, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    45e35c5 View commit details
Showing with 32 additions and 33 deletions.
  1. +1 −0 ksp_plugin_adapter/differential_slider.cs
  2. +5 −10 ksp_plugin_adapter/map_node_pool.cs
  3. +26 −23 ksp_plugin_adapter/orbit_analyser.cs
1 change: 1 addition & 0 deletions ksp_plugin_adapter/differential_slider.cs
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ public DifferentialSlider(string label,
field_width_ = field_width;
unit_ = unit;
if (formatter == null) {
// TODO(egg): Is this just "N3"?
formatter_ = v => v.ToString("#,0.000", Culture.culture);
} else {
formatter_ = formatter;
15 changes: 5 additions & 10 deletions ksp_plugin_adapter/map_node_pool.cs
Original file line number Diff line number Diff line change
@@ -225,10 +225,8 @@ private KSP.UI.Screens.Mapview.MapNode MakePoolNode() {
double speed = properties.velocity.magnitude;
caption.Header =
$@"{source} {celestial.name} {apsis_name} :\n{
celestial.GetAltitude(position):N0} m".ToString(
Culture.culture);
caption.captionLine2 =
$"{speed:N0} m/s".ToString(Culture.culture);
celestial.GetAltitude(position).FormatN(0)} m";
caption.captionLine2 = $"{speed.FormatN(0)} m/s";
break;
}
case MapObject.ObjectType.AscendingNode:
@@ -240,8 +238,7 @@ private KSP.UI.Screens.Mapview.MapNode MakePoolNode() {
string plane =
properties.reference_frame.ReferencePlaneDescription();
caption.Header = $"{source} {node_name} :\n{plane}";
caption.captionLine2 =
$"{properties.velocity.z:N0} m/s".ToString(Culture.culture);
caption.captionLine2 = $"{properties.velocity.z.FormatN(0)} m/s";
break;
}
case MapObject.ObjectType.ApproachIntersect: {
@@ -250,10 +247,8 @@ private KSP.UI.Screens.Mapview.MapNode MakePoolNode() {
properties.world_position).magnitude;
double speed = properties.velocity.magnitude;
caption.Header =
$@"{source} Target Approach : {separation:N0} m".ToString(
Culture.culture);
caption.captionLine2 =
$"{speed:N0} m/s".ToString(Culture.culture);
$@"{source} Target Approach : {separation.FormatN(0)} m";
caption.captionLine2 = $"{speed.FormatN(0)} m/s";
break;
}
case MapObject.ObjectType.PatchTransition: {
49 changes: 26 additions & 23 deletions ksp_plugin_adapter/orbit_analyser.cs
Original file line number Diff line number Diff line change
@@ -11,15 +11,23 @@ namespace ksp_plugin_adapter {
// Miscellaneous formatting utilities; these are extension methods to make null
// handling easier, thanks to null-coalescing operators.
internal static class Formatters {
// Formats |value| in "N<fractional_digits>" using the Principia culture.
public static string FormatN(this double value, int fractional_digits) {
return value.ToString($"N{fractional_digits}", Culture.culture);
}

public static string FormatN(this int value, int fractional_digits) {
return value.ToString($"N{fractional_digits}", Culture.culture);
}

// Displays an interval as midpoint±half-width.
public static string FormatInterval(this Interval interval) {
double half_width = (interval.max - interval.min) / 2;
double midpoint = interval.min + half_width;
int fractional_digits =
Math.Max(0, 1 - (int)Math.Floor(Math.Log10(half_width)));
string format = $"N{fractional_digits}";
string formatted_midpoint = midpoint.ToString(format, Culture.culture);
string formatted_half_width = half_width.ToString(format, Culture.culture);
string formatted_midpoint = midpoint.FormatN(fractional_digits);
string formatted_half_width = half_width.FormatN(fractional_digits);
return $"{formatted_midpoint}±{formatted_half_width}";
}

@@ -36,9 +44,8 @@ public static string FormatLengthInterval(this Interval interval) {
}
int fractional_digits =
Math.Max(0, 1 - (int)Math.Floor(Math.Log10(half_width)));
string format = $"N{fractional_digits}";
string formatted_midpoint = midpoint.ToString(format, Culture.culture);
string formatted_half_width = half_width.ToString(format, Culture.culture);
string formatted_midpoint = midpoint.FormatN(fractional_digits);
string formatted_half_width = half_width.FormatN(fractional_digits);
return $"{formatted_midpoint}±{formatted_half_width} {unit}";
}

@@ -53,11 +60,9 @@ public static string FormatAngleInterval(this Interval interval) {
const double degree = Math.PI / 180;
int fractional_digits =
Math.Max(0, 1 - (int)Math.Floor(Math.Log10(half_width / degree)));
string format = $"N{fractional_digits}";
string formatted_midpoint =
(midpoint / degree).ToString(format, Culture.culture);
string formatted_midpoint = (midpoint / degree).FormatN(fractional_digits);
string formatted_half_width =
(half_width / degree).ToString(format, Culture.culture);
(half_width / degree).FormatN(fractional_digits);
return $"{formatted_midpoint}°±{formatted_half_width}°";
}

@@ -66,9 +71,9 @@ public static string FormatAngleInterval(this Interval interval) {
public static string FormatEquatorialAngle(this double angle,
CelestialBody primary) {
const double degree = Math.PI / 180;
double degrees = angle / degree;
double kilometres = angle * primary.Radius / 1000;
return $"{degrees:N1}° ({kilometres:N1} km)".ToString(Culture.culture);
string degrees = (angle / degree).FormatN(1);
string kilometres = (angle * primary.Radius / 1000).FormatN(1);
return $"{degrees}° ({kilometres} km)";
}

// Similar to |FormatAngleInterval|, but annotated with the equivalent
@@ -81,8 +86,8 @@ public static string FormatEquatorialAngleInterval(this Interval interval,
}
double half_width_distance = half_width_angle * primary.Radius;
string formatted_distance = half_width_distance > 1000
? $"{half_width_distance / 1000:N1} km"
: $"{half_width_distance:N0} m";
? $"{(half_width_distance / 1000).FormatN(1)} km"
: $"{(half_width_distance).FormatN(0)} m";
return $"{interval.FormatAngleInterval()} ({formatted_distance})";
}

@@ -124,7 +129,7 @@ public static string FormatAngularFrequency(this double radians_per_second) {
double day = GameSettings.KERBIN_TIME ? 6 * 60 * 60 : 24 * 60 * 60;
string day_unit = GameSettings.KERBIN_TIME ? "d6" : "d";
double degrees_per_day = radians_per_second / (degree / day);
return $"{degrees_per_day:N2}°/{day_unit}";
return $"{degrees_per_day.FormatN(2)}°/{day_unit}";
}

// Never omit leading 0s (to make keyboard editing easier) but do not show
@@ -250,14 +255,13 @@ protected override void RenderWindow(int window_id) {
? nodal_revolutions / analysis.recurrence.number_of_revolutions
: 0;
string duration_in_ground_track_cycles = ground_track_cycles > 0
? $" ({ground_track_cycles:N0} ground track cycles)"
? $" ({ground_track_cycles.FormatN(0)} ground track cycles)"
: "";
duration_in_revolutions = $@"{
sidereal_revolutions:N0} sidereal revolutions{"\n"}{
nodal_revolutions:N0} nodal revolutions{
sidereal_revolutions.FormatN(0)} sidereal revolutions{"\n"}{
nodal_revolutions.FormatN(0)} nodal revolutions{
duration_in_ground_track_cycles}{"\n"}{
anomalistic_revolutions:N0} anomalistic revolutions".ToString(
Culture.culture);
anomalistic_revolutions.FormatN(0)} anomalistic revolutions";
} else {
duration_in_revolutions =
"could not determine elements; mission duration may be shorter " +
@@ -355,8 +359,7 @@ private void RenderOrbitRecurrence(OrbitRecurrence? recurrence,
}
LabeledField(
"Subcycle",
$@"{recurrence?.subcycle.ToString("N0", Culture.culture) ??
em_dash} days");
$@"{recurrence?.subcycle.FormatN(0) ?? em_dash} days");
LabeledField(
"Equatorial shift",
recurrence?.equatorial_shift.FormatEquatorialAngle(primary));