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