Module: synfig Branch: genete_width_points Commit: bf0d95e6edd5fde267b262c80d81484729591c49 URL: http://synfig.git.sourceforge.net/git/gitweb.cgi?p=synfig;a=commit;h=bf0d95e6edd5fde267b262c80d81484729591c49
Author: Carlos Lopez <car...@pcnuevo.(none)> Date: Mon Aug 3 11:15:55 2009 +0200 Try to not duplicate code. Maybe this function should go in a separate file. --- .../src/modules/mod_geometry/enhanced_outline.cpp | 61 +------------------- .../trunk/src/modules/mod_geometry/outline.cpp | 3 +- .../trunk/src/modules/mod_geometry/outline.h | 9 +++ 3 files changed, 14 insertions(+), 59 deletions(-) diff --git a/synfig-core/trunk/src/modules/mod_geometry/enhanced_outline.cpp b/synfig-core/trunk/src/modules/mod_geometry/enhanced_outline.cpp index 481a43a..1a1871d 100644 --- a/synfig-core/trunk/src/modules/mod_geometry/enhanced_outline.cpp +++ b/synfig-core/trunk/src/modules/mod_geometry/enhanced_outline.cpp @@ -34,6 +34,7 @@ #endif #include "enhanced_outline.h" +#include "outline.h" // hack to use line_intersection #include <synfig/string.h> #include <synfig/time.h> #include <synfig/context.h> @@ -76,62 +77,6 @@ SYNFIG_LAYER_SET_CVS_ID(EnhancedOutline,"$Id$"); /* === P R O C E D U R E S ================================================= */ -// This function was adapted from what was -// described on http://www.whisqu.se/per/docs/math28.htm -Point line_intersection2( - const Point& p1, - const Vector& t1, - const Point& p2, - const Vector& t2 -) -{ - const float& x0(p1[0]); - const float& y0(p1[1]); - - const float x1(p1[0]+t1[0]); - const float y1(p1[1]+t1[1]); - - const float& x2(p2[0]); - const float& y2(p2[1]); - - const float x3(p2[0]+t2[0]); - const float y3(p2[1]+t2[1]); - - const float near_infinity((float)1e+10); - - float m1,m2; // the slopes of each line - - // compute slopes, note the kluge for infinity, however, this will - // be close enough - - if ((x1-x0)!=0) - m1 = (y1-y0)/(x1-x0); - else - m1 = near_infinity; - - if ((x3-x2)!=0) - m2 = (y3-y2)/(x3-x2); - else - m2 = near_infinity; - - // compute constants - const float& a1(m1); - const float& a2(m2); - const float b1(-1.0f); - const float b2(-1.0f); - const float c1(y0-m1*x0); - const float c2(y2-m2*x2); - - // compute the inverse of the determinate - const float det_inv(1.0f/(a1*b2 - a2*b1)); - - // use Kramers rule to compute the intersection - return Point( - ((b1*c2 - b2*c1)*det_inv), - ((a2*c1 - a1*c2)*det_inv) - ); -} // end Intersect_Lines - /* === M E T H O D S ======================================================= */ @@ -294,14 +239,14 @@ EnhancedOutline::sync() const Point p1(iter->get_vertex()+t1*iter_w); const Point p2(iter->get_vertex()+t2*iter_w); - side_a.push_back(line_intersection2(p1,last_tangent,p2,curr_tangent)); + side_a.push_back(line_intersection(p1,last_tangent,p2,curr_tangent)); } else if(cross<-CUSP_THRESHOLD) { const Point p1(iter->get_vertex()-t1*iter_w); const Point p2(iter->get_vertex()-t2*iter_w); - side_b.push_back(line_intersection2(p1,last_tangent,p2,curr_tangent)); + side_b.push_back(line_intersection(p1,last_tangent,p2,curr_tangent)); } else if(cross>0 && perp>1) { diff --git a/synfig-core/trunk/src/modules/mod_geometry/outline.cpp b/synfig-core/trunk/src/modules/mod_geometry/outline.cpp index e84effb..2658931 100644 --- a/synfig-core/trunk/src/modules/mod_geometry/outline.cpp +++ b/synfig-core/trunk/src/modules/mod_geometry/outline.cpp @@ -52,6 +52,7 @@ #endif using namespace etl; +using namespace synfig; /* === M A C R O S ========================================================= */ @@ -76,7 +77,7 @@ SYNFIG_LAYER_SET_CVS_ID(Outline,"$Id$"); // This function was adapted from what was // described on http://www.whisqu.se/per/docs/math28.htm -Point line_intersection( +Point synfig::line_intersection( const Point& p1, const Vector& t1, const Point& p2, diff --git a/synfig-core/trunk/src/modules/mod_geometry/outline.h b/synfig-core/trunk/src/modules/mod_geometry/outline.h index bf1a54f..57ac652 100644 --- a/synfig-core/trunk/src/modules/mod_geometry/outline.h +++ b/synfig-core/trunk/src/modules/mod_geometry/outline.h @@ -43,6 +43,15 @@ using namespace synfig; using namespace std; using namespace etl; +namespace synfig { +Point line_intersection( + const Point& p1, + const Vector& t1, + const Point& p2, + const Vector& t2 +); +}; + class Outline : public synfig::Layer_Polygon { SYNFIG_LAYER_MODULE_EXT ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Synfig-devl mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/synfig-devl
