Skip to content

Commit 7e87776

Browse files
committed
Split geom::segmentize() function into two
with and without output parameter
1 parent 1314cbb commit 7e87776

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/geom-functions.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,22 +309,28 @@ static void split_linestring(linestring_t const &line, double split_at,
309309
}
310310
}
311311

312-
geometry_t segmentize(geometry_t const &geom, double max_segment_length)
312+
void segmentize(geometry_t *output, geometry_t const &input,
313+
double max_segment_length)
313314
{
314-
geometry_t output{multilinestring_t{}, geom.srid()};
315-
auto *multilinestring = &output.get<multilinestring_t>();
315+
output->set_srid(input.srid());
316+
auto *multilinestring = &output->set<multilinestring_t>();
316317

317-
if (geom.is_linestring()) {
318-
split_linestring(geom.get<linestring_t>(), max_segment_length,
318+
if (input.is_linestring()) {
319+
split_linestring(input.get<linestring_t>(), max_segment_length,
319320
multilinestring);
320-
} else if (geom.is_multilinestring()) {
321-
for (auto const &line : geom.get<multilinestring_t>()) {
321+
} else if (input.is_multilinestring()) {
322+
for (auto const &line : input.get<multilinestring_t>()) {
322323
split_linestring(line, max_segment_length, multilinestring);
323324
}
324325
} else {
325-
output.reset();
326+
output->reset();
326327
}
328+
}
327329

330+
geometry_t segmentize(geometry_t const &input, double max_segment_length)
331+
{
332+
geometry_t output;
333+
segmentize(&output, input, max_segment_length);
328334
return output;
329335
}
330336

src/geom-functions.hpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,27 @@ geometry_t transform(geometry_t const &input, reprojection const &reprojection);
115115
* Returns a modified geometry having no segment longer than the given
116116
* max_segment_length.
117117
*
118-
* \param geom The input geometry, must be a linestring or multilinestring.
118+
* \param output Pointer to output geometry. Will be a multilinestring
119+
* geometry, or nullgeom_t on error.
120+
* \param input The input geometry, must be a linestring or multilinestring.
119121
* \param max_segment_length The maximum length (using Euclidean distance
120-
* in the length unit of the srs of the geometry) of each resulting
122+
* in the length unit of the SRS of the geometry) of each resulting
123+
* linestring.
124+
*/
125+
void segmentize(geometry_t *output, geometry_t const &input,
126+
double max_segment_length);
127+
128+
/**
129+
* Returns a modified geometry having no segment longer than the given
130+
* max_segment_length.
131+
*
132+
* \param input The input geometry, must be a linestring or multilinestring.
133+
* \param max_segment_length The maximum length (using Euclidean distance
134+
* in the length unit of the SRS of the geometry) of each resulting
121135
* linestring.
122136
* \returns Resulting multilinestring geometry, nullgeom_t on error.
123137
*/
124-
geometry_t segmentize(geometry_t const &geom, double max_segment_length);
138+
geometry_t segmentize(geometry_t const &input, double max_segment_length);
125139

126140
/**
127141
* Calculate area of geometry.

0 commit comments

Comments
 (0)