diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2019-11-06 13:55:38 -0500 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2019-11-06 13:55:38 -0500 |
commit | 19d657b60b22159359f7a229f5a5b73e729cff79 (patch) | |
tree | f0dc1df96e26bdbe3f49032d396a9efe36a3c5df /lib/src/graph.cpp | |
parent | ba4a31df421ff47de1f8c3dc86daea2cacd942ed (diff) | |
download | fuse_networks-19d657b60b22159359f7a229f5a5b73e729cff79.tar.gz fuse_networks-19d657b60b22159359f7a229f5a5b73e729cff79.tar.bz2 fuse_networks-19d657b60b22159359f7a229f5a5b73e729cff79.zip |
added support for saving networks to the library and revamped the sample method
Diffstat (limited to 'lib/src/graph.cpp')
-rw-r--r-- | lib/src/graph.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/src/graph.cpp b/lib/src/graph.cpp index 1475c40..c75d466 100644 --- a/lib/src/graph.cpp +++ b/lib/src/graph.cpp @@ -1,6 +1,7 @@ #include "graph.hpp" #include <cstring> +#include <sstream> #define JC_VORONOI_IMPLEMENTATION #define JCV_REAL_TYPE double @@ -477,3 +478,61 @@ graph const graph::rotate() { return g2; } + +std::string graph::write() const { + std::string output; + + output += "\"vr\"->{"; + for (const graph::vertex &v : vertices) { + output += "{" + std::to_string(v.r.x) + "," + std::to_string(v.r.y) + "},"; + } + output.pop_back(); + output += "},\"vp\"->{"; + for (const graph::vertex &v : vertices) { + output += "{"; + for (const graph::coordinate &r : v.polygon) { + output += "{" + std::to_string(r.x) + "," + std::to_string(r.y) + "},"; + } + output.pop_back(); + output += "},"; + } + output.pop_back(); + output += "},\"ur\"->{"; + for (const graph::vertex &v : dual_vertices) { + output += "{" + std::to_string(v.r.x) + "," + std::to_string(v.r.y) + "},"; + } + output.pop_back(); + output += "},\"up\"->{"; + for (const graph::vertex &v : dual_vertices) { + output += "{"; + for (const graph::coordinate &r : v.polygon) { + output += "{" + std::to_string(r.x) + "," + std::to_string(r.y) + "},"; + } + output.pop_back(); + output += "},"; + } + output.pop_back(); + output += "},\"e\"->{"; + for (const graph::edge &e : edges) { + output += "{" + std::to_string(e.v[0]) + "," + std::to_string(e.v[1]) + "},"; + } + output.pop_back(); + output += "},\"ec\"->{"; + for (const graph::edge &e : edges) { + output += "{" + std::to_string(e.crossings[0]) + "," + std::to_string(e.crossings[1]) + "},"; + } + output.pop_back(); + output += "},\"d\"->{"; + for (const graph::edge &e : dual_edges) { + output += "{" + std::to_string(e.v[0]) + "," + std::to_string(e.v[1]) + "},"; + } + output.pop_back(); + output += "},\"dc\"->{"; + for (const graph::edge &e : dual_edges) { + output += "{" + std::to_string(e.crossings[0]) + "," + std::to_string(e.crossings[1]) + "},"; + } + output.pop_back(); + output += "}"; + + return output; +} |