diff --git a/NEWS.md b/NEWS.md index 4dd81dc008..bbe72af33f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,8 @@ * Patterns and gradients are now also enabled in `geom_sf()` (@teunbrand, #5716). * `stat_bin()` deals with non-finite breaks better (@teunbrand, #5665). +* Fixed bug in `coord_radial()` where full circles were not treated as such + (@teunbrand, #5750). * When legends detect the presence of values in a layer, `NA` is now detected if the data contains values outside the given breaks (@teunbrand, #5749). * `annotate()` now warns about `stat` or `position` arguments (@teunbrand, #5151) diff --git a/R/coord-radial.R b/R/coord-radial.R index f82189466c..7f8b0eca47 100644 --- a/R/coord-radial.R +++ b/R/coord-radial.R @@ -512,6 +512,11 @@ polar_bbox <- function(arc, margin = c(0.05, 0.05, 0.05, 0.05), # For any `theta` in [0, 2 * pi), test if theta is inside the span # given by `arc` in_arc <- function(theta, arc) { + # Full circle case + if (abs(diff(arc)) > 2 * pi - sqrt(.Machine$double.eps)) { + return(rep(TRUE, length(theta))) + } + # Partial circle case arc <- arc %% (2 * pi) if (arc[1] < arc[2]) { theta >= arc[1] & theta <= arc[2] diff --git a/tests/testthat/test-coord-polar.R b/tests/testthat/test-coord-polar.R index 1285a5368b..4a176fe5cc 100644 --- a/tests/testthat/test-coord-polar.R +++ b/tests/testthat/test-coord-polar.R @@ -124,6 +124,12 @@ test_that("bounding box calculations are sensible", { list(x = c(0, 1), y = c(0, 1)) ) + # Full offset cirle + expect_equal( + polar_bbox(arc = c(2 * pi, 4 * pi)), + list(x = c(0, 1), y = c(0, 1)) + ) + # Right half of circle expect_equal( polar_bbox(arc = c(0, pi)),