Skip to content

Commit

Permalink
Retain component order in MultiLineString::reverse
Browse files Browse the repository at this point in the history
Updated for consistency with the behavior of other geometry types (as
changed in locationtech/jts#513)

Fixes #1013
  • Loading branch information
dbaston committed Feb 5, 2020
1 parent c2a683d commit c01c8c1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Changes in 3.8.1
- Avoid assertion failure with MSVC 2017 / 2019 (#1002, Dan Baston)
- Remove whitespace from end of GEOSversion() output (azhi)
- Improve performance of GEOSisValid (#1008, Dan Baston)
- Avoid changing MultiLineString component order in GEOSReverse
(#1013, Dan Baston)

Changes in 3.8.0
2019-10-10
Expand Down
16 changes: 9 additions & 7 deletions src/geom/MultiLineString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,16 @@ MultiLineString::reverse() const
return clone();
}

size_t nLines = geometries.size();
std::vector<std::unique_ptr<Geometry>> revLines(nLines);
std::vector<std::unique_ptr<Geometry>> reversed(geometries.size());

for(size_t i = 0; i < nLines; ++i) {
const LineString* iLS = static_cast<LineString*>(geometries[i].get());
revLines[nLines - 1 - i] = iLS->reverse();
}
return getFactory()->createMultiLineString(std::move(revLines));
std::transform(geometries.begin(),
geometries.end(),
reversed.begin(),
[](const std::unique_ptr<Geometry> & g) {
return g->reverse();
});

return getFactory()->createMultiLineString(std::move(reversed));
}

} // namespace geos::geom
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/capi/GEOSReverseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void object::test<4>
()
{
testReverse("MULTILINESTRING ((1 1, 2 2), (3 3, 4 4))",
"MULTILINESTRING ((4 4, 3 3), (2 2, 1 1))");
"MULTILINESTRING ((2 2, 1 1), (4 4, 3 3))");
}

template<>
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/linearref/LengthIndexedLineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void object::test<16>
()
{
checkExtractLine("MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))",
19, 1, "MULTILINESTRING ((29 0, 25 0, 20 0), (10 0, 1 0))");
19, 1, "MULTILINESTRING ((10 0, 1 0), (29 0, 25 0, 20 0))");
}

// testExtractLineNegative()
Expand Down

0 comments on commit c01c8c1

Please sign in to comment.