Code

remove many unnecessary to_2geom and from_2geom calls
[inkscape.git] / src / splivarot.cpp
index b8c2bb2f0f891eca1c4d776a7fe4d0b9df30ab3e..47051be2be132a954340c3d8ee223dccc8e1b068 100644 (file)
@@ -461,7 +461,7 @@ sp_selected_path_boolop(bool_op bop, const unsigned int verb, const Glib::ustrin
     // adjust style properties that depend on a possible transform in the source object in order
     // to get a correct style attribute for the new path
     SPItem* item_source = SP_ITEM(source);
-    NR::Matrix i2root = from_2geom(sp_item_i2root_affine(item_source));
+    NR::Matrix i2root(sp_item_i2root_affine(item_source));
     sp_item_adjust_stroke(item_source, NR::expansion(i2root));
     sp_item_adjust_pattern(item_source, i2root);
     sp_item_adjust_gradient(item_source, i2root);
@@ -493,7 +493,7 @@ sp_selected_path_boolop(bool_op bop, const unsigned int verb, const Glib::ustrin
 
     // premultiply by the inverse of parent's repr
     SPItem *parent_item = SP_ITEM(sp_desktop_document(desktop)->getObjectByRepr(parent));
-    NR::Matrix local = from_2geom(sp_item_i2doc_affine(parent_item));
+    NR::Matrix local (sp_item_i2doc_affine(parent_item));
     gchar *transform = sp_svg_transform_write(local.inverse());
 
     // now that we have the result, add it on the canvas
@@ -607,7 +607,7 @@ void sp_selected_path_outline_add_marker( SPObject *marker_object, Geom::Matrix
     SPMarker* marker = SP_MARKER (marker_object);
     SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (marker_object));
 
-    NR::Matrix tr(from_2geom(marker_transform));
+    NR::Matrix tr(marker_transform);
 
     if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
         tr = stroke_scale * tr;
@@ -1610,7 +1610,7 @@ sp_selected_path_simplify_items(SPDesktop *desktop,
 
   bool didSomething = false;
 
-  NR::Maybe<NR::Rect> selectionBbox = selection->bounds();
+  boost::optional<NR::Rect> selectionBbox = selection->bounds();
   if (!selectionBbox) {
     return false;
   }
@@ -1631,7 +1631,7 @@ sp_selected_path_simplify_items(SPDesktop *desktop,
           continue;
 
       if (simplifyIndividualPaths) {
-          NR::Maybe<NR::Rect> itemBbox = item->getBounds(from_2geom(sp_item_i2d_affine(item)));
+          boost::optional<NR::Rect> itemBbox = item->getBounds(sp_item_i2d_affine(item));
           if (itemBbox) {
               simplifySize      = L2(itemBbox->dimensions());
           } else {
@@ -1748,79 +1748,55 @@ Path *
 Path_for_item(SPItem *item, bool doTransformation, bool transformFull)
 {
     SPCurve *curve = curve_for_item(item);
+
     if (curve == NULL)
         return NULL;
-
-    Geom::PathVector pathv = pathvector_for_curve(item, curve, doTransformation, transformFull);
-
-    Path *dest = new Path;
-    dest->LoadPathVector(pathv);
-
+    
+    Geom::PathVector *pathv = pathvector_for_curve(item, curve, doTransformation, transformFull, Geom::identity(), Geom::identity());
     curve->unref();
     
+    Path *dest = new Path;
+    dest->LoadPathVector(*pathv);    
+    delete pathv;
+    
     return dest;
 }
 
-/* 
- * This function always returns a new NArtBpath, the caller must g_free the returned path!
-*/
-NArtBpath *
-bpath_for_curve(SPItem *item, SPCurve *curve, bool doTransformation, bool transformFull, NR::Matrix extraPreAffine, NR::Matrix extraPostAffine)
-{
-    if (curve == NULL)
-        return NULL;
-
-    NArtBpath *bpath = BPath_from_2GeomPath(curve->get_pathvector());
-    if (bpath == NULL) {
-        return NULL;
-    }
-
-    NArtBpath *new_bpath; // we will get a duplicate which has to be freed at some point!
-    if (doTransformation) {
-        if (transformFull) {
-            new_bpath = nr_artpath_affine(bpath, extraPreAffine * from_2geom(sp_item_i2doc_affine(item)) * extraPostAffine);
-        } else {
-            new_bpath = nr_artpath_affine(bpath, extraPreAffine * item->transform * extraPostAffine);
-        }
-    } else {
-        new_bpath = nr_artpath_affine(bpath, extraPreAffine * NR::identity() * extraPostAffine);
-    }
-
-    g_free(bpath);
-    return new_bpath;
-}
-
 /* 
  * NOTE: Returns empty pathvector if curve == NULL
  * TODO: see if calling this method can be optimized. All the pathvector copying might be slow.
  */
-Geom::PathVector
-pathvector_for_curve(SPItem *item, SPCurve *curve, bool doTransformation, bool transformFull)
+Geom::PathVector*
+pathvector_for_curve(SPItem *item, SPCurve *curve, bool doTransformation, bool transformFull, Geom::Matrix extraPreAffine, Geom::Matrix extraPostAffine)
 {
     if (curve == NULL)
-        return Geom::PathVector();
+        return NULL;
 
+    Geom::PathVector *dest = new Geom::PathVector;    
+    *dest = curve->get_pathvector(); // Make a copy; must be freed by the caller!
+    
     if (doTransformation) {
         if (transformFull) {
-            return (curve->get_pathvector()) * sp_item_i2doc_affine(item);
+            *dest *= extraPreAffine * sp_item_i2doc_affine(item) * extraPostAffine;
         } else {
-            return (curve->get_pathvector()) * to_2geom(item->transform);
+            *dest *= extraPreAffine * (Geom::Matrix)item->transform * extraPostAffine;
         }
     } else {
-        return curve->get_pathvector();
+        *dest *= extraPreAffine * extraPostAffine;
     }
+    
+    return dest;
 }
 
 SPCurve* curve_for_item(SPItem *item)
 {
-    if (!item) {
-       return NULL;
-    }
-
+    if (!item) 
+        return NULL;
+    
     SPCurve *curve = NULL;
     if (SP_IS_SHAPE(item)) {
         if (SP_IS_PATH(item)) {
-               curve = sp_path_get_curve_for_edit(SP_PATH(item));
+            curve = sp_path_get_curve_for_edit(SP_PATH(item));
         } else {
             curve = sp_shape_get_curve(SP_SHAPE(item));
         }
@@ -1831,13 +1807,14 @@ SPCurve* curve_for_item(SPItem *item)
     }
     else if (SP_IS_IMAGE(item))
     {
-       curve = sp_image_get_curve(SP_IMAGE(item));
+    curve = sp_image_get_curve(SP_IMAGE(item));
     }
     
     return curve; // do not forget to unref the curve at some point!
 }
 
-Path *bpath_to_Path(NArtBpath const *bpath) {
+Path *bpath_to_Path(NArtBpath const *bpath) 
+{
     Path *dest = new Path;
     dest->SetBackData(false);
     {
@@ -1894,7 +1871,7 @@ Path *bpath_to_Path(NArtBpath const *bpath) {
     return dest;
 }
 
-NR::Maybe<Path::cut_position> get_nearest_position_on_Path(Path *path, NR::Point p, unsigned seg)
+boost::optional<Path::cut_position> get_nearest_position_on_Path(Path *path, NR::Point p, unsigned seg)
 {
     //get nearest position on path
     Path::cut_position pos = path->PointToCurvilignPosition(p, seg);