]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/simple-spacer-scheme.cc
replace SCM_ASSERT_TYPE with LY_ASSERT_TYPE and friends
[lilypond.git] / lily / simple-spacer-scheme.cc
index 24ff02c680aad486a49e019408a52ed63dc20323..2d702edcd0d2a30d8d308212d2efdd10a80a8b58 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #include <cstdio>
@@ -23,14 +23,15 @@ LY_DEFINE (ly_solve_spring_rod_problem, "ly:solve-spring-rod-problem",
           "negative for compressing and #f for non-satisfied constraints) "
           "followed by the @var{spring-count}+1 positions of the objects. ")
 {
+  LY_FUNC_NOTE_FIRST_ARG(springs);
+  
   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, 3);
 
   bool is_ragged = ragged == SCM_BOOL_T;
   Simple_spacer spacer;
@@ -53,29 +54,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);
+  spacer.solve (scm_to_double (length), is_ragged);
 
-  if (is_ragged)
-    spacer.my_solve_natural_len ();
-  else
-    spacer.my_solve_linelen ();
+  vector<Real> posns = spacer.spring_positions ();
 
-  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);
-    }
-
-  SCM force_return = SCM_BOOL_F;
-  if (!isinf (spacer.force_)
-      && (spacer.is_active () || is_ragged))
-    force_return = scm_from_double (spacer.force_);
-
-  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--;)