Does an interval intersect with another one?

      No Comments on Does an interval intersect with another one?

Simple question, simple answer:

// does this interval a intersect b?
    public boolean intersects(Interval b) {
        Interval a = this;
        if (b.left <= a.right && b.left >= a.left) { return true; }
        if (a.left <= b.right && a.left >= b.left) { return true; }
        return false;
    }

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.