func (i Interval) ApproxEqual(other Interval) bool {
	if i.IsEmpty() {
		return other.Length() <= 2*epsilon
	}
	if other.IsEmpty() {
		return i.Length() <= 2*epsilon
	}
	return math.Abs(other.Lo-i.Lo) <= epsilon &&
		math.Abs(other.Hi-i.Hi) <= epsilon
}
ApproxEqual reports whether the interval can be transformed into the
given interval by moving each endpoint a small distance.
The empty interval is considered to be positioned arbitrarily on the
real line, so any interval with a small enough length will match
the empty interval.
package r1
import (
	"fmt"
	"math"
)
type Interval struct {
	Lo, Hi float64
}
func EmptyInterval() Interval { return Interval{1, 0} }
func IntervalFromPoint(p float64) Interval { return Interval{p, p} }
func (i Interval) IsEmpty() bool { return i.Lo > i.Hi }
func (i Interval) Equal(oi Interval) bool {
	return i == oi || i.IsEmpty() && oi.IsEmpty()
}
func (i Interval) Center() float64 { return 0.5 * (i.Lo + i.Hi) }
func (i Interval) Length() float64 { return i.Hi - i.Lo }
func (i Interval) Contains(p float64) bool { return i.Lo <= p && p <= i.Hi }
func (i Interval) ContainsInterval(oi Interval) bool {
	if oi.IsEmpty() {
		return true
	}
	return i.Lo <= oi.Lo && oi.Hi <= i.Hi
}
func (i Interval) InteriorContains(p float64) bool {
	return i.Lo < p && p < i.Hi
}
func (i Interval) InteriorContainsInterval(oi Interval) bool {
	if oi.IsEmpty() {
		return true
	}
	return i.Lo < oi.Lo && oi.Hi < i.Hi
}
func (i Interval) Intersects(oi Interval) bool {
	if i.Lo <= oi.Lo {
		return oi.Lo <= i.Hi && oi.Lo <= oi.Hi  
	}
	return i.Lo <= oi.Hi && i.Lo <= i.Hi  
}
func (i Interval) InteriorIntersects(oi Interval) bool {
	return oi.Lo < i.Hi && i.Lo < oi.Hi && i.Lo < i.Hi && oi.Lo <= oi.Hi
}
func (i Interval) Intersection(j Interval) Interval {
	return Interval{
		Lo: math.Max(i.Lo, j.Lo),
		Hi: math.Min(i.Hi, j.Hi),
	}
}
func (i Interval) AddPoint(p float64) Interval {
	if i.IsEmpty() {
		return Interval{p, p}
	}
	if p < i.Lo {
		return Interval{p, i.Hi}
	}
	if p > i.Hi {
		return Interval{i.Lo, p}
	}
	return i
}
func (i Interval) ClampPoint(p float64) float64 {
	return math.Max(i.Lo, math.Min(i.Hi, p))
}
func (i Interval) Expanded(margin float64) Interval {
	if i.IsEmpty() {
		return i
	}
	return Interval{i.Lo - margin, i.Hi + margin}
}
func (i Interval) Union(other Interval) Interval {
	if i.IsEmpty() {
		return other
	}
	if other.IsEmpty() {
		return i
	}
	return Interval{math.Min(i.Lo, other.Lo), math.Max(i.Hi, other.Hi)}
}
func (i Interval) String() string { return fmt.Sprintf("[%.7f, %.7f]", i.Lo, i.Hi) }
const (
	epsilon = 1e-15
	dblEpsilon = 2.220446049250313e-16
)