Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions Src/Orbiter/Astro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,20 @@ char *DistStr (double dist, int precision)
if (absd < 1e8) sprintf (strbuf, "% 0.*fM", precision-2, dist*1e-6);
else if (absd < 1e9) sprintf (strbuf, "% 0.*fM", precision-3, dist*1e-6);
else sprintf (strbuf, "% 0.*fG", precision-1, dist*1e-9);
} else if (absd < 1e2*AU) {
} else if (absd < 1e1*AU) {
if (absd < 1e11) sprintf (strbuf, "% 0.*fG", precision-2, dist*1e-9);
else if (absd < 1e12) sprintf (strbuf, "% 0.*fG", precision-3, dist*1e-9);
else sprintf (strbuf, "% 0.*fAU",precision-2, dist*iAU);
else sprintf (strbuf, "% 0.*fAU",precision-1, dist*iAU);
} else if (absd < 1e1*parsec) {
if (absd < 1e2*AU) sprintf (strbuf, "% 0.*fAU", precision-2, dist*iAU);
else if (absd < 1e3*AU) sprintf (strbuf, "% 0.*fAU", precision-3, dist*iAU);
else sprintf (strbuf, "% 0.*fpc", precision-1, dist*iparsec);
} else if (absd < 1e4*parsec) {
if (absd < 1e2*parsec) sprintf (strbuf, "% 0.*fpc", precision-2, dist*iparsec);
else if (absd < 1e3*parsec) sprintf (strbuf, "% 0.*fpc", precision-3, dist*iparsec);
else sprintf (strbuf, "% 0.0fpc", dist*iparsec);
} else {
sprintf (strbuf, "% 0.0fAU", dist*iAU);
//FloatStr (dist*iparsec, precision+1);
//strcat (strbuf, "pc");
sprintf (strbuf, "% 0.3epc", dist*iparsec);
}
return strbuf;
}
Expand Down Expand Up @@ -193,23 +199,15 @@ char *FloatStr (double f, int precision)
return strbuf;
}

char *SciStr (double f, int precision, char prefix)
char *SciStr (double f, int precision)
{
const char *fmtstr[3] = {
"%0.*g", "% 0.*g", "%+0.*g"
};
const char *fstr = fmtstr[0];
if (prefix == ' ') fstr = fmtstr[1];
else if (prefix == '+') fstr = fmtstr[2];

int i, len, e;
sprintf (strbuf, fstr, precision, f);
len = strlen (strbuf);
for (i = 0; i < len; i++) {
if (strbuf[i] == 'e') {
sscanf(strbuf+i+1, "%d", &e);
sprintf (strbuf+i, "·10^%d", e);
}
if (f < 1e4)
{
sprintf (strbuf, "%0.*g", precision, f);
}
else
{
sprintf (strbuf, "%0.*e", precision, f);
}
return strbuf;
}
6 changes: 3 additions & 3 deletions Src/Orbiter/Astro.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ char *FloatStr (double f, int precision = 4);
// Formats floating point value f with given precision, using 'k', 'M' and 'G'
// suffix as required.

char *SciStr (double f, int precision = 4, char prefix = '\0');
// Formats floating point value f with given precision, using "*10^x" suffix
// notation as required
char *SciStr (double f, int precision = 4);
// Formats floating point value f with given precision, using scientific
// notation above 10000

char *DistStr (double d, int precision = 4);
// as FloatStr, but uses 'AU' (astronomical units) instead of 'G'
Expand Down
3 changes: 0 additions & 3 deletions Src/Orbiter/MenuInfoBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,6 @@ class InfoTarget: public ImGuiDialog {
if (g_camera->IsExternal()) {
ImGui::SameLine();
ImGui::TextColored(white, " Dst %s", DistStr (g_camera->Distance())+1);
} else {
ImGui::SameLine();
ImGui::TextColored(ImVec4(0,0,0,0), " Dst %s", DistStr (g_camera->Distance())+1);
}

if(prm.FPS == 1)
Expand Down
Loading