cdm/src/main/java/ucar/ma2/Range.java
public boolean intersects(Range r) {
    if ((length() == 0) || (r.length() == 0))
      return false;
    if (this == VLEN || r == VLEN)
      return true;

    int last = Math.min(this.last(), r.last());
    int resultStride = stride * r.stride();

    int useFirst;
    if (resultStride == 1) {   // both strides are 1
      useFirst = Math.max(this.first(), r.first());

    } else if (stride == 1) { // then r has a stride

      if (r.first() >= first())
        useFirst = r.first();
      else {
        int incr = (first() - r.first()) / resultStride;
        useFirst = r.first() + incr * resultStride;
        if (useFirst < first()) useFirst += resultStride;
      }

    } else if (r.stride() == 1) { // then this has a stride

      if (first() >= r.first())
        useFirst = first();
      else {
        int incr = (r.first() - first()) / resultStride;
        useFirst = first() + incr * resultStride;
        if (useFirst < r.first()) useFirst += resultStride;
      }

    } else {
      throw new UnsupportedOperationException("Intersection when both ranges have a stride");
    }

    return (useFirst <= last);
  }
public boolean intersects(Range r) {
    if ((length() == 0) || (r.length() == 0))
      return false;
    if (this == VLEN || r == VLEN)
      return true;

    int last = Math.min(this.last(), r.last());
    int resultStride = stride * r.stride();

    int useFirst;
    if (resultStride == 1) {   // both strides are 1
      useFirst = Math.max(this.first(), r.first());

    } else if (stride == 1) { // then r has a stride

      if (r.first() >= first())
        useFirst = r.first();
      else {
        int incr = (first() - r.first()) / resultStride;
        useFirst = r.first() + incr * resultStride;
        if (useFirst < first()) useFirst += resultStride;
      }

    } else if (r.stride() == 1) { // then this has a stride

      if (first() >= r.first())
        useFirst = first();
      else {
        int incr = (r.first() - first()) / resultStride;
        useFirst = first() + incr * resultStride;
        if (useFirst < r.first()) useFirst += resultStride;
      }

    } else {
      throw new UnsupportedOperationException("Intersection when both ranges have a stride");
    }

    return (useFirst <= last);
  }
Determine if a given Range intersects this one.
NOTE: we dont yet support intersection when both Ranges have strides

@param r range to intersect
@return true if they intersect
@throws UnsupportedOperationException if both Ranges have strides