Code

Extensions. XAML export improvements.
[inkscape.git] / src / live_effects / lpegroupbbox.cpp
index e9cf050994ebec03c81d29d923adc241ac72acfc..e6fc95f866e2ec01aee2ed4b09c12e1757f2bb65 100644 (file)
@@ -1,7 +1,6 @@
-#define INKSCAPE_LPEGROUPBBOX_CPP
-
 /*
  * Copyright (C) Steren Giannini 2008 <steren.giannini@gmail.com>
+ *   Abhishek Sharma
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -9,32 +8,42 @@
 #include "live_effects/lpegroupbbox.h"
 
 #include "sp-item.h"
-#include "libnr/nr-matrix-fns.h"
-#include "libnr/n-art-bpath-2geom.h"
 
 namespace Inkscape {
 namespace LivePathEffect {
 
+/**
+ * \brief  Updates the \c boundingbox_X and \c boundingbox_Y values from the geometric bounding box of \c lpeitem.
+ *
+ * \pre   lpeitem must have an existing geometric boundingbox (usually this is guaranteed when: \code SP_SHAPE(lpeitem)->curve != NULL \endcode )
+          It's not possible to run LPEs on items without their original-d having a bbox.
+ * \param lpeitem   This is not allowed to be NULL.
+ * \param absolute  Determines whether the bbox should be calculated of the untransformed lpeitem (\c absolute = \c false)
+ *                  or of the transformed lpeitem (\c absolute = \c true) using sp_item_i2doc_affine.
+ * \post Updated values of boundingbox_X and boundingbox_Y. These intervals are set to empty intervals when the precondition is not met.
+ */
 void
 GroupBBoxEffect::original_bbox(SPLPEItem *lpeitem, bool absolute)
 {
     // Get item bounding box
     SPItem* item = SP_ITEM(lpeitem);
     
-    NR::Matrix transform;
+    Geom::Matrix transform;
     if (absolute) {
-        transform = from_2geom(sp_item_i2doc_affine(item));
+        transform = item->i2doc_affine();
     }
     else {
-        transform = NR::identity();
+        transform = Geom::identity();
     }
-    
-    NR::Maybe<NR::Rect> itemBBox = item->getBounds(transform, SPItem::GEOMETRIC_BBOX);
 
-    // NR to Geom glue
-    Geom::Rect geomBBox = Geom::Rect(itemBBox->min(), itemBBox->max());
-    boundingbox_X = geomBBox[Geom::X];
-    boundingbox_Y = geomBBox[Geom::Y];
+    Geom::OptRect bbox = item->getBounds(transform, SPItem::GEOMETRIC_BBOX);
+    if (bbox) {
+        boundingbox_X = (*bbox)[Geom::X];
+        boundingbox_Y = (*bbox)[Geom::Y];
+    } else {
+        boundingbox_X = Geom::Interval();
+        boundingbox_Y = Geom::Interval();
+    }
 }
 
 } // namespace LivePathEffect