Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07 / src / synfig / valuenode_bline.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file valuenode_bline.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "valuenode_bline.h"
34 #include "valuenode_const.h"
35 #include "valuenode_composite.h"
36 #include "general.h"
37 #include "exception.h"
38 #include "blinepoint.h"
39 #include <vector>
40 #include <list>
41 #include <algorithm>
42 #include <ETL/hermite>
43 #include <ETL/calculus>
44 #include "segment.h"
45
46 #endif
47
48 /* === U S I N G =========================================================== */
49
50 using namespace std;
51 using namespace etl;
52 using namespace synfig;
53
54 /* === M A C R O S ========================================================= */
55
56 /* === G L O B A L S ======================================================= */
57
58 /* === P R O C E D U R E S ================================================= */
59
60 inline float
61 linear_interpolation(const float& a, const float& b, float c)
62 { return (b-a)*c+a; }
63
64 inline Vector
65 linear_interpolation(const Vector& a, const Vector& b, float c)
66 { return (b-a)*c+a; }
67
68 inline Vector
69 radial_interpolation(const Vector& a, const Vector& b, float c)
70 {
71         // if either extreme is zero then use linear interpolation instead
72         if (a.is_equal_to(Vector::zero()) || b.is_equal_to(Vector::zero()))
73                 return linear_interpolation(a, b, c);
74
75         affine_combo<Real,float> mag_combo;
76         affine_combo<Angle,float> ang_combo;
77
78         Real mag(mag_combo(a.mag(),b.mag(),c));
79         Angle ang(ang_combo(Angle::tan(a[1],a[0]),Angle::tan(b[1],b[0]),c));
80
81         return Point( mag*Angle::cos(ang).get(),mag*Angle::sin(ang).get() );
82 }
83
84 inline void
85 transform_coords(Vector in, Vector& out, const Point& coord_origin, const Point *coord_sys)
86 {
87         in -= coord_origin;
88         out[0] = in * coord_sys[0];
89         out[1] = in * coord_sys[1];
90 }
91
92 inline void
93 untransform_coords(const Vector& in, Vector& out, const Point& coord_origin, const Point *coord_sys)
94 {
95         out[0] = in * coord_sys[0];
96         out[1] = in * coord_sys[1];
97         out += coord_origin;
98 }
99
100 ValueBase
101 synfig::convert_bline_to_segment_list(const ValueBase& bline)
102 {
103         std::vector<Segment> ret;
104
105 //      std::vector<BLinePoint> list(bline.operator std::vector<BLinePoint>());
106         //std::vector<BLinePoint> list(bline);
107         std::vector<BLinePoint> list(bline.get_list().begin(),bline.get_list().end());
108         std::vector<BLinePoint>::const_iterator iter;
109
110         BLinePoint prev,first;
111
112         //start with prev = first and iter on the second...
113
114         if(list.empty()) return ValueBase(ret,bline.get_loop());
115         first = prev = list.front();
116
117         for(iter=++list.begin();iter!=list.end();++iter)
118         {
119                 ret.push_back(
120                         Segment(
121                                 prev.get_vertex(),
122                                 prev.get_tangent2(),
123                                 iter->get_vertex(),
124                                 iter->get_tangent1()
125                         )
126                 );
127                 prev=*iter;
128         }
129         if(bline.get_loop())
130         {
131                 ret.push_back(
132                         Segment(
133                                 prev.get_vertex(),
134                                 prev.get_tangent2(),
135                                 first.get_vertex(),
136                                 first.get_tangent1()
137                         )
138                 );
139         }
140         return ValueBase(ret,bline.get_loop());
141 }
142
143 ValueBase
144 synfig::convert_bline_to_width_list(const ValueBase& bline)
145 {
146         std::vector<Real> ret;
147 //      std::vector<BLinePoint> list(bline.operator std::vector<BLinePoint>());
148         //std::vector<BLinePoint> list(bline);
149         std::vector<BLinePoint> list(bline.get_list().begin(),bline.get_list().end());
150         std::vector<BLinePoint>::const_iterator iter;
151
152         if(bline.empty())
153                 return ValueBase(ValueBase::TYPE_LIST);
154
155         for(iter=list.begin();iter!=list.end();++iter)
156                 ret.push_back(iter->get_width());
157
158         if(bline.get_loop())
159                 ret.push_back(list.front().get_width());
160
161         return ValueBase(ret,bline.get_loop());
162 }
163
164
165 /* === M E T H O D S ======================================================= */
166
167
168 ValueNode_BLine::ValueNode_BLine():
169         ValueNode_DynamicList(ValueBase::TYPE_BLINEPOINT)
170 {
171 }
172
173 ValueNode_BLine::~ValueNode_BLine()
174 {
175 }
176
177 ValueNode_BLine*
178 ValueNode_BLine::create(const ValueBase &value)
179 {
180         if(value.get_type()!=ValueBase::TYPE_LIST)
181                 return 0;
182
183         ValueNode_BLine* value_node(new ValueNode_BLine());
184
185         if(!value.empty())
186         {
187                 switch(value.get_contained_type())
188                 {
189                 case ValueBase::TYPE_BLINEPOINT:
190                 {
191 //                      std::vector<BLinePoint> bline_points(value.operator std::vector<BLinePoint>());
192                         //std::vector<BLinePoint> bline_points(value);
193                         std::vector<BLinePoint> bline_points(value.get_list().begin(),value.get_list().end());
194                         std::vector<BLinePoint>::const_iterator iter;
195
196                         for(iter=bline_points.begin();iter!=bline_points.end();iter++)
197                         {
198                                 value_node->add(ValueNode::Handle(ValueNode_Composite::create(*iter)));
199                         }
200                         value_node->set_loop(value.get_loop());
201                 }
202                         break;
203                 case ValueBase::TYPE_SEGMENT:
204                 {
205                         // Here, we want to convert a list of segments
206                         // into a list of BLinePoints. We make an assumption
207                         // that the segment list is continuous(sp), but not necessarily
208                         // smooth.
209
210                         value_node->set_loop(false);
211 //                      std::vector<Segment> segments(value.operator std::vector<Segment>());
212 //                      std::vector<Segment> segments(value);
213                         std::vector<Segment> segments(value.get_list().begin(),value.get_list().end());
214                         std::vector<Segment>::const_iterator iter,last(segments.end());
215                         --last;
216                         ValueNode_Const::Handle prev,first;
217
218                         for(iter=segments.begin();iter!=segments.end();iter++)
219                         {
220 #define PREV_POINT      prev->get_value().get(BLinePoint())
221 #define FIRST_POINT     first->get_value().get(BLinePoint())
222 #define CURR_POINT      curr->get_value().get(BLinePoint())
223                                 if(iter==segments.begin())
224                                 {
225                                         prev=ValueNode_Const::create(ValueBase::TYPE_BLINEPOINT);
226                                         {
227                                                 BLinePoint prev_point(PREV_POINT);
228                                                 prev_point.set_vertex(iter->p1);
229                                                 prev_point.set_tangent1(iter->t1);
230                                                 prev_point.set_width(0.01);
231                                                 prev_point.set_origin(0.5);
232                                                 prev_point.set_split_tangent_flag(false);
233                                                 prev->set_value(prev_point);
234                                         }
235                                         first=prev;
236                                         value_node->add(ValueNode::Handle(prev));
237
238                                 }
239                                 if(iter==last && iter->p2.is_equal_to(FIRST_POINT.get_vertex()))
240                                 {
241                                         value_node->set_loop(true);
242                                         if(!iter->t2.is_equal_to(FIRST_POINT.get_tangent1()))
243                                         {
244                                                 BLinePoint first_point(FIRST_POINT);
245                                                 first_point.set_tangent1(iter->t2);
246                                                 first->set_value(first_point);
247                                         }
248                                         continue;
249                                 }
250
251                                 ValueNode_Const::Handle curr;
252                                 curr=ValueNode_Const::create(ValueBase::TYPE_BLINEPOINT);
253                                 {
254                                         BLinePoint curr_point(CURR_POINT);
255                                         curr_point.set_vertex(iter->p2);
256                                         curr_point.set_tangent1(iter->t2);
257                                         curr_point.set_width(0.01);
258                                         curr_point.set_origin(0.5);
259                                         curr_point.set_split_tangent_flag(false);
260                                         curr->set_value(curr_point);
261                                 }
262                                 if(!PREV_POINT.get_tangent1().is_equal_to(iter->t1))
263                                 {
264                                         BLinePoint prev_point(PREV_POINT);
265                                         prev_point.set_split_tangent_flag(true);
266                                         prev_point.set_tangent2(iter->t1);
267                                         prev->set_value(prev_point);
268                                 }
269                                 value_node->add(ValueNode::Handle(curr));
270                                 prev=curr;
271                         }
272
273                 }
274                         break;
275                 default:
276                         // We got a list of who-knows-what. We don't have any idea
277                         // what to do with it.
278                         return 0;
279                         break;
280                 }
281         }
282
283
284         return value_node;
285 }
286
287 ValueNode_BLine::ListEntry
288 ValueNode_BLine::create_list_entry(int index, Time time, Real origin)
289 {
290         ValueNode_BLine::ListEntry ret;
291
292
293         synfig::BLinePoint prev,next;
294
295         int prev_i,next_i;
296
297         index=index%link_count();
298
299         assert(index>=0);
300         ret.index=index;
301         ret.set_parent_value_node(this);
302
303         if(!list[index].status_at_time(time))
304                 next_i=find_next_valid_entry(index,time);
305         else
306                 next_i=index;
307         prev_i=find_prev_valid_entry(index,time);
308
309         synfig::info("index=%d, next_i=%d, prev_i=%d",index,next_i,prev_i);
310
311         next=(*list[next_i].value_node)(time);
312         prev=(*list[prev_i].value_node)(time);
313
314         etl::hermite<Vector> curve(prev.get_vertex(),next.get_vertex(),prev.get_tangent2(),next.get_tangent1());
315         etl::derivative< etl::hermite<Vector> > deriv(curve);
316
317         synfig::BLinePoint bline_point;
318         bline_point.set_vertex(curve(origin));
319         bline_point.set_width((next.get_width()-prev.get_width())*origin+prev.get_width());
320         bline_point.set_tangent1(deriv(origin)*min(1.0-origin,origin));
321         bline_point.set_tangent2(bline_point.get_tangent1());
322         bline_point.set_split_tangent_flag(false);
323         bline_point.set_origin(origin);
324
325         ret.value_node=ValueNode_Composite::create(bline_point);
326
327         return ret;
328 }
329
330 ValueBase
331 ValueNode_BLine::operator()(Time t)const
332 {
333         std::vector<BLinePoint> ret_list;
334
335         std::vector<ListEntry>::const_iterator iter,first_iter;
336         bool first_flag(true);
337         bool rising;
338         int index(0);
339         float next_scale(1.0f);
340
341         BLinePoint prev,first;
342         first.set_origin(100.0f);
343
344         // loop through all the list's entries
345         for(iter=list.begin();iter!=list.end();++iter,index++)
346         {
347                 // how 'on' is this vertex?
348                 float amount(iter->amount_at_time(t,&rising));
349
350                 assert(amount>=0.0f);
351                 assert(amount<=1.0f);
352
353                 // it's fully on
354                 if(amount==1.0f)
355                 {
356                         if(first_flag)
357                         {
358                                 first_iter=iter;
359                                 first=prev=(*iter->value_node)(t).get(prev);
360                                 first_flag=false;
361                                 ret_list.push_back(first);
362                                 continue;
363                         }
364
365                         BLinePoint curr;
366                         curr=(*iter->value_node)(t).get(prev);
367
368                         if(next_scale!=1.0f)
369                         {
370                                 ret_list.back().set_split_tangent_flag(true);
371                                 ret_list.back().set_tangent2(prev.get_tangent2()*next_scale);
372
373                                 ret_list.push_back(curr);
374
375                                 ret_list.back().set_split_tangent_flag(true);
376                                 ret_list.back().set_tangent2(curr.get_tangent2());
377                                 ret_list.back().set_tangent1(curr.get_tangent1()*next_scale);
378
379                                 next_scale=1.0f;
380                         }
381                         else
382                         {
383                                 ret_list.push_back(curr);
384                         }
385
386                         prev=curr;
387                 }
388                 // it's partly on
389                 else if(amount>0.0f)
390                 {
391                         std::vector<ListEntry>::const_iterator begin_iter,end_iter;
392
393                         // This is where the interesting stuff happens
394                         // We need to seek forward in the list to see what the next
395                         // active point is
396
397                         BLinePoint blp_here_on;  // the current vertex, when fully on
398                         BLinePoint blp_here_off; // the current vertex, when fully off
399                         BLinePoint blp_here_now; // the current vertex, right now (between on and off)
400                         BLinePoint blp_prev_off; // the beginning of dynamic group when fully off
401                         BLinePoint blp_next_off; // the end of the dynamic group when fully off
402
403                         int dist_from_begin(0), dist_from_end(0);
404                         Time off_time, on_time;
405
406                         if(!rising)     // if not rising, then we were fully on in the past, and will be fully off in the future
407                         {
408                                 try{ on_time=iter->find_prev(t)->get_time(); }
409                                 catch(...) { on_time=Time::begin(); }
410                                 try{ off_time=iter->find_next(t)->get_time(); }
411                                 catch(...) { off_time=Time::end(); }
412                         }
413                         else // otherwise we were fully off in the past, and will be fully on in the future
414                         {
415                                 try{ off_time=iter->find_prev(t)->get_time(); }
416                                 catch(...) { off_time=Time::begin(); }
417                                 try{ on_time=iter->find_next(t)->get_time(); }
418                                 catch(...) { on_time=Time::end(); }
419                         }
420
421                         blp_here_on=(*iter->value_node)(on_time).get(blp_here_on);
422 //                      blp_here_on=(*iter->value_node)(t).get(blp_here_on);
423
424                         // Find "end" of dynamic group - ie. search forward along
425                         // the bline from the current point until we find a point
426                         // which is more 'on'than the current one
427                         end_iter=iter;
428 //                      for(++end_iter;begin_iter!=list.end();++end_iter)
429                         for(++end_iter;end_iter!=list.end();++end_iter)
430                                 if(end_iter->amount_at_time(t)>amount)
431                                         break;
432
433                         // If we did not find an end of the dynamic group...
434                         // Writeme!  at least now it doesn't crash if first_iter
435                         // isn't set yet
436                         if(end_iter==list.end())
437                         {
438                                 if(get_loop() && !first_flag)
439                                         end_iter=first_iter;
440                                 else
441                                         end_iter=--list.end();
442                         }
443
444                         blp_next_off=(*end_iter->value_node)(off_time).get(prev);
445
446                         // Find "begin" of dynamic group
447                         begin_iter=iter;
448                         blp_prev_off.set_origin(100.0f); // set the origin to 100 (which is crazy) so that we can check to see if it was found
449                         do
450                         {
451                                 if(begin_iter==list.begin())
452                                 {
453                                         if(get_loop())
454                                                 begin_iter=list.end();
455                                         else
456                                                 break;
457                                 }
458
459                                 --begin_iter;
460                                 dist_from_begin++;
461
462                                 // if we've gone all around the loop, give up
463                                 if(begin_iter==iter)
464                                         break;
465
466                                 if(begin_iter->amount_at_time(t)>amount)
467                                 {
468                                         blp_prev_off=(*begin_iter->value_node)(off_time).get(prev);
469                                         break;
470                                 }
471                         }while(true);
472
473                         // If we did not find a begin
474                         if(blp_prev_off.get_origin()==100.0f)
475                         {
476                                 // Writeme! - this needs work, but at least now it
477                                 // doesn't crash
478                                 if(first_flag)
479                                         begin_iter=list.begin();
480                                 else
481                                         begin_iter=first_iter;
482                                 blp_prev_off=(*begin_iter->value_node)(off_time).get(prev);
483                         }
484
485                         // this is how the curve looks when we have completely vanished
486                         etl::hermite<Vector> curve(blp_prev_off.get_vertex(),   blp_next_off.get_vertex(),
487                                                                            blp_prev_off.get_tangent2(), blp_next_off.get_tangent1());
488                         etl::derivative< etl::hermite<Vector> > deriv(curve);
489
490                         // where would we be on this curve, how wide will we be, and
491                         // where will our tangents point (all assuming that we hadn't vanished)
492                         blp_here_off.set_vertex(curve(blp_here_on.get_origin()));
493                         blp_here_off.set_width((blp_next_off.get_width()-blp_prev_off.get_width())*blp_here_on.get_origin()+blp_prev_off.get_width());
494                         blp_here_off.set_tangent1(deriv(blp_here_on.get_origin()));
495                         blp_here_off.set_tangent2(deriv(blp_here_on.get_origin()));
496
497                         float prev_tangent_scalar(1.0f);
498                         float next_tangent_scalar(1.0f);
499
500                         //synfig::info("index_%d:dist_from_begin=%d",index,dist_from_begin);
501                         //synfig::info("index_%d:dist_from_end=%d",index,dist_from_end);
502
503                         // If we are the next to the begin
504                         if(begin_iter==--std::vector<ListEntry>::const_iterator(iter) || dist_from_begin==1)
505                                 prev_tangent_scalar=linear_interpolation(blp_here_on.get_origin(), 1.0f, amount);
506                         else
507                                 prev_tangent_scalar=linear_interpolation(blp_here_on.get_origin()-prev.get_origin(), 1.0f, amount);
508
509                         // If we are the next to the end
510                         if(end_iter==++std::vector<ListEntry>::const_iterator(iter) || dist_from_end==1)
511                                 next_tangent_scalar=linear_interpolation(1.0-blp_here_on.get_origin(), 1.0f, amount);
512                         else if(list.end()!=++std::vector<ListEntry>::const_iterator(iter))
513                         {
514                                 BLinePoint next;
515                                 next=((*(++std::vector<ListEntry>::const_iterator(iter))->value_node)(t).get(prev));
516                                 next_tangent_scalar=linear_interpolation(next.get_origin()-blp_here_on.get_origin(), 1.0f, amount);
517                         }
518                         else
519                                 //! \todo this isn't quite right; we should handle looped blines identically no matter where the loop happens
520                                 //! and we currently don't.  this at least makes it a lot better than it was before
521                                 next_tangent_scalar=linear_interpolation(blp_next_off.get_origin()-blp_here_on.get_origin(), 1.0f, amount);
522                         next_scale=next_tangent_scalar;
523
524                         //blp_here_now.set_vertex(linear_interpolation(blp_here_off.get_vertex(), blp_here_on.get_vertex(), amount));
525                         // if(false)
526                         // {
527                         //      // My first try
528                         //      Point ref_point_begin(((*begin_iter->value_node)(off_time).get(prev).get_vertex() +
529                         //                                                 (*end_iter->value_node)(off_time).get(prev).get_vertex()) * 0.5);
530                         //      Point ref_point_end(((*begin_iter->value_node)(on_time).get(prev).get_vertex() +
531                         //                                               (*end_iter->value_node)(on_time).get(prev).get_vertex()) * 0.5);
532                         //      Point ref_point_now(((*begin_iter->value_node)(t).get(prev).get_vertex() +
533                         //                                               (*end_iter->value_node)(t).get(prev).get_vertex()) * 0.5);
534                         //      Point ref_point_linear(linear_interpolation(ref_point_begin, ref_point_end, amount));
535                         //
536                         //      blp_here_now.set_vertex(linear_interpolation(blp_here_off.get_vertex(), blp_here_on.get_vertex(), amount) +
537                         //                                                      (ref_point_now-ref_point_linear));
538                         //      blp_here_now.set_tangent1(linear_interpolation(blp_here_off.get_tangent1(), blp_here_on.get_tangent1(), amount));
539                         //      blp_here_now.set_split_tangent_flag(blp_here_on.get_split_tangent_flag());
540                         //      if(blp_here_now.get_split_tangent_flag())
541                         //              blp_here_now.set_tangent2(linear_interpolation(blp_here_off.get_tangent2(), blp_here_on.get_tangent2(), amount));
542                         // }
543                         // else
544                         {
545                                 // My second try
546
547                                 // define 3 coordinate systems:
548                                 Point off_coord_sys[2],   off_coord_origin; // when the current vertex is completely off
549                                 Point on_coord_sys[2] ,    on_coord_origin; // when the current vertex is completely on
550                                 Point curr_coord_sys[2], curr_coord_origin; // the current state - somewhere in between
551
552                                 // for each of the 3 systems, the origin is half way between the previous and next active point
553                                 // and the axes are based on a vector from the next active point to the previous
554                                 {
555                                         const Point   end_pos_at_off_time((  *end_iter->value_node)(off_time).get(prev).get_vertex());
556                                         const Point begin_pos_at_off_time((*begin_iter->value_node)(off_time).get(prev).get_vertex());
557                                         off_coord_origin=(begin_pos_at_off_time + end_pos_at_off_time)/2;
558                                         off_coord_sys[0]=(begin_pos_at_off_time - end_pos_at_off_time).norm();
559                                         off_coord_sys[1]=off_coord_sys[0].perp();
560
561                                         const Point   end_pos_at_on_time((  *end_iter->value_node)(on_time).get(prev).get_vertex());
562                                         const Point begin_pos_at_on_time((*begin_iter->value_node)(on_time).get(prev).get_vertex());
563                                         on_coord_origin=(begin_pos_at_on_time + end_pos_at_on_time)/2;
564                                         on_coord_sys[0]=(begin_pos_at_on_time - end_pos_at_on_time).norm();
565                                         on_coord_sys[1]=on_coord_sys[0].perp();
566
567                                         const Point   end_pos_at_current_time((  *end_iter->value_node)(t).get(prev).get_vertex());
568                                         const Point begin_pos_at_current_time((*begin_iter->value_node)(t).get(prev).get_vertex());
569                                         curr_coord_origin=(begin_pos_at_current_time + end_pos_at_current_time)/2;
570                                         curr_coord_sys[0]=(begin_pos_at_current_time - end_pos_at_current_time).norm();
571                                         curr_coord_sys[1]=curr_coord_sys[0].perp();
572
573                                         // Invert (transpose) the last of these matricies, since we use it for transform back
574                                         swap(curr_coord_sys[0][1],curr_coord_sys[1][0]);
575                                 }
576
577                                 /* The code that was here before used just end_iter as the origin, rather than the mid-point */
578
579                                 // We know our location and tangent(s) when fully on and fully off
580                                 // Transform each of these into their corresponding coordinate system
581                                 Point trans_on_point, trans_off_point;
582                                 Vector trans_on_t1, trans_on_t2, trans_off_t1, trans_off_t2;
583
584                                 transform_coords(blp_here_on.get_vertex(),  trans_on_point,  on_coord_origin,  on_coord_sys);
585                                 transform_coords(blp_here_off.get_vertex(), trans_off_point, off_coord_origin, off_coord_sys);
586
587 #define COORD_SYS_RADIAL_TAN_INTERP 1
588
589 #ifdef COORD_SYS_RADIAL_TAN_INTERP
590                                 transform_coords(blp_here_on.get_tangent1(),  trans_on_t1,  Point::zero(), on_coord_sys);
591                                 transform_coords(blp_here_off.get_tangent1(), trans_off_t1, Point::zero(), off_coord_sys);
592
593                                 if(blp_here_on.get_split_tangent_flag())
594                                 {
595                                         transform_coords(blp_here_on.get_tangent2(),  trans_on_t2,  Point::zero(), on_coord_sys);
596                                         transform_coords(blp_here_off.get_tangent2(), trans_off_t2, Point::zero(), off_coord_sys);
597                                 }
598 #endif
599
600                                 {
601                                         // Interpolate between the 'on' point and the 'off' point and untransform to get our point's location
602                                         Point tmp;
603                                         untransform_coords(linear_interpolation(trans_off_point, trans_on_point, amount),
604                                                                            tmp, curr_coord_origin, curr_coord_sys);
605                                         blp_here_now.set_vertex(tmp);
606                                 }
607
608 #define INTERP_FUNCTION         radial_interpolation
609 //#define INTERP_FUNCTION       linear_interpolation
610
611 #ifdef COORD_SYS_RADIAL_TAN_INTERP
612                                 {
613                                         Vector tmp;
614                                         untransform_coords(INTERP_FUNCTION(trans_off_t1,trans_on_t1,amount), tmp, Point::zero(), curr_coord_sys);
615                                         blp_here_now.set_tangent1(tmp);
616                                 }
617 #else
618                                 blp_here_now.set_tangent1(radial_interpolation(blp_here_off.get_tangent1(),blp_here_on.get_tangent1(),amount));
619 #endif
620
621                                 if (blp_here_on.get_split_tangent_flag())
622                                 {
623                                         blp_here_now.set_split_tangent_flag(true);
624 #ifdef COORD_SYS_RADIAL_TAN_INTERP
625                                         {
626                                                 Vector tmp;
627                                                 untransform_coords(INTERP_FUNCTION(trans_off_t2,trans_on_t2,amount), tmp, Point::zero(), curr_coord_sys);
628                                                 blp_here_now.set_tangent2(tmp);
629                                         }
630 #else
631                                         blp_here_now.set_tangent2(radial_interpolation(blp_here_off.get_tangent2(),blp_here_on.get_tangent2(),amount));
632 #endif
633                                 }
634                                 else
635                                         blp_here_now.set_split_tangent_flag(false);
636                         }
637
638                         blp_here_now.set_origin(blp_here_on.get_origin());
639                         blp_here_now.set_width(linear_interpolation(blp_here_off.get_width(), blp_here_on.get_width(), amount));
640
641                         // Handle the case where we are the first vertex
642                         if(first_flag)
643                         {
644                                 blp_here_now.set_tangent1(blp_here_now.get_tangent1()*prev_tangent_scalar);
645                                 first_iter=iter;
646                                 first=prev=blp_here_now;
647                                 first_flag=false;
648                                 ret_list.push_back(blp_here_now);
649                                 continue;
650                         }
651
652                         ret_list.back().set_split_tangent_flag(true);
653                         ret_list.back().set_tangent2(prev.get_tangent2()*prev_tangent_scalar);
654                         ret_list.push_back(blp_here_now);
655                         ret_list.back().set_split_tangent_flag(true);
656                         //ret_list.back().set_tangent2(blp_here_now.get_tangent1());
657                         ret_list.back().set_tangent1(blp_here_now.get_tangent1()*prev_tangent_scalar);
658
659                         prev=blp_here_now;
660                 }
661         }
662
663         if(next_scale!=1.0f)
664         {
665                 ret_list.back().set_split_tangent_flag(true);
666                 ret_list.back().set_tangent2(prev.get_tangent2()*next_scale);
667         }
668
669 /*
670         if(get_loop() && !first_flag)
671         {
672                 ret_list.push_back(
673                         Segment(
674                         prev.get_vertex(),
675                         prev.get_tangent2(),
676                         first.get_vertex(),
677                         first.get_tangent1()
678                         )
679                 );
680         }
681 */
682
683         if(list.empty())
684                 synfig::warning(string("ValueNode_BLine::operator()():")+_("No entries in list"));
685         else
686         if(ret_list.empty())
687                 synfig::warning(string("ValueNode_BLine::operator()():")+_("No entries in ret_list"));
688
689         return ValueBase(ret_list,get_loop());
690 }
691
692 String
693 ValueNode_BLine::link_local_name(int i)const
694 {
695         assert(i>=0 && (unsigned)i<list.size());
696         return etl::strprintf(_("Vertex %03d"),i+1);
697 }
698
699 ValueNode*
700 ValueNode_BLine::clone(const GUID& deriv_guid)const
701 {
702         { ValueNode* x(find_value_node(get_guid()^deriv_guid).get()); if(x)return x; }
703
704         ValueNode_BLine* ret=new ValueNode_BLine();
705         ret->set_guid(get_guid()^deriv_guid);
706
707         std::vector<ListEntry>::const_iterator iter;
708
709         for(iter=list.begin();iter!=list.end();++iter)
710         {
711                 if(iter->value_node->is_exported())
712                         ret->add(*iter);
713                 else
714                 {
715                         ListEntry list_entry(*iter);
716                         //list_entry.value_node=find_value_node(iter->value_node->get_guid()^deriv_guid).get();
717                         //if(!list_entry.value_node)
718                                 list_entry.value_node=iter->value_node->clone(deriv_guid);
719                         ret->add(list_entry);
720                         //ret->list.back().value_node=iter->value_node.clone();
721                 }
722         }
723         ret->set_loop(get_loop());
724
725         return ret;
726 }
727
728 String
729 ValueNode_BLine::get_name()const
730 {
731         return "bline";
732 }
733
734 String
735 ValueNode_BLine::get_local_name()const
736 {
737         return _("BLine");
738 }
739
740 LinkableValueNode*
741 ValueNode_BLine::create_new()const
742 {
743         assert(0);
744         return 0;
745 }
746
747 bool
748 ValueNode_BLine::check_type(ValueBase::Type type)
749 {
750         return type==ValueBase::TYPE_LIST;
751 }