Request: Distribution (align and distribute) takes into account stack order
Migrated from: https://bugs.launchpad.net/inkscape/+bug/1587045
Steps to reproduce:
- open Inkscape
- Create an object
- Duplicate so there are 17 identical objects in the same location
- Move the top object down on the canvas a bit (preferably with enough space to distribute all of them and have them separated by a small amount)
- Select all the objects
- Open Align and Distribute dialog
- Distribute centers equidistantly vertically
Svg from original issue (there is flowed test not visible in browser):
What happened?
Selecting the items from top to bottom shows that the items are not distributed by stacking order (but appear to be ordered seemingly randomly)
Note: the original issue mentioned >16 objects causing this error. I replicated with below 16 objects (I think 10? I forget).
What should have happened?
The stacking order should be taken into account when distributing items.
I think this is the solution. Posting this issue anyway because a) let's double check first, and b) for clearer reference.
diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp
index 1355849325..28bc8f6040 100644
--- a/src/ui/dialog/align-and-distribute.cpp
+++ b/src/ui/dialog/align-and-distribute.cpp
@@ -330,7 +330,7 @@ private :
}
}
//sort bbox by anchors
- std::sort(sorted.begin(), sorted.end());
+ std::stable_sort(sorted.begin(), sorted.end());
// see comment in ActionAlign above
int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
Edit: also investigating other places where this behaviour should be used. Also std::sort(..., ..., sp_repr_compare_position_bool);
may be more appropriate (haven't tested)
Inkscape Version and Operating System:
- 1.0alpha2 (e8017634da, 2019-07-17) Linux Mint 19.1