Skip to content

Commit

Permalink
Fix bug in DumpCoordinates for MultiPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstace committed Jul 28, 2021
1 parent c41162f commit 1890266
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions geom/dump_coordinates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func TestDumpCoordinatesMultiPoint(t *testing.T) {
inputWKT: "MULTIPOINT ZM(3 4 5 6)",
want: NewSequence([]float64{3, 4, 5, 6}, DimXYZM),
},
{
description: "reproduce bug",
inputWKT: "MULTIPOINT Z(3 4 5,6 7 8)",
want: NewSequence([]float64{3, 4, 5, 6, 7, 8}, DimXYZ),
},
} {
t.Run(tc.description, func(t *testing.T) {
got := geomFromWKT(t, tc.inputWKT).AsMultiPoint().DumpCoordinates()
Expand Down
5 changes: 3 additions & 2 deletions geom/type_multi_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,17 @@ func (m MultiPoint) Dump() []Point {
// DumpCoordinates returns the non-empty points in a MultiPoint represented as
// a Sequence.
func (m MultiPoint) DumpCoordinates() Sequence {
ctype := m.CoordinatesType()
n := m.seq.Length()
empty := m.empty.CountTrue()
nonEmpty := make([]float64, 0, n-empty)
nonEmpty := make([]float64, 0, ctype.Dimension()*(n-empty))
for i := 0; i < n; i++ {
if m.empty.Get(i) {
continue
}
nonEmpty = m.seq.Get(i).appendFloat64s(nonEmpty)
}
seq := NewSequence(nonEmpty, m.seq.CoordinatesType())
seq := NewSequence(nonEmpty, ctype)
seq.assertNoUnusedCapacity()
return seq
}

0 comments on commit 1890266

Please sign in to comment.