Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 2007--2011 Joe Neeman <joeneeman@gmail.com> | 4 Copyright (C) 2007--2011 Joe Neeman <joeneeman@gmail.com> |
5 | 5 |
6 LilyPond is free software: you can redistribute it and/or modify | 6 LilyPond is free software: you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation, either version 3 of the License, or | 8 the Free Software Foundation, either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 set_distance (dist); | 39 set_distance (dist); |
40 set_min_distance (min_dist); | 40 set_min_distance (min_dist); |
41 set_default_strength (); | 41 set_default_strength (); |
42 update_blocking_force (); | 42 update_blocking_force (); |
43 } | 43 } |
44 | 44 |
45 void | 45 void |
46 Spring::update_blocking_force () | 46 Spring::update_blocking_force () |
47 { | 47 { |
48 // blocking_force_ is the value of force | |
49 // below which length(force) is constant, and | |
50 // above which length(force) varies according to inverse_*_strength. | |
51 // Simple_spacer::compress_line() depends on the contition above. | |
joeneeman
2011/06/04 07:09:05
condition
| |
52 // We assume inverse_*_strength are non-negative. | |
48 if (min_distance_ > distance_) | 53 if (min_distance_ > distance_) |
49 blocking_force_ = (min_distance_ - distance_) / inverse_stretch_strength_; | 54 if (inverse_stretch_strength_ > 0.0) |
55 blocking_force_ = (min_distance_ - distance_) / inverse_stretch_strength_; | |
56 else | |
57 blocking_force_ = 0.0; | |
50 else | 58 else |
51 blocking_force_ = (min_distance_ - distance_) / inverse_compress_strength_; | 59 if (inverse_compress_strength_ > 0.0) |
52 | 60 blocking_force_ = (min_distance_ - distance_) / inverse_compress_strength_ ; |
53 // If the spring is fixed, it's not clear what the natural value | 61 else |
54 // of blocking_force_ would be (because it always blocks). | 62 blocking_force_ = 0.0; |
55 // -infinity_f works fine for now. | |
joeneeman
2011/06/04 07:09:05
So now, you make fixed springs have a blocking_for
Keith
2011/06/04 10:48:09
My comment tries to state the contitions ^H^H cond
joeneeman
2011/06/04 17:32:15
It seems, though, that unstretchable but compressi
| |
56 // If inverse_stretch_strength > 0, the spring is not fixed (because it can st retch). | |
57 if (isnan (blocking_force_) || blocking_force_ == infinity_f) | |
58 blocking_force_ = (inverse_stretch_strength_ > 0) ? 0.0 : -infinity_f; | |
59 | |
60 if (blocking_force_ >= 0) | |
61 inverse_compress_strength_ = 0; | |
62 } | 63 } |
63 | 64 |
64 /* scale a spring, but in a way that doesn't violate min_distance */ | 65 /* scale a spring, but in a way that doesn't violate min_distance */ |
65 void | 66 void |
66 Spring::operator*= (Real r) | 67 Spring::operator*= (Real r) |
67 { | 68 { |
68 distance_ = max (min_distance_, distance_ * r); | 69 distance_ = max (min_distance_, distance_ * r); |
69 inverse_compress_strength_ = max (0.0, distance_ - min_distance_); | 70 inverse_compress_strength_ = max (0.0, distance_ - min_distance_); |
70 inverse_stretch_strength_ *= 0.8; | 71 inverse_stretch_strength_ *= 0.8; |
71 update_blocking_force (); | 72 update_blocking_force (); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 programming_error ("cruelty to springs"); | 206 programming_error ("cruelty to springs"); |
206 force = 0.0; | 207 force = 0.0; |
207 } | 208 } |
208 | 209 |
209 // There is a corner case here: if min_distance_ is larger than | 210 // There is a corner case here: if min_distance_ is larger than |
210 // distance_ but the spring is fixed, then inv_k will be zero | 211 // distance_ but the spring is fixed, then inv_k will be zero |
211 // and we need to make sure that we return min_distance_. | 212 // and we need to make sure that we return min_distance_. |
212 return max (min_distance_, distance_ + force * inv_k); | 213 return max (min_distance_, distance_ + force * inv_k); |
213 } | 214 } |
214 | 215 |
OLD | NEW |