lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cast to Real in C++ style throughout (issue 547560044 by address@hid


From: hanwenn
Subject: Re: Cast to Real in C++ style throughout (issue 547560044 by address@hidden)
Date: Sun, 02 Feb 2020 12:00:36 -0800

Reviewers: Dan Eble, dak,


https://codereview.appspot.com/547560044/diff/555240043/lily/spring.cc
File lily/spring.cc (right):

https://codereview.appspot.com/547560044/diff/555240043/lily/spring.cc#newcode119
lily/spring.cc:119: avg_stretch /= static_cast<Real> (springs.size ());
On 2020/02/02 18:51:08, Dan Eble wrote:
> This is not an issue with this change, but should this function do
something
> other than divide by zero when springs is empty?

what is the average of an empty set of numbers?

the 2 callers use a fallback in case there are not springs.

Description:
Cast to Real in C++ style throughout

Please review this at https://codereview.appspot.com/547560044/

Affected files (+23, -20 lines):
  M flower/cpu-timer.cc
  M flower/include/drul-array.hh
  M lily/bracket.cc
  M lily/freetype.cc
  M lily/midi-walker.cc
  M lily/open-type-font.cc
  M lily/pango-font.cc
  M lily/pitch.cc
  M lily/spring.cc
  M lily/stem.cc
  M lily/volta-bracket.cc


Index: flower/cpu-timer.cc
diff --git a/flower/cpu-timer.cc b/flower/cpu-timer.cc
index 
1bf93e30840288fb948cc73cdfe2e60c5cf990cc..f05f30308da7c0ea627d8f6a035ef4f5cb8573e6
 100644
--- a/flower/cpu-timer.cc
+++ b/flower/cpu-timer.cc
@@ -45,5 +45,6 @@ Real
 Cpu_timer::read ()
 {
   clock_t stop = clock ();
-  return Real (stop - start_clock_) / Real (CLOCKS_PER_SEC);
+  return static_cast<Real> (stop - start_clock_)
+         / static_cast<Real> (CLOCKS_PER_SEC);
 }
Index: flower/include/drul-array.hh
diff --git a/flower/include/drul-array.hh b/flower/include/drul-array.hh
index 
43a01d65003667f521184e10cc7a6bba74795ff3..6144a5fd38f10a7b05d10a5d5b43b311deb25d7d
 100644
--- a/flower/include/drul-array.hh
+++ b/flower/include/drul-array.hh
@@ -73,8 +73,8 @@ scale_drul (Drul_array<T> *dr, T x)
 inline Real
 linear_combination (Drul_array<Real> const &d, Real x)
 {
-  return ((1.0 - x) * Real (d.at (LEFT))
-          + (x + 1.0) * Real (d.at (RIGHT))) * 0.5;
+  return ((1.0 - x) * static_cast<Real> (d.at (LEFT))
+          + (x + 1.0) * static_cast<Real> (d.at (RIGHT))) * 0.5;
 }
 
 #endif /* DRUL_ARRAY_HH */
Index: lily/bracket.cc
diff --git a/lily/bracket.cc b/lily/bracket.cc
index 
7c6a5f6691beca5a6d45d90a9809133147290856..02bce08c51a94a5958fcd4c25fb0ab2d3e785271
 100644
--- a/lily/bracket.cc
+++ b/lily/bracket.cc
@@ -104,7 +104,7 @@ Bracket::make_axis_constrained_bracket (Grob *me, Real 
length, Axis a,
                                                   Interval (0, 0));
 
   // Make sure that it points in the correct direction:
-  scale_drul (&edge_height, Real (-dir));
+  scale_drul (&edge_height, static_cast<Real> (-dir));
 
   Offset start;
   start[a] = length;
Index: lily/freetype.cc
diff --git a/lily/freetype.cc b/lily/freetype.cc
index 
339c42128450bfdf569b5ff9b01507e8ceed3abb..2c4258960d887393e5ffb5f3a15b62e968b6f34a
 100644
--- a/lily/freetype.cc
+++ b/lily/freetype.cc
@@ -44,8 +44,9 @@ ly_FT_get_unscaled_indexed_char_dimensions (FT_Face const 
&face, size_t signed_i
   FT_Pos vb = m.horiBearingY;
 
   // is this viable for all grobs?
-  return Box (Interval (Real (hb), Real (hb + m.width)),
-              Interval (Real (vb - m.height), Real (vb)));
+  return Box (
+      Interval (static_cast<Real> (hb), static_cast<Real> (hb + m.width)),
+      Interval (static_cast<Real> (vb - m.height), static_cast<Real> (vb)));
 }
 
 SCM
Index: lily/midi-walker.cc
diff --git a/lily/midi-walker.cc b/lily/midi-walker.cc
index 
912ee265eba03d1698ad7a4bdb8854b48567d880..033116fb1a531b9f7e075940c5e9c4a32ed6652f
 100644
--- a/lily/midi-walker.cc
+++ b/lily/midi-walker.cc
@@ -87,8 +87,9 @@ Midi_walker::do_start_note (Midi_note *note)
   Audio_item *ptr = items_[index_];
   assert (note->audio_ == ptr);
   int now_ticks = ptr->audio_column_->ticks ();
-  int stop_ticks = int (moment_to_real (note->audio_->length_mom_) *
-                        Real (384 * 4)) + now_ticks;
+  int stop_ticks = int (moment_to_real (note->audio_->length_mom_)
+                        * static_cast<Real> (384 * 4))
+                   + now_ticks;
   for (vsize i = 0; i < stop_note_queue.size (); i++)
     {
       /* if this pitch already in queue, and is not already ignored */
Index: lily/open-type-font.cc
diff --git a/lily/open-type-font.cc b/lily/open-type-font.cc
index 
dfd21e48c71791aba1e78b83ff90cc2a1887d2e0..e4b25e39e128206e0e4cd15e046e1f02e521cb0e
 100644
--- a/lily/open-type-font.cc
+++ b/lily/open-type-font.cc
@@ -350,7 +350,7 @@ Open_type_font::get_indexed_char_dimensions (size_t 
signed_idx) const
 
   Box b = get_unscaled_indexed_char_dimensions (signed_idx);
 
-  b.scale (design_size () / Real (face_->units_per_EM));
+  b.scale (design_size () / static_cast<Real> (face_->units_per_EM));
   return b;
 }
 
@@ -420,7 +420,7 @@ Open_type_font::design_size () const
                                quickly. --hwn.
                              */
                              scm_from_unsigned_integer (1));
-  return scm_to_double (entry) * Real (point_constant);
+  return scm_to_double (entry) * static_cast<Real> (point_constant);
 }
 
 SCM
Index: lily/pango-font.cc
diff --git a/lily/pango-font.cc b/lily/pango-font.cc
index 
cd00b26f80273c02d7474bc72f82edf1d2f3dfc7..c99e0f92ed421057fdd4948bb8becc26f3e320a4
 100644
--- a/lily/pango-font.cc
+++ b/lily/pango-font.cc
@@ -71,7 +71,8 @@ Pango_font::Pango_font (PangoFT2FontMap *fontmap,
   //  --hwn
   output_scale_ = output_scale;
   scale_ = INCH_TO_BP
-           / (Real (PANGO_SCALE) * Real (PANGO_RESOLUTION) * output_scale);
+           / (static_cast<Real> (PANGO_SCALE)
+              * static_cast<Real> (PANGO_RESOLUTION) * output_scale);
 
   // ugh. Should make this configurable.
   pango_context_set_language (context_, pango_language_from_string ("en_US"));
@@ -333,7 +334,7 @@ Pango_font::pango_item_string_stencil (PangoGlyphItem const 
*glyph_item) const
   pgs = 0;
   PangoFontDescription *descr = pango_font_describe (pa->font);
   Real size = pango_font_description_get_size (descr)
-              / (Real (PANGO_SCALE));
+              / (static_cast<Real> (PANGO_SCALE));
 
   if (ps_name_str0.empty ())
     warning (_f ("no PostScript font name for font `%s'", file_name));
Index: lily/pitch.cc
diff --git a/lily/pitch.cc b/lily/pitch.cc
index 
bf44c00839431e4f85b75ddb542f2558131ccbbe..9c18449c0f4c1c61c3a3a27776dbf8697ee601a2
 100644
--- a/lily/pitch.cc
+++ b/lily/pitch.cc
@@ -158,7 +158,7 @@ Pitch::to_string () const
   int n = (notename_ + 2) % scale_->step_count ();
   string s (1, static_cast<char> (n + 'a'));
   Rational qtones = alteration_ * Rational (4, 1);
-  int qt = int (rint (Real (qtones)));
+  int qt = int (rint (static_cast<Real> (qtones)));
 
   s += string (accname[qt + 4]);
   if (octave_ >= 0)
Index: lily/spring.cc
diff --git a/lily/spring.cc b/lily/spring.cc
index 
6af93c3e59ff520590f7e0b4017f35758edbbd2d..7f79a9f88563997f6027a2154cf98b22ece727c0
 100644
--- a/lily/spring.cc
+++ b/lily/spring.cc
@@ -116,9 +116,9 @@ merge_springs (vector<Spring> const &springs)
       min_distance = std::max (springs[i].min_distance (), min_distance);
     }
 
-  avg_stretch /= Real (springs.size ());
-  avg_compress /= Real (springs.size ());
-  avg_distance /= Real (springs.size ());
+  avg_stretch /= static_cast<Real> (springs.size ());
+  avg_compress /= static_cast<Real> (springs.size ());
+  avg_distance /= static_cast<Real> (springs.size ());
   avg_distance = std::max (min_distance + 0.3, avg_distance);
 
   Spring ret = Spring (avg_distance, min_distance);
@@ -231,4 +231,3 @@ Spring::length (Real f) const
   // and we need to make sure that we return min_distance_.
   return std::max (min_distance_, distance_ + force * inv_k);
 }
-
Index: lily/stem.cc
diff --git a/lily/stem.cc b/lily/stem.cc
index 
7f1983bc641f0fc969d62fbbecfc8e1dea870466..69cd4476ca47dc890552a0c23e2507ba6c9f090e
 100644
--- a/lily/stem.cc
+++ b/lily/stem.cc
@@ -556,7 +556,8 @@ Stem::calc_positioning_done (SCM smob)
         heads[i]->translate_axis (amount, X_AXIS);
     }
   bool parity = true;
-  Real lastpos = Real (Staff_symbol_referencer::get_position (heads[0]));
+  Real lastpos
+      = static_cast<Real> (Staff_symbol_referencer::get_position (heads[0]));
   int threshold = robust_scm2int (me->get_property 
("note-collision-threshold"), 1);
   for (vsize i = 1; i < heads.size (); i++)
     {
Index: lily/volta-bracket.cc
diff --git a/lily/volta-bracket.cc b/lily/volta-bracket.cc
index 
dd752f8014daed8692b2a089ce9db2bab44f49d7..584241997e022b515b31ed0fae5947140b5bb0dd
 100644
--- a/lily/volta-bracket.cc
+++ b/lily/volta-bracket.cc
@@ -88,7 +88,7 @@ Volta_bracket_interface::print (SCM smob)
   Drul_array<Real> shorten = robust_scm2interval (me->get_property 
("shorten-pair"),
                                                   Interval (0, 0));
 
-  scale_drul (&edge_height, - Real (get_grob_direction (me)));
+  scale_drul (&edge_height, -static_cast<Real> (get_grob_direction (me)));
 
   Interval empty;
   Offset start;
@@ -173,4 +173,3 @@ ADD_INTERFACE (Volta_bracket_interface,
                "shorten-pair "
                "thickness "
               );
-





reply via email to

[Prev in Thread] Current Thread [Next in Thread]