From c1e3817fb7c0e827de0ab22bc50097585ab51f81 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 6 Mar 2024 09:24:54 +0100 Subject: [PATCH 1/3] account for offsetted full circles --- R/coord-radial.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/coord-radial.R b/R/coord-radial.R index d4aefc979f..9dfdab42a2 100644 --- a/R/coord-radial.R +++ b/R/coord-radial.R @@ -496,6 +496,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] From 983dbdc5062389aa7f6fad48dc57cb645c15e17b Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 6 Mar 2024 09:25:04 +0100 Subject: [PATCH 2/3] add test --- tests/testthat/test-coord-polar.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/testthat/test-coord-polar.R b/tests/testthat/test-coord-polar.R index 613b7d00bc..6969d1b643 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)), From da36f764449c7b0452f0474e7bd0a89c00db9d71 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 6 Mar 2024 09:27:30 +0100 Subject: [PATCH 3/3] add news bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 3e5ba492ef..9740f3e03d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,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). # ggplot2 3.5.0