trevorld / bittermelon

Compare e03f791 ... +14 ... d7f4aa1

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

Learn more about Codecov Flags here.

Showing 16 of 53 files from the diff.
Newly tracked file
R/bm_outline.R created.

@@ -0,0 +1,36 @@
Loading
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 +
}

@@ -43,5 +43,7 @@
Loading
43 43
as_bm_list.character <- function(x, ..., font = bm_font()) {
44 44
    x <- paste(x, collapse = "")
45 45
    ucp <- str2ucp(x)
46 -
    as_bm_list(font[ucp])
46 +
    bml <- as_bm_list(font[ucp])
47 +
    stopifnot(!any(sapply(bml, is.null)))
48 +
    bml
47 49
}

@@ -21,7 +21,8 @@
Loading
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,6 +7,7 @@
Loading
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,6 +32,38 @@
Loading
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

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Learn more Showing 2 files with coverage changes found.

New file R/bm_outline.R
New
Loading file...
Changes in R/bm_compress.R
-2
+2
Loading file...
Files Coverage
R 0.20% 92.30%
Project Totals (38 files) 92.30%
Loading