Code

Use is_straight_curve() instead of three separate dynamic casts
authordvlierop2 <dvlierop2@users.sourceforge.net>
Tue, 5 Aug 2008 14:33:46 +0000 (14:33 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Tue, 5 Aug 2008 14:33:46 +0000 (14:33 +0000)
src/display/inkscape-cairo.cpp
src/display/nr-arena-shape.cpp
src/extension/internal/javafx-out.cpp
src/extension/internal/latex-pstricks.cpp
src/extension/internal/odf.cpp
src/extension/internal/pov-out.cpp
src/extension/internal/ps.cpp
src/helper/geom.cpp
src/livarot/PathCutting.cpp
src/sp-path.cpp
src/sp-polygon.cpp

index d4a9f7062b71572ea11777b34d2f4a28c957c8dd..8bc9eade2815fa61100229d68741289dd219a675 100644 (file)
@@ -27,6 +27,7 @@
 #include <2geom/path.h>
 #include <2geom/transforms.h>
 #include <2geom/sbasis-to-bezier.h>
+#include "helper/geom-curves.h"
 
 /** Creates a cairo context to render to the given pixblock on the given area */
 cairo_t *
@@ -74,9 +75,7 @@ nr_create_cairo_context (NRRectL *area, NRPixBlock *pb)
 static void
 feed_curve_to_cairo(cairo_t *cr, Geom::Curve const &c, Geom::Matrix const & trans, Geom::Rect view, bool optimize_stroke)
 {
-    if( dynamic_cast<Geom::LineSegment const*>(&c) ||
-        dynamic_cast<Geom::HLineSegment const*>(&c) ||
-        dynamic_cast<Geom::VLineSegment const*>(&c) )
+    if( is_straight_curve(c) )
     {
         Geom::Point end_tr = c.finalPoint() * trans;
         if (!optimize_stroke) {
index 325681650e17a36b868230b70a7958b4cddc804c..840f5044a8ad7189776d25fb05d957fa3e61778f 100644 (file)
@@ -32,6 +32,7 @@
 #include "prefs-utils.h"
 #include "inkscape-cairo.h"
 #include "helper/geom.h"
+#include "helper/geom-curves.h"
 #include "sp-filter.h"
 #include "sp-filter-reference.h"
 #include "display/nr-filter.h"
@@ -428,10 +429,7 @@ static bool has_inner_area(Geom::PathVector const & pv) {
 
     if ( (pv.size() == 1) && (pv.front().size() <= 1) ) {
         // vector has only one path with only one segment, see if that's a non-curve segment: that would mean no internal region
-        Geom::Curve const * c = & pv.front().front();
-        if ( dynamic_cast<Geom::LineSegment const*>(c) ||
-             dynamic_cast<Geom::HLineSegment const*>(c) ||
-             dynamic_cast<Geom::VLineSegment const*>(c) )
+        if ( is_straight_curve(pv.front().front()) )
         {
             return false;
         }
index 2e0f2d59fa528d4556615528a182c1e9b38ad7b4..29c2bdab0eafdb6da0fd42325a48d9e3386a4793 100644 (file)
@@ -30,6 +30,7 @@
 #include <2geom/bezier-curve.h>\r
 #include <2geom/hvlinesegment.h>\r
 #include "helper/geom.h"\r
+#include "helper/geom-curves.h"\r
 #include <io/sys.h>\r
 \r
 \r
@@ -473,9 +474,7 @@ bool JavaFXOutput::doCurve(SPItem *item, const String &id)
         for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)\r
             {\r
             //### LINE\r
-            if( dynamic_cast<Geom::LineSegment const *> (&*cit) ||\r
-                dynamic_cast<Geom::HLineSegment const *>(&*cit) ||\r
-                dynamic_cast<Geom::VLineSegment const *>(&*cit) )\r
+            if( is_straight_curve(*cit) )\r
                 {\r
                 Geom::Point p = cit->finalPoint();\r
                 out("            LineTo {\n");\r
index 9909d743685fdc7d5961ce805cd9ff2dce746dfe..c1dcec361b0ca28d249dbbf856d8a10cefe98556 100644 (file)
@@ -31,6 +31,7 @@
 #include <2geom/sbasis-to-bezier.h>
 #include <2geom/bezier-curve.h>
 #include <2geom/hvlinesegment.h>
+#include "helper/geom-curves.h"
 
 #include "sp-item.h"
 
@@ -305,9 +306,7 @@ PrintLatex::print_2geomcurve(SVGOStringStream &os, Geom::Curve const & c )
     using Geom::X;
     using Geom::Y;
 
-    if( dynamic_cast<Geom::LineSegment const*>(&c) ||
-        dynamic_cast<Geom::HLineSegment const*>(&c) ||
-        dynamic_cast<Geom::VLineSegment const*>(&c) )
+    if( is_straight_curve(c) )
     {
         os << "\\lineto(" << c.finalPoint()[X] << "," << c.finalPoint()[Y] << ")\n";
     }
index 2a71eabca4ec3f489c06259ded10dd2a20b5050b..02c3626bf9ba9f2255e0b3ee60810cac0f178e23 100644 (file)
@@ -56,6 +56,7 @@
 #include <2geom/hvlinesegment.h>
 #include <2geom/transforms.h>
 #include <helper/geom.h>
+#include "helper/geom-curves.h"
 #include "extension/system.h"
 
 #include "xml/repr.h"
@@ -1504,9 +1505,7 @@ writePath(Writer &outs, Geom::PathVector const &pathv,
 
             for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit) {
 
-                if( dynamic_cast<Geom::LineSegment const *> (&*cit) ||
-                    dynamic_cast<Geom::HLineSegment const *>(&*cit) ||
-                    dynamic_cast<Geom::VLineSegment const *>(&*cit) )
+                if( is_straight_curve(*cit) )
                 {
                     double destx = cit->finalPoint()[X];
                     double desty = cit->finalPoint()[Y];
index 01b8e64b5b3c91732fc4027c83c2fb853b20bbd7..ea746eae72adc4a601bf93294e963b413e61545b 100644 (file)
@@ -32,6 +32,7 @@
 #include <2geom/bezier-curve.h>
 #include <2geom/hvlinesegment.h>
 #include "helper/geom.h"
+#include "helper/geom-curves.h"
 #include <io/sys.h>
 
 #include <string>
@@ -352,9 +353,7 @@ bool PovOutput::doCurve(SPItem *item, const String &id)
         for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_closed(); ++cit)
                    {
 
-            if( dynamic_cast<Geom::LineSegment const *> (&*cit) ||
-                    dynamic_cast<Geom::HLineSegment const *>(&*cit) ||
-                    dynamic_cast<Geom::VLineSegment const *>(&*cit) )
+            if( is_straight_curve(*cit) )
                 {
                 Geom::Point p0 = cit->initialPoint();
                 Geom::Point p1 = cit->finalPoint();
index cad5769758aa45cec80861276b07c070bcfebb6d..6f1405de206e97139820c67f9d6afb9afda6e73a 100644 (file)
@@ -78,6 +78,7 @@
 #include <2geom/sbasis-to-bezier.h>
 #include <2geom/bezier-curve.h>
 #include <2geom/hvlinesegment.h>
+#include "helper/geom-curves.h"
 
 /*
 using std::atof;
@@ -1465,9 +1466,7 @@ PrintPS::print_2geomcurve(SVGOStringStream &os, Geom::Curve const & c )
     using Geom::X;
     using Geom::Y;
 
-    if( dynamic_cast<Geom::LineSegment const*>(&c) ||
-        dynamic_cast<Geom::HLineSegment const*>(&c) ||
-        dynamic_cast<Geom::VLineSegment const*>(&c) )
+    if( is_straight_curve(c) )
     {
         os << c.finalPoint()[X] << " " << c.finalPoint()[Y] << " lineto\n";
     }
index ac8930412a62cb53c45c241ee477ef3557532850..bf487f65222a5d80e3ab0ee20497d47e4bb10c74 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include "helper/geom.h"
+#include "helper/geom-curves.h"
 #include <typeinfo>
 #include <2geom/pathvector.h>
 #include <2geom/path.h>
@@ -173,9 +174,7 @@ bounds_exact_transformed(Geom::PathVector const & pv, Geom::Matrix const & t)
         for (Geom::Path::const_iterator cit = it->begin(); cit != it->end_open(); ++cit) {
             Geom::Curve const &c = *cit;
 
-            if( dynamic_cast<Geom::LineSegment const*>(&c) ||
-                dynamic_cast<Geom::HLineSegment const*>(&c) ||
-                dynamic_cast<Geom::VLineSegment const*>(&c)    )
+            if( is_straight_curve(c) )
             {
                 bbox.expandTo( c.finalPoint() * t );
             }
@@ -363,9 +362,7 @@ geom_curve_bbox_wind_distance(Geom::Curve const & c, Geom::Matrix const &m,
                  Geom::Coord tolerance, Geom::Rect const *viewbox,
                  Geom::Point &p0) // pass p0 through as it represents the last endpoint added (the finalPoint of last curve)
 {
-    if( dynamic_cast<Geom::LineSegment const*>(&c) ||
-        dynamic_cast<Geom::HLineSegment const*>(&c) ||
-        dynamic_cast<Geom::VLineSegment const*>(&c) )
+    if( is_straight_curve(c) )
     {
         Geom::Point pe = c.finalPoint() * m;
         if (bbox) {
@@ -509,10 +506,8 @@ pathv_to_linear_and_cubic_beziers( Geom::PathVector const &pathv )
         output.back().close( pit->closed() );
 
         for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_open(); ++cit) {
-            if( dynamic_cast<Geom::CubicBezier const*>(&*cit) ||
-                dynamic_cast<Geom::LineSegment const*>(&*cit) ||
-                dynamic_cast<Geom::HLineSegment const*>(&*cit) ||
-                dynamic_cast<Geom::VLineSegment const*>(&*cit) )
+            if( dynamic_cast<Geom::CubicBezier const*>(&*cit) || 
+                is_straight_curve(*cit) )
             {
                 output.back().append(*cit);
             }
index 3a7bd71adf98aefeaf00ea46b6ab07bdf23e63ca..47956031f55fcbaa6670f2de86b78da9f9f63b4a 100644 (file)
@@ -28,6 +28,7 @@
 #include <2geom/sbasis-to-bezier.h>
 #include <2geom/curves.h>
 #include "../display/canvas-bpath.h"
+#include "helper/geom-curves.h"
 
 void  Path::DashPolyline(float head,float tail,float body,int nbD,float *dashs,bool stPlain,float stOffset)
 {
@@ -379,9 +380,7 @@ Path::MakePathVector()
 
 void  Path::AddCurve(Geom::Curve const &c)
 {
-    if( dynamic_cast<Geom::LineSegment const*>(&c) ||
-        dynamic_cast<Geom::HLineSegment const*>(&c) ||
-        dynamic_cast<Geom::VLineSegment const*>(&c) )
+    if( is_straight_curve(c) )
     {
         LineTo( from_2geom(c.finalPoint()) );
     }
index e641632d910751e93e8b21f0edc79dc70a2873d4..e0e10b6deba7c740fab38769eb3d859766576bb6 100644 (file)
@@ -25,6 +25,7 @@
 #include <2geom/pathvector.h>
 #include <2geom/bezier-curve.h>
 #include <2geom/hvlinesegment.h>
+#include "helper/geom-curves.h"
 
 #include "svg/svg.h"
 #include "xml/repr.h"
@@ -157,9 +158,7 @@ sp_path_convert_to_guides(SPItem *item)
     for(Geom::PathVector::const_iterator pit = pv.begin(); pit != pv.end(); ++pit) {
         for(Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_default(); ++cit) {
             // only add curves for straight line segments
-            if( dynamic_cast<Geom::LineSegment const *>(&*cit) ||
-                dynamic_cast<Geom::HLineSegment const *>(&*cit) ||
-                dynamic_cast<Geom::VLineSegment const *>(&*cit) )
+            if( is_straight_curve(*cit) )
             {
                 pts.push_back(std::make_pair(cit->initialPoint() * i2d, cit->finalPoint() * i2d));
             }
index fddc9d1dba7d712e0971d638dfa0056d93d62075..014c68c9b75652ba8af992a904325b2c0daca8db 100644 (file)
@@ -21,6 +21,7 @@
 #include <2geom/pathvector.h>
 #include <2geom/bezier-curve.h>
 #include <2geom/hvlinesegment.h>
+#include "helper/geom-curves.h"
 #include "svg/stringstream.h"
 #include "xml/repr.h"
 #include "document.h"
@@ -98,9 +99,7 @@ static gchar *sp_svg_write_polygon(Geom::PathVector const & pathv)
 
     for (Geom::PathVector::const_iterator pit = pathv.begin(); pit != pathv.end(); ++pit) {
         for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_default(); ++cit) {
-            if ( dynamic_cast<Geom::LineSegment const *>(&*cit) ||
-                 dynamic_cast<Geom::HLineSegment const *>(&*cit) ||
-                 dynamic_cast<Geom::VLineSegment const *>(&*cit) )
+            if ( is_straight_curve(*cit) )
             {
                 os << cit->finalPoint()[0] << "," << cit->finalPoint()[1] << " ";
             } else {