Skip to content

Commit

Permalink
make sure aggregate centroids normalize points when creating a PointG…
Browse files Browse the repository at this point in the history
…eography (#119)
  • Loading branch information
paleolimbot committed Jun 5, 2021
1 parent e39716e commit 8401275
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 8401275

Please sign in to comment.