Skip to content

Commit cacc2e4

Browse files
committed
Change frame algo for shape_sf
1 parent 824ba11 commit cacc2e4

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

R/inset_shape_sf.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,15 @@ get_quasi_tangents <- function(shape1, shape2) {
143143
}
144144
rays <- rays[rays_keep]
145145

146-
# keep at most the two rays that are furthest apart from each other
146+
# keep at most the two rays that are "most separated" by computing the enclosed area
147147
if (length(rays) > 2) {
148148
sep <- expand.grid(i = seq_along(rays), j = seq_along(rays))
149-
sep$distance <- apply(sep, 1, simplify = TRUE, FUN = function(x) {
150-
sf::st_distance(rays[[x[[1]]]], rays[[x[[2]]]])
149+
sep$area <- apply(sep, 1, simplify = TRUE, FUN = function(x) {
150+
sf::st_combine(c(rays[[x[[1]]]], rays[[x[[2]]]])) |>
151+
sf::st_triangulate() |>
152+
sf::st_area()
151153
})
152-
sep_max <- sep[which.max(sep$distance),]
154+
sep_max <- sep[which.max(sep$area), ]
153155
rays <- rays[c(sep_max$i, sep_max$j)]
154156
}
155157

0 commit comments

Comments
 (0)