Skip to content

Commit

Permalink
implement 'convex' iso param for #223
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed May 17, 2024
1 parent 303146d commit c1b1bbb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dodgr
Title: Distances on Directed Graphs
Version: 0.3.0.018
Version: 0.3.0.019
Authors@R: c(
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre")),
person("Andreas", "Petutschnig", role = "aut"),
Expand Down
19 changes: 15 additions & 4 deletions R/iso.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dodgr_isodists <- function (graph,
d [d >= 0] <- NA
d <- -d # convert negative-flagged iso-values to positive

return (dmat_to_pts (d, from_id, dat$v, dlim))
return (dmat_to_pts (d, from_id, dat$v, dlim, convex = convex))
}

iso_pre <- function (graph, from = NULL, heap = "BHeap", contract = TRUE) {
Expand Down Expand Up @@ -272,7 +272,7 @@ dodgr_isoverts <- function (graph,
index <- match (f, attr (f, "levels"))
d [na_index] <- breaks [-1] [index]

res <- dmat_to_pts (d, dat$from_index$id, dat$v, dlim)
res <- dmat_to_pts (d, dat$from_index$id, dat$v, dlim, convex = FALSE)
if (has_tlim) {
names (res) [names (res) == "dlim"] <- "tlim"
}
Expand All @@ -281,7 +281,7 @@ dodgr_isoverts <- function (graph,

# convert distance matrix with values equal to various isodistances into list of
# lists of points ordered around the central points
dmat_to_pts <- function (d, from, v, dlim) {
dmat_to_pts <- function (d, from, v, dlim, convex = FALSE) {

pt_names <- colnames (d)
pts <- list ()
Expand Down Expand Up @@ -312,8 +312,19 @@ dmat_to_pts <- function (d, from, v, dlim) {
}
names (pts) <- rownames (d)

# flatten lists
# pts are then nested lists of [[from]] [[dlim]]

if (convex) {
pts <- lapply (pts, function (pt_from) {
lapply (pt_from, function (pt_dlim) {
pt_dlim [grDevices::chull (pt_dlim [, c ("x", "y")]), ]
})
})
}

# flatten lists:
pts <- do.call (rbind, lapply (pts, function (i) do.call (rbind, i)))

rownames (pts) <- NULL

return (pts)
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"codeRepository": "https://github.com/UrbanAnalyst/dodgr",
"issueTracker": "https://github.com/UrbanAnalyst/dodgr/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.3.0.018",
"version": "0.3.0.019",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit c1b1bbb

Please sign in to comment.