LEFT | RIGHT |
(no file at all) | |
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--2019 Joe Neeman <joeneeman@gmail.com> | 4 Copyright (C) 2007--2019 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 Spring ret = Spring (avg_distance, min_distance); | 122 Spring ret = Spring (avg_distance, min_distance); |
123 ret.set_inverse_stretch_strength (avg_stretch); | 123 ret.set_inverse_stretch_strength (avg_stretch); |
124 ret.set_inverse_compress_strength (1 / avg_compress); | 124 ret.set_inverse_compress_strength (1 / avg_compress); |
125 | 125 |
126 return ret; | 126 return ret; |
127 } | 127 } |
128 | 128 |
129 void | 129 void |
130 Spring::set_distance (Real d) | 130 Spring::set_distance (Real d) |
131 { | 131 { |
132 if (d < 0 || isinf (d) || isnan (d)) | 132 if (d < 0 || !std::isfinite (d)) |
133 programming_error ("insane spring distance requested, ignoring it"); | 133 programming_error ("insane spring distance requested, ignoring it"); |
134 else | 134 else |
135 { | 135 { |
136 distance_ = d; | 136 distance_ = d; |
137 update_blocking_force (); | 137 update_blocking_force (); |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 void | 141 void |
142 Spring::set_min_distance (Real d) | 142 Spring::set_min_distance (Real d) |
143 { | 143 { |
144 if (d < 0 || isinf (d) || isnan (d)) | 144 if (d < 0 || !std::isfinite (d)) |
145 programming_error ("insane spring min_distance requested, ignoring it"); | 145 programming_error ("insane spring min_distance requested, ignoring it"); |
146 else | 146 else |
147 { | 147 { |
148 min_distance_ = d; | 148 min_distance_ = d; |
149 update_blocking_force (); | 149 update_blocking_force (); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 void | 153 void |
154 Spring::ensure_min_distance (Real d) | 154 Spring::ensure_min_distance (Real d) |
155 { | 155 { |
156 set_min_distance (max (d, min_distance_)); | 156 set_min_distance (max (d, min_distance_)); |
157 } | 157 } |
158 | 158 |
159 void | 159 void |
160 Spring::set_inverse_stretch_strength (Real f) | 160 Spring::set_inverse_stretch_strength (Real f) |
161 { | 161 { |
162 if (isinf (f) || isnan (f) || f < 0) | 162 if (!std::isfinite (f) || f < 0) |
163 programming_error ("insane spring constant"); | 163 programming_error ("insane spring constant"); |
164 else | 164 else |
165 inverse_stretch_strength_ = f; | 165 inverse_stretch_strength_ = f; |
166 | 166 |
167 update_blocking_force (); | 167 update_blocking_force (); |
168 } | 168 } |
169 | 169 |
170 void | 170 void |
171 Spring::set_inverse_compress_strength (Real f) | 171 Spring::set_inverse_compress_strength (Real f) |
172 { | 172 { |
173 if (isinf (f) || isnan (f) || f < 0) | 173 if (!std::isfinite (f) || f < 0) |
174 programming_error ("insane spring constant"); | 174 programming_error ("insane spring constant"); |
175 else | 175 else |
176 inverse_compress_strength_ = f; | 176 inverse_compress_strength_ = f; |
177 | 177 |
178 update_blocking_force (); | 178 update_blocking_force (); |
179 } | 179 } |
180 | 180 |
181 void | 181 void |
182 Spring::set_blocking_force (Real f) | 182 Spring::set_blocking_force (Real f) |
183 { | 183 { |
184 if (isinf (f) || isnan (f)) | 184 if (!std::isfinite (f)) |
185 { | 185 { |
186 programming_error ("insane blocking force"); | 186 programming_error ("insane blocking force"); |
187 return; | 187 return; |
188 } | 188 } |
189 | 189 |
190 blocking_force_ = -infinity_f; | 190 blocking_force_ = -infinity_f; |
191 min_distance_ = length (f); | 191 min_distance_ = length (f); |
192 update_blocking_force (); | 192 update_blocking_force (); |
193 } | 193 } |
194 | 194 |
(...skipping 16 matching lines...) Expand all Loading... |
211 { | 211 { |
212 inverse_stretch_strength_ = distance_; | 212 inverse_stretch_strength_ = distance_; |
213 } | 213 } |
214 | 214 |
215 Real | 215 Real |
216 Spring::length (Real f) const | 216 Spring::length (Real f) const |
217 { | 217 { |
218 Real force = max (f, blocking_force_); | 218 Real force = max (f, blocking_force_); |
219 Real inv_k = force < 0.0 ? inverse_compress_strength_ : inverse_stretch_streng
th_; | 219 Real inv_k = force < 0.0 ? inverse_compress_strength_ : inverse_stretch_streng
th_; |
220 | 220 |
221 if (isinf (force)) | 221 if (std::isinf (force)) |
222 { | 222 { |
223 programming_error ("cruelty to springs"); | 223 programming_error ("cruelty to springs"); |
224 force = 0.0; | 224 force = 0.0; |
225 } | 225 } |
226 | 226 |
227 // There is a corner case here: if min_distance_ is larger than | 227 // There is a corner case here: if min_distance_ is larger than |
228 // distance_ but the spring is fixed, then inv_k will be zero | 228 // distance_ but the spring is fixed, then inv_k will be zero |
229 // and we need to make sure that we return min_distance_. | 229 // and we need to make sure that we return min_distance_. |
230 return max (min_distance_, distance_ + force * inv_k); | 230 return max (min_distance_, distance_ + force * inv_k); |
231 } | 231 } |
232 | 232 |
LEFT | RIGHT |