Skip to content

Commit

Permalink
CoordinateSequence: Fix logic error when adding another CoordSeq
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Sep 22, 2023
1 parent bd633c6 commit 2499819
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/geom/CoordinateSequence.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 2499819

Please sign in to comment.