Code

Prevent localized doubles from being written into filter matrices
[inkscape.git] / src / unclump.cpp
index aebcfd9088f05f368f1f6e089259d18c503a774a..1039351a334b6f780b6d8d222fa18da2f963cb1b 100644 (file)
@@ -3,6 +3,8 @@
  */
 /* Authors:
  *   bulia byak
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2005 Authors
  * Released under GNU GPL, read the file 'COPYING' for more information
@@ -16,7 +18,7 @@
 // Taking bbox of an item is an expensive operation, and we need to do it many times, so here we
 // cache the centers, widths, and heights of items
 
-//FIXME: make a class with these cashes as members instead of globals 
+//FIXME: make a class with these cashes as members instead of globals
 std::map<const gchar *, Geom::Point> c_cache;
 std::map<const gchar *, Geom::Point> wh_cache;
 
@@ -26,18 +28,18 @@ Center of bbox of item
 Geom::Point
 unclump_center (SPItem *item)
 {
-    std::map<const gchar *, Geom::Point>::iterator i = c_cache.find(SP_OBJECT_ID(item));
+    std::map<const gchar *, Geom::Point>::iterator i = c_cache.find(item->getId());
     if ( i != c_cache.end() ) {
         return i->second;
     }
 
-    Geom::OptRect r = item->getBounds(sp_item_i2d_affine(item));
+    Geom::OptRect r = item->getBounds(item->i2d_affine());
     if (r) {
-       Geom::Point const c = r->midpoint();
-       c_cache[SP_OBJECT_ID(item)] = c;
-        return c; 
+        Geom::Point const c = r->midpoint();
+        c_cache[item->getId()] = c;
+        return c;
     } else {
-       // FIXME
+        // FIXME
         return Geom::Point(0, 0);
     }
 }
@@ -46,16 +48,16 @@ Geom::Point
 unclump_wh (SPItem *item)
 {
     Geom::Point wh;
-    std::map<const gchar *, Geom::Point>::iterator i = wh_cache.find(SP_OBJECT_ID(item));
+    std::map<const gchar *, Geom::Point>::iterator i = wh_cache.find(item->getId());
     if ( i != wh_cache.end() ) {
         wh = i->second;
     } else {
-        Geom::OptRect r = item->getBounds(sp_item_i2d_affine(item));
-       if (r) {
+        Geom::OptRect r = item->getBounds(item->i2d_affine());
+        if (r) {
             wh = r->dimensions();
-            wh_cache[SP_OBJECT_ID(item)] = wh;
+            wh_cache[item->getId()] = wh;
         } else {
-           wh = Geom::Point(0, 0);
+            wh = Geom::Point(0, 0);
         }
     }
 
@@ -63,7 +65,7 @@ unclump_wh (SPItem *item)
 }
 
 /**
-Distance between "edges" of item1 and item2. An item is considered to be an ellipse inscribed into its w/h, 
+Distance between "edges" of item1 and item2. An item is considered to be an ellipse inscribed into its w/h,
 so its radius (distance from center to edge) depends on the w/h and the angle towards the other item.
 May be negative if the edge of item1 is between the center and the edge of item2.
 */
@@ -287,15 +289,15 @@ unclump_push (SPItem *from, SPItem *what, double dist)
 
     Geom::Matrix move = Geom::Translate (by);
 
-    std::map<const gchar *, Geom::Point>::iterator i = c_cache.find(SP_OBJECT_ID(what));
+    std::map<const gchar *, Geom::Point>::iterator i = c_cache.find(what->getId());
     if ( i != c_cache.end() ) {
         i->second *= move;
     }
 
-    //g_print ("push %s at %g,%g from %g,%g by %g,%g, dist %g\n", SP_OBJECT_ID(what), it[Geom::X],it[Geom::Y], p[Geom::X],p[Geom::Y], by[Geom::X],by[Geom::Y], dist);
+    //g_print ("push %s at %g,%g from %g,%g by %g,%g, dist %g\n", what->getId(), it[Geom::X],it[Geom::Y], p[Geom::X],p[Geom::Y], by[Geom::X],by[Geom::Y], dist);
 
-    sp_item_set_i2d_affine(what, sp_item_i2d_affine(what) * move);
-    sp_item_write_transform(what, SP_OBJECT_REPR(what), what->transform, NULL);
+    what->set_i2d_affine(what->i2d_affine() * move);
+    what->doWriteTransform(SP_OBJECT_REPR(what), what->transform, NULL);
 }
 
 /**
@@ -310,22 +312,22 @@ unclump_pull (SPItem *to, SPItem *what, double dist)
 
     Geom::Matrix move = Geom::Translate (by);
 
-    std::map<const gchar *, Geom::Point>::iterator i = c_cache.find(SP_OBJECT_ID(what));
+    std::map<const gchar *, Geom::Point>::iterator i = c_cache.find(what->getId());
     if ( i != c_cache.end() ) {
         i->second *= move;
     }
 
-    //g_print ("pull %s at %g,%g to %g,%g by %g,%g, dist %g\n", SP_OBJECT_ID(what), it[Geom::X],it[Geom::Y], p[Geom::X],p[Geom::Y], by[Geom::X],by[Geom::Y], dist);
+    //g_print ("pull %s at %g,%g to %g,%g by %g,%g, dist %g\n", what->getId(), it[Geom::X],it[Geom::Y], p[Geom::X],p[Geom::Y], by[Geom::X],by[Geom::Y], dist);
 
-    sp_item_set_i2d_affine(what, sp_item_i2d_affine(what) * move);
-    sp_item_write_transform(what, SP_OBJECT_REPR(what), what->transform, NULL);
+    what->set_i2d_affine(what->i2d_affine() * move);
+    what->doWriteTransform(SP_OBJECT_REPR(what), what->transform, NULL);
 }
 
 
 /**
 Unclumps the items in \a items, reducing local unevenness in their distribution. Produces an effect
 similar to "engraver dots". The only distribution which is unchanged by unclumping is a hexagonal
-grid. May be called repeatedly for stronger effect. 
+grid. May be called repeatedly for stronger effect.
  */
 void
 unclump (GSList *items)
@@ -333,7 +335,7 @@ unclump (GSList *items)
     c_cache.clear();
     wh_cache.clear();
 
-    for (GSList *i = items; i != NULL; i = i->next) { //  for each original/clone x: 
+    for (GSList *i = items; i != NULL; i = i->next) { //  for each original/clone x:
         SPItem *item = SP_ITEM (i->data);
 
         GSList *nei = NULL;
@@ -353,7 +355,7 @@ unclump (GSList *items)
                 g_slist_free (rest);
                 break;
             }
-        } 
+        }
 
         if (g_slist_length (nei) >= 2) {
             double ave = unclump_average (item, nei);
@@ -364,12 +366,12 @@ unclump (GSList *items)
             double dist_closest = unclump_dist (closest, item);
             double dist_farest = unclump_dist (farest, item);
 
-            //g_print ("NEI %d for item %s    closest %s at %g  farest %s at %g  ave %g\n", g_slist_length(nei), SP_OBJECT_ID(item), SP_OBJECT_ID(closest), dist_closest, SP_OBJECT_ID(farest), dist_farest, ave);
+            //g_print ("NEI %d for item %s    closest %s at %g  farest %s at %g  ave %g\n", g_slist_length(nei), item->getId(), closest->getId(), dist_closest, farest->getId(), dist_farest, ave);
 
             if (fabs (ave) < 1e6 && fabs (dist_closest) < 1e6 && fabs (dist_farest) < 1e6) { // otherwise the items are bogus
                 // increase these coefficients to make unclumping more aggressive and less stable
                 // the pull coefficient is a bit bigger to counteract the long-term expansion trend
-                unclump_push (closest, item, 0.3 * (ave - dist_closest)); 
+                unclump_push (closest, item, 0.3 * (ave - dist_closest));
                 unclump_pull (farest, item, 0.35 * (dist_farest - ave));
             }
         }
@@ -385,4 +387,4 @@ unclump (GSList *items)
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :