Ops.bm_object: S3 Ops group generic methods for bitmap objects

Ops.bm_bitmapR Documentation

S3 Ops group generic methods for bitmap objects

Description

The S3 Ops group generic methods for bm_bitmap() objects are simply the result of the generic integer matrix method cast back to a binary bm_bitmap() object (which is an integer matrix of ones and zeros). The S3 Ops group generic methods for bm_list() and bm_font() objects simply returns another object with that operator applied to every bitmap in the original object. Since base::which() does not automatically cast its argument to a logical value we also redefine it as a generic and besides a default method which simply calls base:which() we offer a which.bm_bitmap() method that first casts the bitmap to logical before calling base::which().

Usage

## S3 method for class 'bm_bitmap'
Ops(e1, e2)

## S3 method for class 'bm_list'
Ops(e1, e2)

which(x, arr.ind = FALSE, useNames = TRUE)

## Default S3 method:
which(x, arr.ind = FALSE, useNames = TRUE)

## S3 method for class 'bm_bitmap'
which(x, arr.ind = FALSE, useNames = TRUE)

Arguments

e1, e2

objects.

x

a logical vector or array. NAs are allowed and omitted (treated as if FALSE).

arr.ind

logical; should array indices be returned when x is an array? Anything other than a single true value is treated as false.

useNames

logical indicating if the value of arrayInd() should have (non-null) dimnames at all.

Value

which.bm_bitmap() returns a logical vector. The various Ops.bm_bitmap methods return a bm_bitmap() object. The various Ops.bm_list methods return a bm_list() object.

See Also

base::Ops

Examples

  font_file <- system.file("fonts/spleen/spleen-8x16.hex.gz", package = "bittermelon")
  font <- read_hex(font_file)

  # Examples applied to individual bitmaps
  capital_r <- font[[str2ucp("R")]]
  print(!capital_r, px = px_ascii)
  capital_b <- font[[str2ucp("B")]]
  print(capital_r & capital_b, px = px_ascii)
  print(capital_r | capital_b, px = px_ascii)
  print(capital_r + 1L, px = px_ascii)
  print(capital_r + 1L > 1L, px = px_ascii)
  which(capital_r > 0L)

  # Examples applied to `bm_list()` objects
  bml <- font[c("U+0023", "U+0052", "U+0053", "U+0054", "U+0041", "U+0054", "U+0053")] # #RSTATS
  bml <- as_bm_list(bml)
  bm <- do.call(cbind, bml)
  print(bm, px = px_ascii)

  bml <- !bml
  bm <- do.call(cbind, bml)
  print(bm, px = px_ascii)

  bml <- 2 * (bml + 1L)
  bm <- do.call(cbind, bml)
  print(bm, px = px_ascii)


bittermelon documentation built on Feb. 16, 2023, 8:08 p.m.