Skip to content

Commit ce6eed8

Browse files
authored
Fix coord_radial() full circle bug (#5752)
* account for offsetted full circles * add test * add news bullet
1 parent 9806e27 commit ce6eed8

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* Patterns and gradients are now also enabled in `geom_sf()`
1313
(@teunbrand, #5716).
1414
* `stat_bin()` deals with non-finite breaks better (@teunbrand, #5665).
15+
* Fixed bug in `coord_radial()` where full circles were not treated as such
16+
(@teunbrand, #5750).
1517
* When legends detect the presence of values in a layer, `NA` is now detected
1618
if the data contains values outside the given breaks (@teunbrand, #5749).
1719
* `annotate()` now warns about `stat` or `position` arguments (@teunbrand, #5151)

R/coord-radial.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,11 @@ polar_bbox <- function(arc, margin = c(0.05, 0.05, 0.05, 0.05),
512512
# For any `theta` in [0, 2 * pi), test if theta is inside the span
513513
# given by `arc`
514514
in_arc <- function(theta, arc) {
515+
# Full circle case
516+
if (abs(diff(arc)) > 2 * pi - sqrt(.Machine$double.eps)) {
517+
return(rep(TRUE, length(theta)))
518+
}
519+
# Partial circle case
515520
arc <- arc %% (2 * pi)
516521
if (arc[1] < arc[2]) {
517522
theta >= arc[1] & theta <= arc[2]

tests/testthat/test-coord-polar.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ test_that("bounding box calculations are sensible", {
124124
list(x = c(0, 1), y = c(0, 1))
125125
)
126126

127+
# Full offset cirle
128+
expect_equal(
129+
polar_bbox(arc = c(2 * pi, 4 * pi)),
130+
list(x = c(0, 1), y = c(0, 1))
131+
)
132+
127133
# Right half of circle
128134
expect_equal(
129135
polar_bbox(arc = c(0, pi)),

0 commit comments

Comments
 (0)