Skip to content

Commit df6839c

Browse files
committed
Improve float storage in TSVG compact mode
If value too small, one have to preserve several significant digits. So small values converted with %3.1f or %5.3f format, or just stored as before
1 parent 54aaf25 commit df6839c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

graf2d/postscript/src/TSVG.cxx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,14 +1539,25 @@ void TSVG::Initialize()
15391539
}
15401540

15411541
////////////////////////////////////////////////////////////////////////////////
1542-
/// Write real value into output stream
1543-
/// In compact form only integer value will be written
1542+
/// Write float value into output stream
1543+
/// In compact form try to store only first 2-3 significant digits
15441544

15451545
void TSVG::WriteReal(Float_t r, Bool_t space)
15461546
{
1547-
if (fCompact)
1548-
TVirtualPS::WriteInteger(std::lround(r), space);
1549-
else
1547+
if (fCompact) {
1548+
auto a = std::abs(r);
1549+
if (a > 10)
1550+
TVirtualPS::WriteInteger(std::lround(r), space);
1551+
else if (a < 0.005)
1552+
TVirtualPS::WriteReal(r, space);
1553+
else {
1554+
char str[15];
1555+
snprintf(str, 15, (a > 1) ? "%3.1f" : "%5.3f", r);
1556+
if(space)
1557+
PrintFast(1," ");
1558+
PrintStr(str);
1559+
}
1560+
} else
15501561
TVirtualPS::WriteReal(r, space);
15511562
}
15521563

0 commit comments

Comments
 (0)