diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2015-04-29 21:14:01 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <mc@M0nst3r.bouyguesbox.fr> | 2015-04-29 21:14:01 +0000 |
| commit | 9b7af8caac08ad42a48214518bc004e258eb5873 (patch) | |
| tree | dcaaac56217eb5da334ab420f5e791cf7eb70f23 /src/unclump.cpp | |
| parent | Better solution picking (diff) | |
| parent | corrected test file (diff) | |
| download | inkscape-9b7af8caac08ad42a48214518bc004e258eb5873.tar.gz inkscape-9b7af8caac08ad42a48214518bc004e258eb5873.zip | |
bzr merge lp:~mc.../inkscape/SelContainer
The main change of this branch is that the container for selections is now a std::vector and not a GSList.
This change propagates in most of the codebase.
Normally, there are no changes of semantics, except the following:
-> childList is now in the intuitive order (childList()[0] is now firstChild)
-> sp_selection_paste_impl is now in the opposite order (change is local to selection-chemistry.cpp, and simplify a few things there)
-> selection.setReprList now takes the list in the opposite order. It was always the case (the list was always reversed before handing to it)
-> a few comparison functions now work "the c++ way": the C way was to return -1 if a<b, 0 if a==b and 1 if a>b, now they return (bool)(a<b) so they can be used with std::sort
(bzr r14074)
Diffstat (limited to 'src/unclump.cpp')
| -rw-r--r-- | src/unclump.cpp | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/src/unclump.cpp b/src/unclump.cpp index 940369d7a..81c958937 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, std::list<SPItem*> &others) { int n = 0; double sum = 0; - - for (GSList *i = others; i != NULL; i = i->next) { - SPItem *other = SP_ITEM (i->data); + for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();i++) { + SPItem *other = *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, std::list<SPItem*> &others) { double min = HUGE_VAL; SPItem *closest = NULL; - for (GSList *i = others; i != NULL; i = i->next) { - SPItem *other = SP_ITEM (i->data); + for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();i++) { + SPItem *other = *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, std::list<SPItem*> &others) { double max = -HUGE_VAL; SPItem *farest = NULL; - - for (GSList *i = others; i != NULL; i = i->next) { - SPItem *other = SP_ITEM (i->data); + for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();i++) { + SPItem *other = *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 std::vector<SPItem*> +unclump_remove_behind (SPItem *item, SPItem *closest, std::list<SPItem*> &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); + std::vector<SPItem*> out; + for (std::list<SPItem*>::const_reverse_iterator i = rest.rbegin(); i != rest.rend();i++) { + SPItem *other = *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_back(other); } } @@ -334,34 +331,34 @@ 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 (std::vector<SPItem*> &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 (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end();i++) { // for each original/clone x: + SPItem *item = *i; - GSList *nei = NULL; + std::list<SPItem*> nei; - GSList *rest = g_slist_copy (items); - rest = g_slist_remove (rest, item); + std::list<SPItem*> rest; + for(int i=0;i<items.size();i++)rest.push_front(items[items.size()-i-1]); + 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); - rest = new_rest; + nei.push_front(closest); + rest.remove(closest); + std::vector<SPItem*> new_rest = unclump_remove_behind (item, closest, rest); + rest.clear(); + for(int i=0;i<new_rest.size();i++)rest.push_front(new_rest[new_rest.size()-i-1]); } 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); |
