Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoordinateSequence: Fix logic error when adding another CoordSeq #963

Merged
merged 1 commit into from Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion NEWS.md
Expand Up @@ -13,8 +13,9 @@
- Fix LargestEmptyCircle to respect polygonal obstacles (GH-939, Martin Davis)
- Fix WKTWriter to emit EMPTY elements in multi-geometries (GH-952, Mike Taves)
- Fix IncrementalDelaunayTriangulator to ensure triangulation boundary is convex (GH-953, Martin Davis)
- Fix PreparedLineStringDistance for lines within envelope and polygons (GH-959, Martin Davis)
- Fix PreparedLineStringDistance for lines within envelope and polygons (GH-959, Martin Davis)
- Improve scale handling for PrecisionModel (GH-956, Martin Davis)
- Fix error in CoordinateSequence::add when disallowing repeated points (GH-963, Dan Baston)


## Changes in 3.12.0
Expand Down
7 changes: 6 additions & 1 deletion src/geom/CoordinateSequence.cpp
Expand Up @@ -191,8 +191,13 @@ CoordinateSequence::add(const CoordinateSequence& cs, std::size_t from, std::siz
}
}

if (first > to) {
// No unique points to add.
return;
}

std::size_t last = first + 1;
const CoordinateXY* last_unique = &cs.front<CoordinateXY>();
const CoordinateXY* last_unique = &cs.getAt<CoordinateXY>(first);
while(last <= to) {
const CoordinateXY* curr = &cs.getAt<CoordinateXY>(last);
if (curr->equals2D(*last_unique)) {
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/geom/CoordinateSequenceTest.cpp
Expand Up @@ -1493,4 +1493,21 @@ void object::test<54>
ensure(xyz3_2.equalsIdentical(xyz3));
}


// test add(CoordinateSequence&, false) when last point of receiving sequence is found after the beginning of donor sequence
template<>
template<>
void object::test<55>
()
{
CoordinateSequence seq1{CoordinateXY(1,2), CoordinateXY(3, 4)};
CoordinateSequence seq2{CoordinateXY(3, 4), CoordinateXY(3, 4), CoordinateXY(5, 6), CoordinateXY(3, 4), CoordinateXY(7, 8), CoordinateXY(7, 8), CoordinateXY(9, 10)};

CoordinateSequence expected{CoordinateXY(1, 2), CoordinateXY(3, 4), CoordinateXY(5, 6), CoordinateXY(3, 4), CoordinateXY(7, 8), CoordinateXY(9, 10)};

seq1.add(seq2, false);

ensure_equals(seq1, expected);
}

} // namespace tut