Expand or contract intervals
Description
It is often useful to shrink or grow each interval in a set of
intervals: to smooth over small, uninteresting gaps, or to address
possible imprecision resulting from floating point arithmetic. The
expand
and contract
methods implement this, using either
absolute or relative difference.
Usage
1 2 3 4 5 
Arguments
x 
An 
delta 
A nonnegative adjustement value. A vector is permitted, and its entries will be recycled if necessary. 
type 
Should adjustment be based on relative or absolute difference. When

Value
A single object of appropriate class, with endpoint positions adjusted
as requested. Expansion returns an object with the same dimension as
x
; contraction may lead to the elimination of nowempty rows.
Note
Here, the relative difference between x and y is x  y/max(x, y).
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37  # Using adjustment to remove small gaps
x < Intervals( c(1,10,100,8,50,200), type = "Z" )
close_intervals( contract( reduce( expand(x, 1) ), 1 ) )
# Finding points for which, as a result of possible floating point
# error, intersection may be ambiguous. Whether y1 intersects y2[2,]
# depends on precision.
delta < .Machine$double.eps^0.5
y1 < Intervals( c( .5, 1  delta / 2 ) )
y2 < Intervals( c( .25, 1, .75, 2 ) )
# Nominal
interval_intersection( y1, y2 )
# Inner limit
inner < interval_intersection(
contract( y1, delta, "relative" ),
contract( y2, delta, "relative" )
)
# Outer limit
outer < interval_intersection(
expand( y1, delta, "relative" ),
expand( y2, delta, "relative" )
)
# The ambiguous set, corresponding to points which may or may not be in
# the intersection  depending on numerical values for endpoints
# which are, with respect to relative difference, indistinguishable from
# the nominal values.
interval_difference( outer, inner )

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker. Vote for new features on Trello.