25 #ifndef __SYNFIG_VALUEOPERATIONS_H
26 #define __SYNFIG_VALUEOPERATIONS_H
42 namespace types_namespace {
class TypeWeightedValueBase; }
114 bp.set_tangent1( transformation.
transform(bp.get_tangent1(),
false) );
115 bp.set_tangent2( transformation.
transform(bp.get_tangent2(),
false) );
126 s.t1 = transformation.
transform(s.t1,
false);
128 s.t2 = transformation.
transform(s.t2,
false);
185 res.set_vertex( res.get_vertex() + b.get_vertex() );
186 res.set_tangent1( res.get_tangent1() + b.get_tangent1() );
187 res.set_tangent2( res.get_tangent2() + b.get_tangent2() );
217 res.set_width( res.get_width() + b.get_width() );
221 return default_value;
225 {
return add(value_a, value_b, value_a); }
231 return value.
get(
Real()) * amplifier;
236 res.
set_vertex( res.get_vertex() * amplifier );
237 res.set_tangent1( res.get_tangent1() * amplifier );
238 res.set_tangent2( res.get_tangent2() * amplifier );
264 res.
set_width( res.get_width() * amplifier );
273 template<
typename ConstIterator,
typename ConstWeightIterator>
277 ConstWeightIterator weight_begin,
278 ConstWeightIterator weight_end,
287 for(ConstIterator i(begin); !(i == end); ++i, ++count)
288 if ((*i).get_type() != type)
return ValueBase();
291 bool weights = !(weight_begin == weight_end);
292 Real summary_weight = 0.0;
293 int weights_count = 0;
295 for(ConstWeightIterator i(weight_begin); !(i == weight_end) && weights_count < count; ++i, ++weights_count)
296 summary_weight += *i;
297 if (weights_count < count || summary_weight == 0.0) weights =
false;
298 if (!weights) summary_weight = (
Real)count;
299 Real amplifier = 1.0/summary_weight;
306 ConstWeightIterator j(weight_begin);
307 ConstIterator i(begin);
308 summary =
multiply(*i, (*j) * amplifier);
309 for(++i, ++j; !(i == end); ++i, ++j)
315 ConstIterator i(begin);
317 for(++i; !(i == end); ++i)
324 template<
typename ConstIterator>
332 const std::vector<ValueBase> &list_vector = list.
get_list();
335 std::vector<Real> weights_vector_real;
336 weights_vector_real.reserve(weights.
get_list().size());
337 const std::vector<ValueBase> &weights_vector = weights.
get_list();
338 for(std::vector<ValueBase>::const_iterator i = weights_vector.begin(); i != weights_vector.end(); ++i)
340 weights_vector_real.push_back(i->get(
Real()));
else break;
341 if (weights_vector.size() >= list_vector.size())
343 list_vector.begin(), list_vector.end(),
344 weights_vector_real.begin(), weights_vector_real.end(),
347 return average_generic(list_vector.begin(), list_vector.end(), default_value);
362 template<
typename Iterator,
typename ConstWeightIterator>
366 ConstWeightIterator weight_begin,
367 ConstWeightIterator weight_end,
370 if (begin == end)
return;
376 for(Iterator i(begin); !(i == end); ++i, ++count)
377 if ((*i).get_type() != type)
return;
384 for(Iterator i(begin); !(i == end); ++i)
385 *i =
add(*i, difference);
388 template<
typename Iterator>
396 std::vector<ValueBase> list_vector = list.
get_list();
399 std::vector<Real> weights_vector_real;
400 weights_vector_real.reserve(weights.
get_list().size());
401 const std::vector<ValueBase> &weights_vector = weights.
get_list();
402 for(std::vector<ValueBase>::const_iterator i = weights_vector.begin(); i != weights_vector.end(); ++i)
404 weights_vector_real.push_back(i->get(
Real()));
else break;
405 if (weights_vector.size() >= list_vector.size())
408 list_vector.begin(), list_vector.end(),
409 weights_vector_real.begin(), weights_vector_real.end(),