summaryrefslogtreecommitdiffstats
path: root/src/removeoverlap.cpp
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-07-01 23:31:49 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2017-07-01 23:31:49 +0000
commit03bb87a0175289274132a0240628936fbccf6ca5 (patch)
tree979519e873c0ceff7a6a8b0f53252a4a5ece1143 /src/removeoverlap.cpp
parentImproving CR feedback. thanks! (diff)
parentWhen running without installing, extensions will spawn correct Inkscape (diff)
downloadinkscape-03bb87a0175289274132a0240628936fbccf6ca5.tar.gz
inkscape-03bb87a0175289274132a0240628936fbccf6ca5.zip
Merge https://gitlab.com/inkscape/inkscape into selectable-knots
Diffstat (limited to 'src/removeoverlap.cpp')
-rw-r--r--src/removeoverlap.cpp116
1 files changed, 55 insertions, 61 deletions
diff --git a/src/removeoverlap.cpp b/src/removeoverlap.cpp
index 138577fb8..9dd8e5152 100644
--- a/src/removeoverlap.cpp
+++ b/src/removeoverlap.cpp
@@ -2,34 +2,36 @@
* Interface between Inkscape code (SPItem) and remove-overlaps function.
*/
/*
-* Authors:
-* Tim Dwyer <tgdwyer@gmail.com>
+ * Authors:
+ * Tim Dwyer <tgdwyer@gmail.com>
* Abhishek Sharma
-*
-* Copyright (C) 2005 Authors
-*
-* Released under GNU LGPL. Read the file 'COPYING' for more information.
-*/
+ *
+ * Copyright (C) 2005 Authors
+ *
+ * Released under GNU LGPL. Read the file 'COPYING' for more information.
+ */
+
#include <utility>
#include <2geom/transforms.h>
#include "sp-item.h"
#include "sp-item-transform.h"
-#include "libvpsc/generate-constraints.h"
-#include "libvpsc/remove_rectangle_overlap.h"
+#include "libvpsc/rectangle.h"
#include "removeoverlap.h"
using vpsc::Rectangle;
namespace {
- struct Record {
- SPItem *item;
- Geom::Point midpoint;
- Rectangle *vspc_rect;
- Record() : item(0), vspc_rect(0) {}
- Record(SPItem *i, Geom::Point m, Rectangle *r)
- : item(i), midpoint(m), vspc_rect(r) {}
- };
+struct Record {
+ SPItem * item;
+ Geom::Point midpoint;
+ Rectangle * vspc_rect;
+
+ Record() : item(0), vspc_rect(0) {}
+ Record(SPItem * i, Geom::Point m, Rectangle * r)
+ : item(i), midpoint(m), vspc_rect(r) {}
+};
+
}
/**
@@ -37,49 +39,41 @@ namespace {
* such that rectangular bounding boxes are separated by at least xGap
* horizontally and yGap vertically
*/
-void removeoverlap(std::vector<SPItem*> const &items, double const xGap, double const yGap) {
- std::vector<SPItem*> selected(items);
- std::vector<Record> records;
- std::vector<Rectangle *> rs;
+void removeoverlap(std::vector<SPItem*> const & items, double const xGap, double const yGap) {
+ std::vector<SPItem*> selected = items;
+ std::vector<Record> records;
+ std::vector<Rectangle*> rs;
- Geom::Point const gap(xGap, yGap);
- for (std::vector<SPItem*>::iterator it(selected.begin());
- it != selected.end();
- ++it)
- {
- SPItem* item = *it;
- using Geom::X; using Geom::Y;
- Geom::OptRect item_box((item)->desktopVisualBounds());
- if (item_box) {
- Geom::Point min(item_box->min() - .5*gap);
- Geom::Point max(item_box->max() + .5*gap);
- // A negative gap is allowed, but will lead to problems when the gap is larger than
- // the bounding box (in either X or Y direction, or both); min will have become max
- // now, which cannot be handled by Rectangle() which is called below. And how will
- // removeRectangleOverlap handle such a case?
- // That's why we will enforce some boundaries on min and max here:
- if (max[X] < min[X]) {
- min[X] = max[X] = (min[X] + max[X])/2;
- }
- if (max[Y] < min[Y]) {
- min[Y] = max[Y] = (min[Y] + max[Y])/2;
- }
- Rectangle *vspc_rect = new Rectangle(min[X], max[X], min[Y], max[Y]);
- records.push_back(Record(item, item_box->midpoint(), vspc_rect));
- rs.push_back(vspc_rect);
- }
- }
- if (!rs.empty()) {
- removeRectangleOverlap(rs.size(), &rs[0], 0.0, 0.0);
- }
- for ( std::vector<Record>::iterator it = records.begin();
- it != records.end();
- ++it )
- {
- Geom::Point const curr = it->midpoint;
- Geom::Point const dest(it->vspc_rect->getCentreX(),
- it->vspc_rect->getCentreY());
- sp_item_move_rel(it->item, Geom::Translate(dest - curr));
- delete it->vspc_rect;
- }
+ Geom::Point const gap(xGap, yGap);
+ for (SPItem * item: selected) {
+ using Geom::X; using Geom::Y;
+ Geom::OptRect item_box(item->desktopVisualBounds());
+ if (item_box) {
+ Geom::Point min(item_box->min() - .5 * gap);
+ Geom::Point max(item_box->max() + .5 * gap);
+ // A negative gap is allowed, but will lead to problems when the gap is larger than
+ // the bounding box (in either X or Y direction, or both); min will have become max
+ // now, which cannot be handled by Rectangle() which is called below. And how will
+ // removeRectangleOverlap handle such a case?
+ // That's why we will enforce some boundaries on min and max here:
+ if (max[X] < min[X]) {
+ min[X] = max[X] = (min[X] + max[X]) / 2.;
+ }
+ if (max[Y] < min[Y]) {
+ min[Y] = max[Y] = (min[Y] + max[Y]) / 2.;
+ }
+ Rectangle * vspc_rect = new Rectangle(min[X], max[X], min[Y], max[Y]);
+ records.push_back(Record(item, item_box->midpoint(), vspc_rect));
+ rs.push_back(vspc_rect);
+ }
+ }
+ if (!rs.empty()) {
+ removeoverlaps(rs);
+ }
+ for (Record & rec: records) {
+ Geom::Point const curr = rec.midpoint;
+ Geom::Point const dest(rec.vspc_rect->getCentreX(), rec.vspc_rect->getCentreY());
+ sp_item_move_rel(rec.item, Geom::Translate(dest - curr));
+ delete rec.vspc_rect;
+ }
}