]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/simple-spacer-scheme.cc
Issue 5167/6: Changes: show \markup xxx = ... \etc assignments
[lilypond.git] / lily / simple-spacer-scheme.cc
index c47993fb6a29c78e7b5f1cb7f2d6dbff801c920b..7c1c866c6113015354ce5161e4142e8b48f6e566 100644 (file)
@@ -1,9 +1,20 @@
 /*
-  simple-spacer-scheme.cc -- implement Simple_spacer
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-  (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include <cstdio>
 #include "simple-spacer.hh"
 
 LY_DEFINE (ly_solve_spring_rod_problem, "ly:solve-spring-rod-problem",
-          4, 1, 0, (SCM springs, SCM rods, SCM length, SCM ragged),
-          "Solve a spring and rod problem for @var{count} objects, that "
-          "are connected by @var{count-1} springs, and an arbitrary number of rods "
-          "Springs have the format (ideal, hooke) and rods (idx1, idx2, distance) "
-          "@var{length} is a number, @var{ragged} a boolean "
-          "Return: a list containing the force (positive for stretching, "
-          "negative for compressing and #f for non-satisfied constraints) "
-          "followed by the @var{spring-count}+1 positions of the objects. ")
+           4, 1, 0, (SCM springs, SCM rods, SCM length, SCM ragged),
+           "Solve a spring and rod problem for @var{count} objects, that"
+           " are connected by @var{count}-1 @var{springs}, and an arbitrary"
+           " number of @var{rods}.  @var{count} is implicitly given by"
+           " @var{springs} and @var{rods}.  The @var{springs} argument has"
+           " the format @code{(ideal, inverse_hook)} and @var{rods} is of"
+           " the form @code{(idx1, idx2, distance)}.\n"
+           "\n"
+           "@var{length} is a number, @var{ragged} a boolean.\n"
+           "\n"
+           "The function returns a list containing the force (positive for"
+           " stretching, negative for compressing and @code{#f} for"
+           " non-satisfied constraints) followed by @var{spring-count}+1"
+           " positions of the objects.")
 {
   int len = scm_ilength (springs);
   if (len == 0)
     return scm_list_2 (scm_from_double (0.0), scm_from_double (0.0));
 
   SCM_ASSERT_TYPE (len >= 0, springs, SCM_ARG1, __FUNCTION__, "list of springs");
-  SCM_ASSERT_TYPE (scm_ilength (rods) >= 0, rods, SCM_ARG2, __FUNCTION__, "list of rods");
-  SCM_ASSERT_TYPE (scm_is_number (length) || length == SCM_BOOL_F,
-                  length, SCM_ARG3, __FUNCTION__, "number or #f");
+  SCM_ASSERT_TYPE (scm_ilength (rods) > 0, rods, SCM_ARG1, __FUNCTION__, "list of rods");
+  LY_ASSERT_TYPE (scm_is_number, length, 3);
 
-  bool is_ragged = ragged == SCM_BOOL_T;
+  bool is_ragged = to_boolean (ragged);
   Simple_spacer spacer;
   for (SCM s = springs; scm_is_pair (s); s = scm_cdr (s))
     {
       Real ideal = scm_to_double (scm_caar (s));
-      Real hooke = scm_to_double (scm_cadar (s));
+      Real inv_hooke = scm_to_double (scm_cadar (s));
 
-      spacer.add_spring (ideal, 1 / hooke);
+      Spring sp (ideal, 0.0);
+      sp.set_inverse_compress_strength (inv_hooke);
+      sp.set_inverse_stretch_strength (inv_hooke);
+
+      spacer.add_spring (sp);
     }
 
   for (SCM s = rods; scm_is_pair (s); s = scm_cdr (s))
@@ -53,29 +73,11 @@ LY_DEFINE (ly_solve_spring_rod_problem, "ly:solve-spring-rod-problem",
       spacer.add_rod (l, r, distance);
     }
 
-  spacer.line_len_ = scm_to_double (length);
-
-  if (is_ragged)
-    spacer.my_solve_natural_len ();
-  else
-    spacer.my_solve_linelen ();
-
-  std::vector<Real> posns;
-  posns.push_back (0.0);
-  for (vsize i = 0; i < spacer.springs_.size (); i++)
-    {
-      Real l = spacer.springs_[i].length ((is_ragged) ? 0.0 : spacer.force_);
-      posns.push_back (posns.back () + l);
-    }
+  spacer.solve (scm_to_double (length), is_ragged);
 
-  SCM force_return = SCM_BOOL_F;
-  if (!isinf (spacer.force_)
-      && (spacer.is_active () || is_ragged))
-    force_return = scm_from_double (spacer.force_);
+  vector<Real> posns = spacer.spring_positions ();
 
-  if (is_ragged
-      && posns.back () > spacer.line_len_)
-    force_return = SCM_BOOL_F;
+  SCM force_return = spacer.fits () ? scm_from_double (spacer.force ()) : SCM_BOOL_F;
 
   SCM retval = SCM_EOL;
   for (vsize i = posns.size (); i--;)