+ // we need to be able to erase(next) and can't do that if next is end()
+ if (next == vertex_list.end()) next = vertex_list.begin();
+ debug_show_vertex_list(i, vertex_list, "in loop around vertices", current);
+ synfigapp::ValueDesc value_prev(*prev);
+ synfigapp::ValueDesc value_desc(*iter);
+ synfigapp::ValueDesc value_next(*next);
+
+ assert(value_desc.is_valid());
+ assert(value_next.is_valid());
+ assert(value_prev.is_valid());
+
+ // synfig::info("-------");
+ // synfig::info(__FILE__":%d: value_prev 0x%08X:%d",__LINE__,value_prev.get_parent_value_node().get(),value_prev.get_index());
+ // synfig::info(__FILE__":%d: value_desc 0x%08X:%d",__LINE__,value_desc.get_parent_value_node().get(),value_desc.get_index());
+ // synfig::info(__FILE__":%d: value_next 0x%08X:%d",__LINE__,value_next.get_parent_value_node().get(),value_next.get_index());
+
+ /*
+ if(value_prev.parent_is_value_node() && value_desc.parent_is_value_node() && value_next.parent_is_value_node())
+ {
+ // Remove random extraneous vertices
+ if(value_prev.get_parent_value_node()==value_next.get_parent_value_node() &&
+ value_prev.get_parent_value_node()!=value_desc.get_parent_value_node())
+ {
+ vertex_list.erase(iter);
+ done=false;
+ break;
+ }
+ }
+ */
+
+ // // Remove duplicate vertices
+
+ // // if previous is the same as current or
+ // // current is the same as next, remove current
+ // if(value_prev.get_value_node()==value_desc.get_value_node() ||
+ // value_desc.get_value_node()==value_next.get_value_node())
+ // {
+ // vertex_list.erase(iter);
+ // done=false;
+ // printf("erased node - i = %d\n", i);
+ // break;
+ // }
+
+ // // if previous is the same as next, remove previous? or next?
+ // if(value_prev.get_value_node()==value_next.get_value_node())
+ // {
+ // vertex_list.erase(next);
+ // // vertex_list.erase(prev);
+ // done=false;
+ // printf("erased node - i = %d\n", i);
+ // break;
+ // }
+
+ // if 'this' and 'next' both have parents
+ if (value_desc.parent_is_value_node() && value_next.parent_is_value_node())
+ {
+ // if they are both on the same bline - this has been handled by new code above
+ if (value_desc.get_parent_value_node() == value_next.get_parent_value_node())
+ {
+ // // if (next != vertex_list.end())
+ // {
+ // printf("parent loop is %d and node loop is ??\n",
+ // (*(value_desc.get_parent_value_node()))(get_time()).get_loop()
+ // // value_desc.get_value_node().get_loop(),
+ // );
+ //
+ // // Fill in missing vertices
+ // // \todo take loops into account: seeing (15, 2, 3, 4) probably means that (0, 1) is missing, not 14 through 3
+ // if(value_desc.get_index()<value_next.get_index()-1)
+ // {
+ // debug_show_vertex_list(i, vertex_list,
+ // strprintf("same parent, different points this %d < next-1 %d",
+ // value_desc.get_index(), ((value_next.get_index()-1))),
+ // current);
+ // for (int index = value_desc.get_index()+1; index < value_next.get_index(); index++)
+ // {
+ // printf("inserting up %d\n", index);
+ // vertex_list.insert(next, synfigapp::ValueDesc(value_desc.get_parent_value_node(), index));
+ // }
+ // debug_show_vertex_list(i, vertex_list, "new list", current);
+ // done=false;
+ // break;
+ // }
+ // if(value_next.get_index()<value_desc.get_index()-1)
+ // {
+ // debug_show_vertex_list(i, vertex_list,
+ // strprintf("same parent, different points next %d < this-1 %d",
+ // value_next.get_index(), ((value_desc.get_index()-1))),
+ // current);
+ // for (int index = value_desc.get_index()-1; index > value_next.get_index(); index--)
+ // {
+ // printf("inserting down %d\n", index);
+ // vertex_list.insert(next, synfigapp::ValueDesc(value_desc.get_parent_value_node(), index));
+ // }
+ // debug_show_vertex_list(i, vertex_list, "new list", current);
+ // done=false;
+ // break;
+ // }
+ // }
+ }
+ // 'this' and 'next' have different parents
+ else
+ {
+ ValueNode::Handle v1 = value_desc.get_value_node();
+ ValueNode::Handle v2 = value_desc.get_parent_value_node();
+ if (v1 == v2)
+ printf("same\n");
+ else
+ printf("different\n");
+
+ if (value_desc.get_value_node() != value_next.get_value_node())
+ {
+ // Ensure that connections between blines are properly connected
+ BLinePoint vertex(value_desc.get_value(get_time()).get(BLinePoint()));
+ BLinePoint vertex_next(value_next.get_value(get_time()).get(BLinePoint()));
+
+ //synfig::info("--------");
+ //synfig::info(__FILE__":%d: vertex: [%f, %f]",__LINE__,vertex.get_vertex()[0],vertex.get_vertex()[1]);
+ //synfig::info(__FILE__":%d: vertex_next: [%f, %f]",__LINE__,vertex_next.get_vertex()[0],vertex_next.get_vertex()[1]);
+
+ // if this vertex is close to the next one, replace this vertex with a new one
+ // and erase the next one
+ printf("this point is %5.2f from the next point - compare with %5.2f\n",
+ (vertex.get_vertex()-vertex_next.get_vertex()).mag_squared(),
+ radius*radius);
+ if((vertex.get_vertex()-vertex_next.get_vertex()).mag_squared()<radius*radius)
+ {
+ printf("in one - it's close\n");
+ ValueNode_Composite::Handle value_node;
+ ValueNode_Composite::Handle value_node_next;
+ value_node=ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node().clone());
+ value_node_next=ValueNode_Composite::Handle::cast_dynamic(value_next.get_value_node().clone());
+ if(!value_node || !value_node_next)
+ {
+ synfig::info(__FILE__":%d: Unable to properly connect blines.",__LINE__);
+ continue;
+ }
+ // \todo if next isn't split, don't we want to copy its 'Tangent 1' instead?
+ value_node->set_link(5,value_node_next->get_link(5)); // Tangent 2
+ value_node->set_link(3,ValueNode_Const::create(true)); // Split Tangents
+
+ // get_canvas_interface()->auto_export(value_node);
+ printf("exporting\n");
+ get_canvas_interface()->add_value_node(value_node,value_node->get_id() + strprintf("foo %d", rand()));
+
+ assert(value_node->is_exported());
+ // replace 'this' with the new valuenode
+ *iter=synfigapp::ValueDesc(get_canvas(),value_node->get_id());
+ printf("erasing next\n");
+ printf("erasing next point\n");
+ vertex_list.erase(next);
+ done=false;
+ break;
+ } // this vertex isn't close to the next one
+ else if (value_prev.parent_is_value_node())
+ {
+ printf("in two - it's far\n");
+ // \todo this only makes sense if prev is on the same bline
+ printf("this is index %d\n", value_desc.get_index());
+ printf("prev is index %d\n", value_prev.get_index());
+ bool positive_trend(value_desc.get_index()>value_prev.get_index());
+
+ if(positive_trend)
+ {
+ printf("positive trend\n");
+ printf("comparing index %d < link_count()-1 = %d-1 = %d\n",
+ value_desc.get_index(),
+ LinkableValueNode::Handle::cast_static(value_desc.get_parent_value_node())->link_count(),
+ LinkableValueNode::Handle::cast_static(value_desc.get_parent_value_node())->link_count()-1);
+ if (value_desc.get_index()<LinkableValueNode::Handle::cast_static(value_desc.get_parent_value_node())->link_count()-1)
+ {
+ printf("in two - b\n");
+ printf("inserting node with index %d\n", value_desc.get_index()+1);
+ vertex_list.insert(next,
+ synfigapp::ValueDesc(value_desc.get_parent_value_node(),
+ value_desc.get_index()+1));
+ done=false;
+ break;
+ }
+ }
+ else // !positive_trend
+ {
+ printf("negative trend\n");
+ if(value_desc.get_index()>0)
+ {
+ printf("in two - a\n");
+ printf("inserting node on this line with index %d\n",
+ value_desc.get_index()-1);
+ vertex_list.insert(next,
+ synfigapp::ValueDesc(value_desc.get_parent_value_node(),
+ value_desc.get_index()-1));
+ done=false;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }