Skip to content

Commit b5e547b

Browse files
committed
Code cleanup: Put code that belong together in sections
Put geometry functions in sections together with their support classes and functions.
1 parent 175a298 commit b5e547b

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

src/geom-functions.cpp

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ point_t interpolate(point_t p1, point_t p2, double frac) noexcept
3232
frac * (p1.y() - p2.y()) + p2.y()};
3333
}
3434

35+
/****************************************************************************/
36+
3537
std::string_view geometry_type(geometry_t const &geom)
3638
{
3739
using namespace std::literals::string_view_literals;
@@ -52,12 +54,16 @@ std::string_view geometry_type(geometry_t const &geom)
5254
}});
5355
}
5456

57+
/****************************************************************************/
58+
5559
std::size_t num_geometries(geometry_t const &geom)
5660
{
5761
return geom.visit(
5862
[&](auto const &input) { return input.num_geometries(); });
5963
}
6064

65+
/****************************************************************************/
66+
6167
namespace {
6268

6369
class geometry_n_visitor
@@ -111,6 +117,8 @@ geometry_t geometry_n(geometry_t const &input, std::size_t n)
111117
return output;
112118
}
113119

120+
/****************************************************************************/
121+
114122
namespace {
115123

116124
void set_to_same_type(geometry_t *output, geometry_t const &input)
@@ -231,6 +239,8 @@ geometry_t transform(geometry_t const &input, reprojection const &reprojection)
231239
return output;
232240
}
233241

242+
/****************************************************************************/
243+
234244
namespace {
235245

236246
/**
@@ -333,6 +343,8 @@ geometry_t segmentize(geometry_t const &input, double max_segment_length)
333343
return output;
334344
}
335345

346+
/****************************************************************************/
347+
336348
double area(geometry_t const &geom)
337349
{
338350
return std::abs(geom.visit(
@@ -348,6 +360,8 @@ double area(geometry_t const &geom)
348360
}}));
349361
}
350362

363+
/****************************************************************************/
364+
351365
double length(geometry_t const &geom)
352366
{
353367
return geom.visit(overloaded{
@@ -364,6 +378,8 @@ double length(geometry_t const &geom)
364378
}});
365379
}
366380

381+
/****************************************************************************/
382+
367383
namespace {
368384

369385
class split_visitor
@@ -413,25 +429,6 @@ std::vector<geometry_t> split_multi(geometry_t &&geom, bool split_multi)
413429
return output;
414430
}
415431

416-
/**
417-
* Add points specified by iterators to the linestring. If linestring is not
418-
* empty, do not add the first point returned by *it.
419-
*/
420-
template <typename ITERATOR>
421-
static void add_nodes_to_linestring(linestring_t *linestring, ITERATOR it,
422-
ITERATOR end)
423-
{
424-
if (!linestring->empty()) {
425-
assert(it != end);
426-
++it;
427-
}
428-
429-
while (it != end) {
430-
linestring->push_back(*it);
431-
++it;
432-
}
433-
}
434-
435432
/****************************************************************************/
436433

437434
static void reverse(geom::nullgeom_t * /*output*/,
@@ -488,6 +485,25 @@ geometry_t reverse(geometry_t const &input)
488485

489486
/****************************************************************************/
490487

488+
/**
489+
* Add points specified by iterators to the linestring. If linestring is not
490+
* empty, do not add the first point returned by *it.
491+
*/
492+
template <typename ITERATOR>
493+
static void add_nodes_to_linestring(linestring_t *linestring, ITERATOR it,
494+
ITERATOR end)
495+
{
496+
if (!linestring->empty()) {
497+
assert(it != end);
498+
++it;
499+
}
500+
501+
while (it != end) {
502+
linestring->push_back(*it);
503+
++it;
504+
}
505+
}
506+
491507
void line_merge(geometry_t *output, geometry_t const &input)
492508
{
493509
if (input.is_linestring()) {
@@ -670,6 +686,8 @@ geometry_t line_merge(geometry_t const &input)
670686
return output;
671687
}
672688

689+
/****************************************************************************/
690+
673691
/**
674692
* This helper function is used to calculate centroids of geometry collections.
675693
* It first creates a multi geometry that only contains the geometries of

0 commit comments

Comments
 (0)