Identify overlapping number_line objects

overlaps(x, y, methods = 8)

overlap(x, y)

none(x, y)

exact(x, y)

across(x, y)

x_across_y(x, y)

y_across_x(x, y)

chain(x, y)

x_chain_y(x, y)

y_chain_x(x, y)

aligns_start(x, y)

x_aligns_start_y(x, y)

y_aligns_start_x(x, y)

aligns_end(x, y)

x_aligns_end_y(x, y)

y_aligns_end_x(x, y)

inbetween(x, y)

x_inbetween_y(x, y)

y_inbetween_x(x, y)

overlap_method(x, y)

include_overlap_method(methods)

exclude_overlap_method(methods)

overlap_method_codes(methods)

overlap_method_names(methods)

Arguments

x

[number_line]

y

[number_line]

methods

[charater|integer]. Type of overlap. See as.data.frame(diyar::overlap_methods$options) for options.

Value

logical; character

Details

There are 6 mutually exclusive types of overlap;

Except exact(), each type of overlap has two variations;

There are two mutually inclusive types of overlap;

  • overlap() - a convenient option to select "ANY" and "ALL" type of overlap.

  • none() - a convenient option to select "NO" type of overlap.

Selecting multiple types of overlap;

  • overlaps() - select specific type(s) of overlap.

  • overlap_method() - return the type of overlap for a pair of number_line objects.

  • overlap_method_codes() - return the corresponding overlap method code for a specific type(s) of overlap.

  • overlap_method_names() - return the corresponding type(s) of overlap for a specific overlap code.

  • include_overlap_method() - return a character(1) value for specified type(s) of overlap.

  • exclude_overlap_method() - return a character(1) value for all type(s) of overlap except those specified.

Examples

a <- number_line(-100, 100)
g <- number_line(100, 100)
overlaps(a, g)
#> [1] TRUE

# It's neither an "exact" or "chain"-overlap
overlaps(a, g, methods = "exact|chain")
#> [1] FALSE

# It's an "aligns_end"-overlap
overlap_method(a, g)
#> [1] "x_aligns_end_y"
overlaps(a, g, methods = "exact|chain|x_aligns_end_y")
#> [1] TRUE

# Corresponding overlap code
overlap_method_codes("exact|chain|x_aligns_end_y")
#> [1] 1411
include_overlap_method(c("exact", "chain", "x_aligns_end_y"))
#> [1] 1411

# Corresponding overlap name
overlap_method_names(overlap_method_codes("exact|chain|x_aligns_end_y"))
#> [1] "exact|x_aligns_end_y|x_chain_y|y_chain_x"

# Every other type overlap
exclude_overlap_method(c("exact", "chain", "x_aligns_end_y"))
#> [1] 4137
overlap_method_names(exclude_overlap_method(c("exact", "chain", "x_aligns_end_y")))
#> [1] "x_across_y|x_aligns_start_y|x_inbetween_y|y_across_x|y_aligns_end_x|y_aligns_start_x|y_inbetween_x"

# All the above is based on tests for each specific type of overlap as seen below
none(a, g)
#> [1] FALSE
exact(a, g)
#> [1] FALSE
across(a, g)
#> [1] FALSE
x_across_y(a, g)
#> [1] FALSE
y_across_x(a, g)
#> [1] FALSE
chain(a, g)
#> [1] FALSE
x_chain_y(a, g)
#> [1] FALSE
y_chain_x(a, g)
#> [1] FALSE
inbetween(a, g)
#> [1] FALSE
x_inbetween_y(a, g)
#> [1] FALSE
y_inbetween_x(a, g)
#> [1] FALSE
aligns_start(a, g)
#> [1] FALSE
x_aligns_start_y(a, g)
#> [1] FALSE
y_aligns_start_x(a, g)
#> [1] FALSE
aligns_end(a, g)
#> [1] TRUE
x_aligns_end_y(a, g)
#> [1] TRUE
y_aligns_end_x(a, g)
#> [1] FALSE