Mercurial > hg > octave-lojdl
changeset 14258:08779abcb640
maint: Style fixes for 5cc69bafe3b9
graphics.cc: Use Octave spacing conventions for functions versus indexing.
Use std::string instead of caseless_str where possible.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 24 Jan 2012 08:53:42 -0800 |
parents | 5cc69bafe3b9 |
children | 1f911333ed3d |
files | src/graphics.cc |
diffstat | 1 files changed, 92 insertions(+), 110 deletions(-) [+] |
line wrap: on
line diff
--- a/src/graphics.cc +++ b/src/graphics.cc @@ -3464,13 +3464,13 @@ { Matrix pos = get_paperposition ().matrix_value (); Matrix sz = get_papersize ().matrix_value (); - caseless_str porient = get_paperorientation (); - - pos (0) = pos (0) / sz(0); - pos (1) = pos (1) / sz(1); - pos (2) = pos (2) / sz(0); - pos (3) = pos (3) / sz(1); - + + pos(0) /= sz(0); + pos(1) /= sz(1); + pos(2) /= sz(0); + pos(3) /= sz(1); + + std::string porient = get_paperorientation (); caseless_str punits = get_paperunits (); caseless_str typ = get_papertype (); @@ -3478,41 +3478,37 @@ { if (old_paperunits.compare ("centimeters")) { - sz (0) = sz (0) / 2.54; - sz (1) = sz (1) / 2.54; + sz(0) /= 2.54; + sz(1) /= 2.54; } else if (old_paperunits.compare ("points")) { - sz (0) = sz (0) / 72.0; - sz (1) = sz (1) / 72.0; + sz(0) /= 72.0; + sz(1) /= 72.0; } if (punits.compare ("centimeters")) { - sz(0) = sz(0) * 2.54; - sz(1) = sz(1) * 2.54; - } - else if (old_paperunits.compare ("points")) - { - sz (0) = sz (0) * 72.0; - sz (1) = sz (1) * 72.0; + sz(0) *= 2.54; + sz(1) *= 2.54; + } + else if (punits.compare ("points")) + { + sz(0) *= 72.0; + sz(1) *= 72.0; } } else { sz = papersize_from_type (punits, typ); - if (porient.compare ("landscape")) - { - double tmp = sz (0); - sz (0) = sz (1); - sz (1) = tmp; - } - } - - pos (0) = pos (0) * sz(0); - pos (1) = pos (1) * sz(1); - pos (2) = pos (2) * sz(0); - pos (3) = pos (3) * sz(1); + if (porient == "landscape") + std::swap (sz(0), sz(1)); + } + + pos(0) *= sz(0); + pos(1) *= sz(1); + pos(2) *= sz(0); + pos(3) *= sz(1); papersize.set (octave_value (sz)); paperposition.set (octave_value (pos)); @@ -3525,15 +3521,10 @@ if (! typ.compare ("<custom>")) { Matrix sz = papersize_from_type (get_paperunits (), typ); - caseless_str porient = get_paperorientation (); - if (porient.compare ("landscape")) - { - double tmp = sz (0); - sz (0) = sz (1); - sz (1) = tmp; - } - // Call papersize.set rather than set_papersize to avoid loops between - // update_papersize and update_papertype + if (get_paperorientation () == "landscape") + std::swap (sz(0), sz(1)); + // Call papersize.set rather than set_papersize to avoid loops + // between update_papersize and update_papertype papersize.set (octave_value (sz)); } } @@ -3542,93 +3533,90 @@ figure::properties::update_papersize (void) { Matrix sz = get_papersize ().matrix_value (); - if (sz (0) > sz (1)) - { - double tmp = sz (0); - sz (0) = sz (1); - sz (1) = tmp; + if (sz(0) > sz(1)) + { + std::swap (sz(0), sz(1)); papersize.set (octave_value (sz)); - caseless_str porient = "landscape"; - paperorientation.set (octave_value (porient)); + paperorientation.set (octave_value ("landscape")); } else { - caseless_str porient = "portrait"; - paperorientation.set (octave_value (porient)); - } - caseless_str punits = get_paperunits (); - if (punits.compare ("centimeters")) - { - sz (0) = sz (0) / 2.54; - sz (1) = sz (1) / 2.54; - } - else if (punits.compare ("points")) - { - sz (0) = sz (0) / 72.0; - sz (1) = sz (1) / 72.0; - } - if (punits.compare ("normalized")) + paperorientation.set ("portrait"); + } + std::string punits = get_paperunits (); + if (punits == "centimeters") + { + sz(0) /= 2.54; + sz(1) /= 2.54; + } + else if (punits == "points") + { + sz(0) = 72.0; + sz(1) = 72.0; + } + if (punits == "normalized") { caseless_str typ = get_papertype (); - if (typ.compare ("<custom>")) + if (get_papertype () == "<custom>") error ("set: can't set the papertype to <custom> when the paperunits is normalized"); } else { - // TODO - the papersizes info is also in papersize_from_type(). Both should be - // rewritten to avoid the duplication. - caseless_str typ = "<custom>"; - double mm2in = 1.0 / 25.4; - double tol = 0.01; - if (std::abs (sz (0) - 8.5) + std::abs (sz (1) - 11.0) < tol) + // TODO - the papersizes info is also in papersize_from_type(). + // Both should be rewritten to avoid the duplication. + std::string typ = "<custom>"; + const double mm2in = 1.0 / 25.4; + const double tol = 0.01; + + if (std::abs (sz(0) - 8.5) + std::abs (sz(1) - 11.0) < tol) typ = "usletter"; - else if (std::abs (sz (0) - 8.5) + std::abs (sz (1) - 14.0) < tol) + else if (std::abs (sz(0) - 8.5) + std::abs (sz(1) - 14.0) < tol) typ = "uslegal"; - else if (std::abs (sz (0) - 11.0) + std::abs (sz (1) - 17.0) < tol) + else if (std::abs (sz(0) - 11.0) + std::abs (sz(1) - 17.0) < tol) typ = "tabloid"; - else if (std::abs (sz (0) - 841.0 * mm2in) + std::abs (sz (1) - 1198.0 * mm2in) < tol) + else if (std::abs (sz(0) - 841.0 * mm2in) + std::abs (sz(1) - 1198.0 * mm2in) < tol) typ = "a0"; - else if (std::abs (sz (0) - 594.0 * mm2in) + std::abs (sz (1) - 841.0 * mm2in) < tol) + else if (std::abs (sz(0) - 594.0 * mm2in) + std::abs (sz(1) - 841.0 * mm2in) < tol) typ = "a1"; - else if (std::abs (sz (0) - 420.0 * mm2in) + std::abs (sz (1) - 594.0 * mm2in) < tol) + else if (std::abs (sz(0) - 420.0 * mm2in) + std::abs (sz(1) - 594.0 * mm2in) < tol) typ = "a2"; - else if (std::abs (sz (0) - 297.0 * mm2in) + std::abs (sz (1) - 420.0 * mm2in) < tol) + else if (std::abs (sz(0) - 297.0 * mm2in) + std::abs (sz(1) - 420.0 * mm2in) < tol) typ = "a3"; - else if (std::abs (sz (0) - 210.0 * mm2in) + std::abs (sz (1) - 297.0 * mm2in) < tol) + else if (std::abs (sz(0) - 210.0 * mm2in) + std::abs (sz(1) - 297.0 * mm2in) < tol) typ = "a4"; - else if (std::abs (sz (0) - 148.0 * mm2in) + std::abs (sz (1) - 210.0 * mm2in) < tol) + else if (std::abs (sz(0) - 148.0 * mm2in) + std::abs (sz(1) - 210.0 * mm2in) < tol) typ = "a5"; - else if (std::abs (sz (0) - 1029.0 * mm2in) + std::abs (sz (1) - 1456.0 * mm2in) < tol) + else if (std::abs (sz(0) - 1029.0 * mm2in) + std::abs (sz(1) - 1456.0 * mm2in) < tol) typ = "b0"; - else if (std::abs (sz (0) - 728.0 * mm2in) + std::abs (sz (1) - 1028.0 * mm2in) < tol) + else if (std::abs (sz(0) - 728.0 * mm2in) + std::abs (sz(1) - 1028.0 * mm2in) < tol) typ = "b1"; - else if (std::abs (sz (0) - 514.0 * mm2in) + std::abs (sz (1) - 728.0 * mm2in) < tol) + else if (std::abs (sz(0) - 514.0 * mm2in) + std::abs (sz(1) - 728.0 * mm2in) < tol) typ = "b2"; - else if (std::abs (sz (0) - 364.0 * mm2in) + std::abs (sz (1) - 514.0 * mm2in) < tol) + else if (std::abs (sz(0) - 364.0 * mm2in) + std::abs (sz(1) - 514.0 * mm2in) < tol) typ = "b3"; - else if (std::abs (sz (0) - 257.0 * mm2in) + std::abs (sz (1) - 364.0 * mm2in) < tol) + else if (std::abs (sz(0) - 257.0 * mm2in) + std::abs (sz(1) - 364.0 * mm2in) < tol) typ = "b4"; - else if (std::abs (sz (0) - 182.0 * mm2in) + std::abs (sz (1) - 257.0 * mm2in) < tol) + else if (std::abs (sz(0) - 182.0 * mm2in) + std::abs (sz(1) - 257.0 * mm2in) < tol) typ = "b5"; - else if (std::abs (sz (0) - 9.0) + std::abs (sz (1) - 12.0) < tol) + else if (std::abs (sz(0) - 9.0) + std::abs (sz(1) - 12.0) < tol) typ = "arch-a"; - else if (std::abs (sz (0) - 12.0) + std::abs (sz (1) - 18.0) < tol) + else if (std::abs (sz(0) - 12.0) + std::abs (sz(1) - 18.0) < tol) typ = "arch-b"; - else if (std::abs (sz (0) - 18.0) + std::abs (sz (1) - 24.0) < tol) + else if (std::abs (sz(0) - 18.0) + std::abs (sz(1) - 24.0) < tol) typ = "arch-c"; - else if (std::abs (sz (0) - 24.0) + std::abs (sz (1) - 36.0) < tol) + else if (std::abs (sz(0) - 24.0) + std::abs (sz(1) - 36.0) < tol) typ = "arch-d"; - else if (std::abs (sz (0) - 36.0) + std::abs (sz (1) - 48.0) < tol) + else if (std::abs (sz(0) - 36.0) + std::abs (sz(1) - 48.0) < tol) typ = "arch-e"; - else if (std::abs (sz (0) - 8.5) + std::abs (sz (1) - 11.0) < tol) + else if (std::abs (sz(0) - 8.5) + std::abs (sz(1) - 11.0) < tol) typ = "a"; - else if (std::abs (sz (0) - 11.0) + std::abs (sz (1) - 17.0) < tol) + else if (std::abs (sz(0) - 11.0) + std::abs (sz(1) - 17.0) < tol) typ = "b"; - else if (std::abs (sz (0) - 17.0) + std::abs (sz (1) - 22.0) < tol) + else if (std::abs (sz(0) - 17.0) + std::abs (sz(1) - 22.0) < tol) typ = "c"; - else if (std::abs (sz (0) - 22.0) + std::abs (sz (1) - 34.0) < tol) + else if (std::abs (sz(0) - 22.0) + std::abs (sz(1) - 34.0) < tol) typ = "d"; - else if (std::abs (sz (0) - 34.0) + std::abs (sz (1) - 43.0) < tol) + else if (std::abs (sz(0) - 34.0) + std::abs (sz(1) - 43.0) < tol) typ = "e"; // Call papertype.set rather than set_papertype to avoid loops between // update_papersize and update_papertype @@ -3639,23 +3627,17 @@ void figure::properties::update_paperorientation (void) { - caseless_str porient = get_paperorientation (); + std::string porient = get_paperorientation (); Matrix sz = get_papersize ().matrix_value (); Matrix pos = get_paperposition ().matrix_value (); - if ((sz (0) > sz (1) && porient.compare ("portrait")) - || (sz (0) < sz (1) && porient.compare ("landscape"))) - { - double tmp = sz (0); - sz (0) = sz (1); - sz (1) = tmp; - tmp = pos (0); - pos (0) = pos (1); - pos (1) = tmp; - tmp = pos (2); - pos (2) = pos (3); - pos (3) = tmp; - // Call papertype.set rather than set_papertype to avoid loops between - // update_papersize and update_papertype + if ((sz(0) > sz(1) && porient == "portrait") + || (sz(0) < sz(1) && porient == "landscape")) + { + std::swap (sz(0), sz(1)); + std::swap (pos(0), pos(1)); + std::swap (pos(2), pos(3)); + // Call papertype.set rather than set_papertype to avoid loops + // between update_papersize and update_papertype papersize.set (octave_value (sz)); paperposition.set (octave_value (pos)); } @@ -3665,11 +3647,11 @@ %!test %! figure (1, "visible", false); %! tol = 100 * eps (); -%! set (gcf (), "paperorientation", "portrait") +%! set (gcf (), "paperorientation", "PORTRAIT") %! set (gcf (), "paperunits", "inches") -%! set (gcf (), "papertype", "usletter") +%! set (gcf (), "papertype", "USletter") %! assert (get (gcf (), "papersize"), [8.5, 11.0], tol) -%! set (gcf (), "paperorientation", "landscape") +%! set (gcf (), "paperorientation", "Landscape") %! assert (get (gcf (), "papersize"), [11.0, 8.5], tol) %! set (gcf (), "paperunits", "centimeters") %! assert (get (gcf (), "papersize"), [11.0, 8.5] * 2.54, tol)