diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
commit | cca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch) | |
tree | 146f39ded1c938019e1ed42d30923c2ac9e86789 /src/3rdparty/adaptagrams/libcola/tests/initialOverlap.cpp | |
parent | Initial commit. (diff) | |
download | inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip |
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/3rdparty/adaptagrams/libcola/tests/initialOverlap.cpp')
-rw-r--r-- | src/3rdparty/adaptagrams/libcola/tests/initialOverlap.cpp | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/src/3rdparty/adaptagrams/libcola/tests/initialOverlap.cpp b/src/3rdparty/adaptagrams/libcola/tests/initialOverlap.cpp new file mode 100644 index 0000000..4f0a8bf --- /dev/null +++ b/src/3rdparty/adaptagrams/libcola/tests/initialOverlap.cpp @@ -0,0 +1,168 @@ +// Check that rectangles that start at same position don't get stuck on top of each other +// during force-directed layout. +#include <vector> +#include <utility> +#include "libcola/cola.h" +#include "libcola/pseudorandom.h" + +using namespace cola; + +int main(void) { + CompoundConstraints ccs; + std::vector<Edge> es; + EdgeLengths eLengths; + double defaultEdgeLength=1; + std::vector<vpsc::Rectangle*> rs; + vpsc::Rectangle *rect = nullptr; + + rect = new vpsc::Rectangle(0, 100, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 100, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 100, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 20, 0, 20); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 60, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 60, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 60, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 60, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 20, 0, 20); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 60, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 60, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 20, 0, 20); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 100, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 20, 0, 20); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 20, 0, 20); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 60, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 60, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 60, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 60, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 100, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 100, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 100, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 100, 0, 60); + rs.push_back(rect); + + rect = new vpsc::Rectangle(0, 100, 0, 60); + rs.push_back(rect); + + es.push_back(std::make_pair(0, 3)); + es.push_back(std::make_pair(1, 3)); + es.push_back(std::make_pair(2, 3)); + es.push_back(std::make_pair(2, 8)); + es.push_back(std::make_pair(2, 11)); + es.push_back(std::make_pair(3, 4)); + es.push_back(std::make_pair(3, 5)); + es.push_back(std::make_pair(6, 8)); + es.push_back(std::make_pair(7, 8)); + es.push_back(std::make_pair(8, 22)); + es.push_back(std::make_pair(8, 23)); + es.push_back(std::make_pair(9, 11)); + es.push_back(std::make_pair(10, 11)); + es.push_back(std::make_pair(11, 12)); + es.push_back(std::make_pair(11, 23)); + es.push_back(std::make_pair(12, 13)); + es.push_back(std::make_pair(12, 14)); + es.push_back(std::make_pair(13, 17)); + es.push_back(std::make_pair(13, 18)); + es.push_back(std::make_pair(13, 19)); + es.push_back(std::make_pair(13, 20)); + es.push_back(std::make_pair(14, 15)); + es.push_back(std::make_pair(14, 16)); + es.push_back(std::make_pair(14, 20)); + es.push_back(std::make_pair(14, 21)); + + eLengths.resize(25); + eLengths[0] = 100; + eLengths[1] = 100; + eLengths[2] = 100; + eLengths[3] = 100; + eLengths[4] = 100; + eLengths[5] = 100; + eLengths[6] = 100; + eLengths[7] = 100; + eLengths[8] = 100; + eLengths[9] = 100; + eLengths[10] = 100; + eLengths[11] = 100; + eLengths[12] = 100; + eLengths[13] = 100; + eLengths[14] = 100; + eLengths[15] = 100; + eLengths[16] = 100; + eLengths[17] = 100; + eLengths[18] = 100; + eLengths[19] = 100; + eLengths[20] = 100; + eLengths[21] = 100; + eLengths[22] = 100; + eLengths[23] = 100; + eLengths[24] = 100; + + ConstrainedFDLayout alg(rs, es, defaultEdgeLength, eLengths); + alg.run(); + //alg.outputInstanceToSVG("initialOverlap"); + + bool overlaps = false; + + for (size_t i = 0; i < rs.size(); ++i) + { + for (size_t j = i + 1; j < rs.size(); ++j) + { + overlaps |= ((rs[i]->overlapD(0, rs[j]) > 0) && (rs[i]->overlapD(1, rs[j]) > 0)); + if (overlaps) + { + break; + } + } + if (overlaps) + { + break; + } + } + + alg.freeAssociatedObjects(); + + return (overlaps) ? 1 : 0; +}; |