Skip to content

Commit 117fa85

Browse files
committed
LaTeX output: let Rust decide the number of digits
1 parent a9cbcd2 commit 117fa85

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

‎src/lib.rs‎

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,17 +1698,17 @@ impl<'a, D> LaTeX<'a, D> {
16981698
n += 1;
16991699
if new_path {
17001700
writeln!(f, "\\pgfpathmoveto{{\\pgfpointxy\
1701-
{{{:.16}}}{{{:.16}}}}}", x, y)?
1701+
{{{x}}}{{{y}}}}}")?
17021702
} else if n >= self.n {
17031703
write!(f, "\\pgfpathlineto{{\\pgfpointxy\
1704-
{{{:.16}}}{{{:.16}}}}}\n\
1704+
{{{x}}}{{{y}}}}}\n\
17051705
\\pgfusepath{{stroke}}\n\
17061706
\\pgfpathmoveto{{\\pgfpointxy\
1707-
{{{:.16}}}{{{:.16}}}}}\n", x, y, x, y)?;
1707+
{{{x}}}{{{y}}}}}\n")?;
17081708
n = 0;
17091709
} else {
17101710
writeln!(f, "\\pgfpathlineto{{\\pgfpointxy\
1711-
{{{:.16}}}{{{:.16}}}}}", x, y)?
1711+
{{{x}}}{{{y}}}}}")?
17121712
}
17131713
new_path = false;
17141714
}
@@ -1758,50 +1758,48 @@ impl<'a, D> LaTeX<'a, D> {
17581758
// extremely expensive. Just draw the current segment.
17591759
let pct = rem_len / l;
17601760
if pct <= 1e-14 {
1761-
write!(f, "\\pgfsetarrowsstart{{{}}}\n\
1761+
write!(f, "\\pgfsetarrowsstart{{{arrow}}}\n\
17621762
\\pgfpathmoveto{{\\pgfpointxy
1763-
{{{:.16}}}{{{:.16}}}}}\n\
1763+
{{{x0}}}{{{y0}}}}}\n\
17641764
\\pgfpathlineto{{\\pgfpointxy\
1765-
{{{:.16}}}{{{:.16}}}}}\n\
1765+
{{{x}}}{{{y}}}}}\n\
17661766
\\pgfusepath{{stroke}}\n\
17671767
\\pgfsetarrowsend{{}}\n\
17681768
\\pgfpathmoveto{{\\pgfpointxy\
1769-
{{{:.16}}}{{{:.16}}}}}\n",
1770-
arrow, x0, y0, x, y, x, y)?;
1769+
{{{x}}}{{{y}}}}}\n")?;
17711770
} else {
17721771
let xm = x0 + pct * dx;
17731772
let ym = y0 + pct * dy;
1774-
write!(f, "\\pgfsetarrowsend{{{}}}\n\
1773+
write!(f, "\\pgfsetarrowsend{{{arrow}}}\n\
17751774
\\pgfpathmoveto{{\\pgfpointxy\
1776-
{{{:.16}}}{{{:.16}}}}}\n\
1775+
{{{x0}}}{{{y0}}}}}\n\
17771776
\\pgfpathlineto{{\\pgfpointxy\
1778-
{{{:.16}}}{{{:.16}}}}}\n\
1777+
{{{xm}}}{{{ym}}}}}\n\
17791778
\\pgfusepath{{stroke}}\n\
17801779
\\pgfsetarrowsend{{}}\n\
17811780
\\pgfpathmoveto{{\\pgfpointxy\
1782-
{{{:.16}}}{{{:.16}}}}}\n\
1781+
{{{xm}}}{{{ym}}}}}\n\
17831782
\\pgfpathlineto{{\\pgfpointxy\
1784-
{{{:.16}}}{{{:.16}}}}}\n",
1785-
arrow, x0, y0, xm, ym, xm, ym, x, y)?;
1783+
{{{x}}}{{{y}}}}}\n")?;
17861784
n = 2;
17871785
}
17881786
rem_len = f64::INFINITY; // No more arrow for this sub-path
17891787
} else if n >= self.n {
17901788
write!(f, "\\pgfpathlineto{{\\pgfpointxy\
1791-
{{{:.16}}}{{{:.16}}}}}\n\
1789+
{{{x}}}{{{y}}}}}\n\
17921790
\\pgfusepath{{stroke}}\n\
17931791
\\pgfpathmoveto{{\\pgfpointxy\
1794-
{{{:.16}}}{{{:.16}}}}}\n", x, y, x, y)?;
1792+
{{{x}}}{{{y}}}}}\n")?;
17951793
n = 0;
17961794
} else {
17971795
writeln!(f, "\\pgfpathlineto{{\\pgfpointxy\
1798-
{{{:.16}}}{{{:.16}}}}}", x, y)?
1796+
{{{x}}}{{{y}}}}}")?
17991797
}
18001798
rem_len -= l;
18011799
} else {
18021800
// No previous point. New sub-path.
18031801
writeln!(f, "\\pgfpathmoveto{{\\pgfpointxy\
1804-
{{{:.16}}}{{{:.16}}}}}", x, y)?
1802+
{{{x}}}{{{y}}}}}")?
18051803
}
18061804
prev_pt = Some(p);
18071805
}
@@ -1815,9 +1813,8 @@ impl<'a, D> LaTeX<'a, D> {
18151813
writeln!(f, "\\begin{{pgfscope}}")?;
18161814
if let Some(RGB8 {r, g, b}) = self.color {
18171815
write!(f, "\\definecolor{{RustCurveSamplingColor}}{{RGB}}\
1818-
{{{},{},{}}}\n\
1819-
\\pgfsetstrokecolor{{RustCurveSamplingColor}}\n",
1820-
r, g, b)?
1816+
{{{r},{g},{b}}}\n\
1817+
\\pgfsetstrokecolor{{RustCurveSamplingColor}}\n")?
18211818
}
18221819
match (self.arrow, self.arrow_pos) {
18231820
(None, None) => self.write_with_lines(f)?,
@@ -1846,7 +1843,7 @@ impl<D> Sampling<D> {
18461843
if x.is_nan() {
18471844
writeln!(f)?
18481845
} else {
1849-
writeln!(f, "{:e} {:e}", x, y)?
1846+
writeln!(f, "{x:e} {y:e}")?
18501847
}
18511848
}
18521849
Ok(())
@@ -1863,7 +1860,7 @@ impl<D> Display for Sampling<D> {
18631860
if x.is_nan() {
18641861
writeln!(f)?
18651862
} else {
1866-
writeln!(f, "{:e} {:e}", x, y)?
1863+
writeln!(f, "{x:e} {y:e}")?
18671864
}
18681865
}
18691866
Ok(())
@@ -2207,7 +2204,7 @@ mod tests {
22072204
write!(fh, "set terminal pdfcairo\n\
22082205
set output \"horror.pdf\"\n\
22092206
set grid\n\
2210-
{}\n", s)?;
2207+
{s}\n")?;
22112208
Ok(())
22122209
}
22132210

0 commit comments

Comments
 (0)