intersectsEnvelopeCoords static method

bool intersectsEnvelopeCoords(
  1. Coordinate p1,
  2. Coordinate p2,
  3. Coordinate q1,
  4. Coordinate q2,
)

Tests whether the envelope defined by p1-p2 and the envelope defined by q1-q2 intersect.

@param p1 one extremal point of the envelope P @param p2 another extremal point of the envelope P @param q1 one extremal point of the envelope Q @param q2 another extremal point of the envelope Q @return true if Q intersects P

Implementation

static bool intersectsEnvelopeCoords(
    Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) {
  double minq = math.min(q1.x, q2.x);
  double maxq = math.max(q1.x, q2.x);
  double minp = math.min(p1.x, p2.x);
  double maxp = math.max(p1.x, p2.x);

  if (minp > maxq) return false;
  if (maxp < minq) return false;

  minq = math.min(q1.y, q2.y);
  maxq = math.max(q1.y, q2.y);
  minp = math.min(p1.y, p2.y);
  maxp = math.max(p1.y, p2.y);

  if (minp > maxq) return false;
  if (maxp < minq) return false;
  return true;
}