diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-05-09 18:34:01 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-05-09 18:34:01 +0000 |
| commit | 36bc16fc9772ce0271eb5ec62e2c03cb1038282e (patch) | |
| tree | c13d992c952bd21bc00c393d80bfe31c3b35284e /src/unclump.cpp | |
| parent | prevent overflow index on a pathinfo function (diff) | |
| parent | Fix Doxyfile (diff) | |
| download | inkscape-36bc16fc9772ce0271eb5ec62e2c03cb1038282e.tar.gz inkscape-36bc16fc9772ce0271eb5ec62e2c03cb1038282e.zip | |
update to trunk
(bzr r13645.1.85)
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); |
