No flags found
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
e03f791
... +14 ...
d7f4aa1
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
1 | + | #' Compute "outline" bitmap of a bitmap |
|
2 | + | #' |
|
3 | + | #' `bm_outline()` returns a bitmap that is just the \dQuote{outline} |
|
4 | + | #' of another bitmap. |
|
5 | + | #' @inheritParams bm_clamp |
|
6 | + | #' @inherit bm_clamp return |
|
7 | + | #' @examples |
|
8 | + | #' square <- bm_bitmap(matrix(1L, nrow = 16L, ncol = 16L)) |
|
9 | + | #' square_outline <- bm_outline(square) |
|
10 | + | #' print(square_outline, px = px_ascii) |
|
11 | + | #' |
|
12 | + | #' if (require(grid) && capabilities("png")) { |
|
13 | + | #' circle <- as_bm_bitmap(circleGrob(), width=16, height=16) |
|
14 | + | #' circle_outline <- bm_outline(circle) |
|
15 | + | #' print(circle_outline, px = px_ascii) |
|
16 | + | #' } |
|
17 | + | #' @export |
|
18 | + | bm_outline <- function(bm_object) { |
|
19 | + | modify_bm_bitmaps(bm_object, bm_outline_bitmap) |
|
20 | + | } |
|
21 | + | ||
22 | + | bm_outline_bitmap <- function(bitmap) { |
|
23 | + | if (nrow(bitmap) <= 2L || ncol(bitmap) <= 2L) |
|
24 | + | return(bitmap) |
|
25 | + | ||
26 | + | outline <- bitmap |
|
27 | + | for (i in 2:(nrow(bitmap) - 1L)) { |
|
28 | + | for (j in 2:(ncol(bitmap) - 1L)) { |
|
29 | + | neighbors <- bitmap[i, c(j - 1, j + 1)] |
|
30 | + | neighbors <- c(neighbors, bitmap[c(i - 1, i + 1), j]) |
|
31 | + | if (all(neighbors == 1L)) |
|
32 | + | outline[i, j] <- 0L |
|
33 | + | } |
|
34 | + | } |
|
35 | + | outline |
|
36 | + | } |
21 | 21 | #' share the same name we only keep the last one. |
|
22 | 22 | #' Although names are preserved other attributes such as font |
|
23 | 23 | #' comments and properties are not guaranteed to be preserved. |
|
24 | - | #' |
|
24 | + | #' @return Either a [bm_list()] or [bm_font()] object. |
|
25 | + | #' See Details for more info. |
|
25 | 26 | #' @param ... [bm_bitmap()], [bm_list()], and/or [bm_font()] objects to combine. |
|
26 | 27 | #' @examples |
|
27 | 28 | #' font_file <- system.file("fonts/spleen/spleen-8x16.hex.gz", package = "bittermelon") |
7 | 7 | #' @inheritParams bm_clamp |
|
8 | 8 | #' @param .f A function to execute. |
|
9 | 9 | #' @param ... Additional arguments to `.f`. |
|
10 | + | #' @return The return value of `.f`. |
|
10 | 11 | #' @examples |
|
11 | 12 | #' font_file <- system.file("fonts/spleen/spleen-8x16.hex.gz", package = "bittermelon") |
|
12 | 13 | #' font <- read_hex(font_file) |
32 | 32 | as_bm_bitmap.matrix(as.matrix(x)) |
|
33 | 33 | } |
|
34 | 34 | ||
35 | + | #' @inheritParams as_bm_list |
|
36 | + | #' @rdname as_bm_bitmap |
|
37 | + | #' @param direction For horizontal binding either "left-to-right" (default) or its aliases "ltr" and "lr" |
|
38 | + | #' OR "right-to-left" or its aliases "rtl" and "rl". |
|
39 | + | #' For vertical binding either "top-to-bottom" (default) or its aliases "ttb" and "tb" |
|
40 | + | #' OR "bottom-to-top" or its aliases "btt" and "bt". |
|
41 | + | #' The `direction` argument is not case-sensitive. |
|
42 | + | #' @examples |
|
43 | + | #' font_file <- system.file("fonts/fixed/4x6.yaff.gz", package = "bittermelon") |
|
44 | + | #' font <- read_yaff(font_file) |
|
45 | + | #' bm <- as_bm_bitmap("RSTATS", font = font) |
|
46 | + | #' print(bm, px = px_ascii) |
|
47 | + | #' bm <- as_bm_bitmap("RSTATS", direction = "top-to-bottom", font = font) |
|
48 | + | #' print(bm, px = px_ascii) |
|
49 | + | #' @export |
|
50 | + | as_bm_bitmap.character <- function(x, ..., |
|
51 | + | direction = "left-to-right", |
|
52 | + | font = bm_font()) { |
|
53 | + | bml <- as_bm_list(x, font = font) |
|
54 | + | ||
55 | + | is_ltr <- c(tolower(direction) %in% c("left-to-right", "ltr", "lr")) |
|
56 | + | is_rtl <- c(tolower(direction) %in% c("right-to-left", "rtl", "rl")) |
|
57 | + | is_ttb <- c(tolower(direction) %in% c("top-to-bottom", "ttb", "tb")) |
|
58 | + | is_bbt <- c(tolower(direction) %in% c("bottom-to-top", "bbt", "bt")) |
|
59 | + | stopifnot(is_ltr || is_rtl || is_ttb || is_bbt) |
|
60 | + | if (is_ltr || is_rtl) |
|
61 | + | bm <- bm_call(bml, cbind, direction = direction) |
|
62 | + | else |
|
63 | + | bm <- bm_call(bml, rbind, direction = direction) |
|
64 | + | bm |
|
65 | + | } |
|
66 | + | ||
35 | 67 | #' @rdname as_bm_bitmap |
|
36 | 68 | #' @param width Desired width of bitmap |
|
37 | 69 | #' @param height Desired height of bitmap |
Learn more Showing 2 files with coverage changes found.
R/bm_outline.R
R/bm_compress.R
Files | Coverage |
---|---|
R | 0.20% 92.30% |
Project Totals (38 files) | 92.30% |
d7f4aa1
c9b26ba
0a4f878
6cb8db6
8e7e3dc
76dd8ea
9180dd7
1e8074f
5519f31
bf25337
d883e9a
33686f7
8b4e3d8
5fb4695
ce801a9
e03f791