Skip to content

Commit

Permalink
Merge pull request #121 from r-spatial/dewey-dev
Browse files Browse the repository at this point in the history
make sure aggregate centroids normalize points
  • Loading branch information
Dewey Dunnington authored Jun 5, 2021
2 parents e39716e + 8401275 commit 8491cd3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/s2-transformers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ List cpp_s2_centroid_agg(List geog, bool naRm) {
if (cumCentroid.Norm2() == 0) {
output[0] = Rcpp::XPtr<Geography>(new PointGeography());
} else {
output[0] = Rcpp::XPtr<Geography>(new PointGeography(cumCentroid));
output[0] = Rcpp::XPtr<Geography>(new PointGeography(cumCentroid.Normalize()));
}

return output;
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-s2-transformers.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ test_that("s2_centroid() works", {
)
})

test_that("s2_centroid() and s2_centroid_agg() normalize points", {
expect_equal(
s2_distance(
s2_centroid("MULTIPOINT (1 1, 1 1)"),
"POINT (1 1)"
),
0
)

expect_equal(
s2_distance(
s2_centroid_agg(c("POINT (1 1)", "POINT (1 1)")),
"POINT (1 1)"
),
0
)
})

test_that("s2_boundary() works", {
expect_true(s2_is_empty(s2_boundary("POINT (30 10)")))
expect_true(s2_is_empty(s2_boundary("POINT EMPTY")))
Expand Down

0 comments on commit 8491cd3

Please sign in to comment.