71 std::ostringstream log;
72 std::ostringstream err;
73 std::ostringstream notice;
78 const int64_t round = 100000000000000;
80 std::vector<Pgr_edge_xy_t> edges(edgesArr, edgesArr + edgesSize);
91 std::sort(edges.begin(), edges.end(),
94 std::floor(lhs.y1 * static_cast<double>(round)) < std::floor(rhs.y1 * static_cast<double>(round));
96 std::stable_sort(edges.begin(), edges.end(),
99 std::floor(lhs.x1 * static_cast<double>(round)) < std::floor(rhs.x1 * static_cast<double>(round));
101 log <<
"ending sort";
105 int64_t source_id(0);
106 auto prev = edges.front();
107 for (
auto &e : edges) {
109 e.source = source_id;
111 e.source = ++source_id;
115 std::stable_sort(edges.begin(), edges.end(),
127 for (
auto &c : edges) {
142 a->target = b->source;
146 b->target = c.source;
150 c.target = a->source;
157 Pgr_alphaShape alphaShape(edges);
159 auto results = alphaShape(alpha);
160 log << alphaShape.get_log();
165 if (results.empty()) {
167 *return_tuples =
pgr_alloc(*return_count, (*return_tuples));
168 std::stringstream ss;
169 ss <<
"MULTIPOLYGON EMPTY";
170 (*return_tuples)[0].geom =
pgr_msg(ss.str().c_str());
172 *return_count = results.size();
173 *return_tuples =
pgr_alloc(*return_count, (*return_tuples));
175 for (
const auto &r : results) {
176 std::stringstream ss;
178 (*return_tuples)[row].geom =
pgr_msg(ss.str().c_str());
184 *log_msg = log.str().empty()?
187 *notice_msg = notice.str().empty()?
191 (*return_tuples) =
pgr_free(*return_tuples);
193 err << except.
what();
194 *err_msg =
pgr_msg(err.str().c_str());
195 }
catch (std::exception &except) {
196 (*return_tuples) =
pgr_free(*return_tuples);
198 err << except.what();
199 *err_msg =
pgr_msg(err.str().c_str());
201 (*return_tuples) =
pgr_free(*return_tuples);
203 err <<
"Caught unknown exception!";
204 *err_msg =
pgr_msg(err.str().c_str());