summaryrefslogtreecommitdiffstats
path: root/src/unclump.cpp
diff options
context:
space:
mode:
authorMarc Jeanmougin <mc@localhost.localdomain>2015-02-17 02:00:37 +0000
committerMarc Jeanmougin <mc@localhost.localdomain>2015-02-17 02:00:37 +0000
commita7f2b2ba3f13ceb60376802f4a31e104153839e8 (patch)
tree6db393e9e5a0a9ab7916a0e7ed29d875efa39ea1 /src/unclump.cpp
parentdevice-manager: Get rid of GLists (diff)
downloadinkscape-a7f2b2ba3f13ceb60376802f4a31e104153839e8.tar.gz
inkscape-a7f2b2ba3f13ceb60376802f4a31e104153839e8.zip
At first, I was thinking "I just have to go to the selection file, and change that GSList* with a std::list, then resolve the few problems"
So, i tried that. And I will continue tomorrow, and the days after, on and on. (bzr r13922.1.1)
Diffstat (limited to 'src/unclump.cpp')
-rw-r--r--src/unclump.cpp57
1 files changed, 26 insertions, 31 deletions
diff --git a/src/unclump.cpp b/src/unclump.cpp
index 940369d7a..d1cfc6628 100644
--- a/src/unclump.cpp
+++ b/src/unclump.cpp
@@ -168,13 +168,12 @@ unclump_dist (SPItem *item1, SPItem *item2)
/**
Average unclump_dist from item to others
*/
-static double unclump_average (SPItem *item, GSList *others)
+static double unclump_average (SPItem *item, SelContainer &others)
{
int n = 0;
double sum = 0;
-
- for (GSList *i = others; i != NULL; i = i->next) {
- SPItem *other = SP_ITEM (i->data);
+ for (SelContainer::const_iterator i = others.begin(); i != others.end();i++) {
+ SPItem *other = SP_ITEM (*i);
if (other == item)
continue;
@@ -192,13 +191,13 @@ static double unclump_average (SPItem *item, GSList *others)
/**
Closest to item among others
*/
-static SPItem *unclump_closest (SPItem *item, GSList *others)
+static SPItem *unclump_closest (SPItem *item, SelContainer &others)
{
double min = HUGE_VAL;
SPItem *closest = NULL;
- for (GSList *i = others; i != NULL; i = i->next) {
- SPItem *other = SP_ITEM (i->data);
+ for (SelContainer::const_iterator i = others.begin(); i != others.end();i++) {
+ SPItem *other = SP_ITEM (*i);
if (other == item)
continue;
@@ -216,13 +215,12 @@ static SPItem *unclump_closest (SPItem *item, GSList *others)
/**
Most distant from item among others
*/
-static SPItem *unclump_farest (SPItem *item, GSList *others)
+static SPItem *unclump_farest (SPItem *item, SelContainer &others)
{
double max = -HUGE_VAL;
SPItem *farest = NULL;
-
- for (GSList *i = others; i != NULL; i = i->next) {
- SPItem *other = SP_ITEM (i->data);
+ for (SelContainer::const_iterator i = others.begin(); i != others.end();i++) {
+ SPItem *other = SP_ITEM (*i);
if (other == item)
continue;
@@ -242,8 +240,8 @@ Removes from the \a rest list those items that are "behind" \a closest as seen f
i.e. those on the other side of the line through \a closest perpendicular to the direction from \a
item to \a closest. Returns a newly created list which must be freed.
*/
-static GSList *
-unclump_remove_behind (SPItem *item, SPItem *closest, GSList *rest)
+static SelContainer
+unclump_remove_behind (SPItem *item, SPItem *closest, SelContainer &rest)
{
Geom::Point it = unclump_center (item);
Geom::Point p1 = unclump_center (closest);
@@ -260,10 +258,9 @@ unclump_remove_behind (SPItem *item, SPItem *closest, GSList *rest)
// substitute the item into it:
double val_item = A * it[Geom::X] + B * it[Geom::Y] + C;
- GSList *out = NULL;
-
- for (GSList *i = rest; i != NULL; i = i->next) {
- SPItem *other = SP_ITEM (i->data);
+ SelContainer out;
+ for (SelContainer::const_iterator i = rest.begin(); i != rest.end();i++) {
+ SPItem *other = SP_ITEM (*i);
if (other == item)
continue;
@@ -274,7 +271,7 @@ unclump_remove_behind (SPItem *item, SPItem *closest, GSList *rest)
if (val_item * val_other <= 1e-6) {
// different signs, which means item and other are on the different sides of p1-p2 line; skip
} else {
- out = g_slist_prepend (out, other);
+ out.push_front(other);
}
}
@@ -334,34 +331,32 @@ similar to "engraver dots". The only distribution which is unchanged by unclumpi
grid. May be called repeatedly for stronger effect.
*/
void
-unclump (GSList *items)
+unclump (SelContainer &items)
{
c_cache.clear();
wh_cache.clear();
- for (GSList *i = items; i != NULL; i = i->next) { // for each original/clone x:
- SPItem *item = SP_ITEM (i->data);
+ for (SelContainer::const_iterator i = items.begin(); i != items.end();i++) { // for each original/clone x:
+ SPItem *item = SP_ITEM (*i);
- GSList *nei = NULL;
+ SelContainer nei;
- GSList *rest = g_slist_copy (items);
- rest = g_slist_remove (rest, item);
+ SelContainer rest(items);
+ rest.remove(item);
- while (rest != NULL) {
+ while (!rest.empty()) {
SPItem *closest = unclump_closest (item, rest);
if (closest) {
- nei = g_slist_prepend (nei, closest);
- rest = g_slist_remove (rest, closest);
- GSList *new_rest = unclump_remove_behind (item, closest, rest);
- g_slist_free (rest);
+ nei.push_front(closest);
+ rest.remove(closest);
+ SelContainer new_rest = unclump_remove_behind (item, closest, rest);
rest = new_rest;
} else {
- g_slist_free (rest);
break;
}
}
- if (g_slist_length (nei) >= 2) {
+ if ( (nei.size()) >= 2) {
double ave = unclump_average (item, nei);
SPItem *closest = unclump_closest (item, nei);