X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fmodules%2Fmod_geometry%2Foutline.cpp;h=e540fa5fa94a5fe983474d289055c47da38fd597;hb=c74ce4738eff208de3bef4b63929b6975a896e93;hp=c4252b1ff350f42a6ad46c081c91d995593b157b;hpb=5ddcf36f04cfbd10fabda4e3c5633cb27cdd4c0a;p=synfig.git diff --git a/synfig-core/trunk/src/modules/mod_geometry/outline.cpp b/synfig-core/trunk/src/modules/mod_geometry/outline.cpp index c4252b1..e540fa5 100644 --- a/synfig-core/trunk/src/modules/mod_geometry/outline.cpp +++ b/synfig-core/trunk/src/modules/mod_geometry/outline.cpp @@ -1,8 +1,8 @@ /* === S Y N F I G ========================================================= */ -/*! \file bline.cpp +/*! \file outline.cpp ** \brief Template ** -** $Id: outline.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $ +** $Id$ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley @@ -69,7 +69,7 @@ SYNFIG_LAYER_SET_NAME(Outline,"outline"); SYNFIG_LAYER_SET_LOCAL_NAME(Outline,_("Outline")); SYNFIG_LAYER_SET_CATEGORY(Outline,_("Geometry")); SYNFIG_LAYER_SET_VERSION(Outline,"0.2"); -SYNFIG_LAYER_SET_CVS_ID(Outline,"$Id: outline.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $"); +SYNFIG_LAYER_SET_CVS_ID(Outline,"$Id$"); /* === P R O C E D U R E S ================================================= */ @@ -171,6 +171,13 @@ void Outline::sync() { clear(); + + if (!bline.get_list().size()) + { + synfig::warning(string("Outline::sync():")+_("No verticies in outline " + string("\"") + get_description() + string("\""))); + return; + } + try { #if 1 @@ -194,9 +201,24 @@ Outline::sync() else iter=next++; + // iter next + // ---- ---- + // looped nth 1st + // !looped 1st 2nd + + Vector first_tangent=bline.front().get_tangent2(); Vector last_tangent=iter->get_tangent1(); - for(bool first=!loop;next!=end;iter=next++,first=false) + // if we are looped and drawing sharp cusps, we'll need a value for the incoming tangent + if (loop && sharp_cusps && last_tangent.is_equal_to(Vector::zero())) + { + hermite curve((iter-1)->get_vertex(), iter->get_vertex(), (iter-1)->get_tangent2(), iter->get_tangent1()); + const derivative< hermite > deriv(curve); + last_tangent=deriv(1.0-CUSP_TANGENT_ADJUST); + } + + // `first' is for making the cusps; don't do that for the first point if we're not looped + for(bool first=!loop; next!=end; iter=next++) { Vector prev_t(iter->get_tangent1()); Vector iter_t(iter->get_tangent2()); @@ -204,10 +226,16 @@ Outline::sync() bool split_flag(iter->get_split_tangent_flag()); + // if iter.t2 == 0 and next.t1 == 0, this is a straight line if(iter_t.is_equal_to(Vector::zero()) && next_t.is_equal_to(Vector::zero())) { iter_t=next_t=next->get_vertex()-iter->get_vertex(); - split_flag=true; + // split_flag=true; + + // if the two points are on top of each other, ignore this segment + // leave `first' true if was before + if (iter_t.is_equal_to(Vector::zero())) + continue; } // Setup the curve @@ -224,6 +252,9 @@ Outline::sync() const derivative< hermite > deriv(curve); + if (first) + first_tangent = deriv(CUSP_TANGENT_ADJUST); + // Make cusps as necessary if(!first && sharp_cusps && split_flag && (!prev_t.is_equal_to(iter_t) || iter_t.is_equal_to(Vector::zero())) && !last_tangent.is_equal_to(Vector::zero())) { @@ -268,7 +299,7 @@ Outline::sync() const float length(curve.length()); float dist(0); Point lastpoint; - for(float n=0.0f;n<1.0f;n+=1.0f/SAMPLES) + for(float n=0.0f;n<0.999999f;n+=1.0f/SAMPLES) { const Vector d(deriv(n>CUSP_TANGENT_ADJUST?n:CUSP_TANGENT_ADJUST).perp().norm()); const Vector p(curve(n)); @@ -285,7 +316,7 @@ Outline::sync() } } else - for(float n=0.0f;n<1.0f;n+=1.0f/SAMPLES) + for(float n=0.0f;n<0.999999f;n+=1.0f/SAMPLES) { const Vector d(deriv(n>CUSP_TANGENT_ADJUST?n:CUSP_TANGENT_ADJUST).perp().norm()); const Vector p(curve(n)); @@ -297,6 +328,8 @@ Outline::sync() last_tangent=deriv(1.0-CUSP_TANGENT_ADJUST); side_a.push_back(curve(1.0)+last_tangent.perp().norm()*next_w); side_b.push_back(curve(1.0)-last_tangent.perp().norm()*next_w); + + first=false; } if(loop) @@ -324,11 +357,8 @@ Outline::sync() -tangent*w*ROUND_END_FACTOR ); - for(float n=0.0f;n<1.0f;n+=1.0f/SAMPLES) + for(float n=0.0f;n<0.999999f;n+=1.0f/SAMPLES) side_a.push_back(curve(n)); - - // remove the last point - side_a.pop_back(); } for(;!side_b.empty();side_b.pop_back()) @@ -341,7 +371,7 @@ Outline::sync() side_a.pop_back(); const Point vertex(bline.front().get_vertex()); - const Vector tangent(bline.front().get_tangent2().norm()); + const Vector tangent(first_tangent.norm()); const float w((bline.front().get_width()*width)*0.5f+expand); hermite curve( @@ -351,17 +381,14 @@ Outline::sync() tangent*w*ROUND_END_FACTOR ); - for(float n=0.0f;n<1.0f;n+=1.0f/SAMPLES) + for(float n=0.0f;n<0.999999f;n+=1.0f/SAMPLES) side_a.push_back(curve(n)); - - // remove the last point - side_a.pop_back(); } add_polygon(side_a); -#else +#else /* 1 */ bool loop_; if(bline.get_contained_type()==ValueBase::TYPE_BLINEPOINT) @@ -623,12 +650,12 @@ Outline::sync() } //synfig::info("BLEHH__________--- x:%f, y:%f",vector_list.front()[0],vector_list.front()[1]); } -#endif +#endif /* _DEBUG */ add_polygon(vector_list); -#endif +#endif /* 1 */ } catch (...) { synfig::error("Outline::sync(): Exception thrown"); throw; } } @@ -701,7 +728,7 @@ Outline::set_param(const String & param, const ValueBase &value) return true; } - if( param=="width_list" && value.same_as(width_list)) + if( param=="width_list" && value.same_type_as(width_list)) { width_list=value; //sync();