# Point to interval
to <- Intervals( c(0,5,3,Inf) )
from <- -5:10
plot( from, distance_to_nearest( from, to ), type = "l" )
segments( to[,1], 1, pmin(to[,2], par("usr")[2]), 1, col = "red" )
# Interval to interval
from <- Intervals( c(-Inf,-Inf,3.5,-1,1,4) )
distance_to_nearest( from, to )
Run the code above in your browser using DataLab