Check if two rectangles intersect
10162
def intersect(a, b):
    
    if a[x0] == a[x1] or a[y0] == a[y1]:
        return False
    if b[x0] == b[x1] or b[y0] == b[y1]:
        return False
    return a[x0] <= b[x1] and b[x0] <= a[x1] and a[y0] <= b[y1] and b[y0] <= a[y1]
347980
def _check_intersection(self, other):
        """"""
        # pylint: disable=C0123
        props = ["_callables_db", "_reverse_callables_db", "_modules_dict"]
        for prop in props:
            self_dict = getattr(self, prop)
            other_dict = getattr(other, prop)
            keys_self = set(self_dict.keys())
            keys_other = set(other_dict.keys())
            for key in keys_self & keys_other:
                svalue = self_dict[key]
                ovalue = other_dict[key]
                same_type = type(svalue) == type(ovalue)
                if same_type:
                    list_comp = isinstance(svalue, list) and any(
                        [item not in svalue for item in ovalue]
                    )
                    str_comp = isinstance(svalue, str) and svalue != ovalue
                    dict_comp = isinstance(svalue, dict) and svalue != ovalue
                    comp = any([list_comp, str_comp, dict_comp])
                if (not same_type) or (same_type and comp):
                    emsg = "Conflicting information between objects"
                    raise RuntimeError(emsg)
920230
private static <T> List<T> intersect(T[] first, T[] second) {
    List<T> result = new ArrayList<>();
    for (T a : first) {
      for (T b : second) {
        if (a.equals(b)) {
          result.add(b);
          break;
        }
      }
    }
    return result;
  }
711817
function(rect, opt) {

        rect = g.rect(rect);
        opt = joint.util.defaults(opt || {}, { strict: false });

        var method = opt.strict ? 'containsRect' : 'intersect';

        return this.getElements().filter(function(el) {
            return rect[method](el.getBBox());
        });
    }
914152
public boolean intersectsWithOrTouches(Range other) {
        return contains(other.lower) || contains(other.upper - 1) || (other.upper > upper && other.lower < lower) ||
                other.lower == upper || other.upper == lower;
    }
1191752
private int countAreas(Area a, Rectangular r)
    {
        int ret = 0;
        
        for (int i = 0; i < a.getChildCount(); i++)
        {
            Area n = a.getChildAt(i);
            if (a.getTopology().getPosition(n).intersects(r))
                ret++;
        }
        return ret;
    }
561712
@Override
	@Pure
	public boolean intersects(Shape2D<?, ?, ?, ?, ?, ? extends Rectangle2afp<?, ?, ?, ?, ?, ?>> rectangle) {
		if (boundsIntersects(rectangle)) {
			final double x = getX();
			final double y = getY();
			final Rectangle2afp<?, ?, ?, ?, ?, ?> box = rectangle.toBoundingBox();
			final double minx = box.getMinX();
			final double miny = box.getMinY();
			final double maxx = box.getMaxX();
			final double maxy = box.getMaxY();

			return MathUtil.min(
					Segment2afp.calculatesDistanceSegmentPoint(minx, miny, maxx, miny, x, y),
					Segment2afp.calculatesDistanceSegmentPoint(minx, miny, minx, maxy, x, y),
					Segment2afp.calculatesDistanceSegmentPoint(maxx, miny, maxx, maxy, x, y),
					Segment2afp.calculatesDistanceSegmentPoint(minx, maxy, maxx, maxy, x, y)) <= this.radius;
		}
		return false;
	}
87064
def windows_intersection(windows):
    

    def intersect2(left, right):
        if left == right:
            return left
        elif left is (None, None):
            return right
        elif right is (None, None):
            return left
        elif left[0] is None:
            if right[0] is None:
                return None, min((left[1], right[1]))
            elif right[1] is None:
                if left[1] <= right[0]:
                    return left[1], right[0]
                else:
                    return None
            elif right[0] <= left[1]:
                return right[0], left[1]
            else:
                return None
        elif left[1] is None:
            if right[0] is None:
                return left[0], right[1]
            else:
                return right  # assumes left[0] <= right[0]
        # None not in left
        elif right[0] is None:
            return left[0], min((left[1], right[1]))
        elif right[1] is None:
            if left[1] >= right[0]:
                return right[0], left[1]
            else:
                return None
        assert None not in left and None not in right and left[0] < right[1]
        if left[1] >= right[0]:
            if right[1] > left[1]:
                return right[0], left[1]
            else:
                return right
        return None

    if len(windows) == 1:
        return windows
    left_none = []
    right_none = []
    otherwise = []
    for window in windows:
        assert window is not None, None
        if window[0] is None:
            left_none.append(window)
        elif window[1] is None:
            right_none.append(window)
        else:
            otherwise.append(window)

    done = []
    todo = left_none + sorted(otherwise)
    for window in todo:
        if not done:
            done.append(window)
            continue
        res = intersect2(done.pop(), window)
        if res:
            done.append(res)
    return done
571851
def intersection(self, other, ignore_conflicts=False):
        """"""
        result = self.copy()
        result.intersection_update(other, ignore_conflicts)
        return result
340222
function intersects(a, b) {
	return a.position[0] < b.position[0] + b.size[0] && a.position[0] + a.size[0] > b.position[0]
	    && a.position[1] < b.position[1] + b.size[1] && a.position[1] + a.size[1] > b.position[1]
}
10993
function intersect(a, b, not) {
  return a.filter((c) => {
    const index = ~indexOfDeclaration(b, c);
    return not ? !index : index;
  });
}
518162
public boolean intersects(Rectangle2D r) {
		if(np==0)return false;
		Line2D line = new Line2D.Double(x[0],y[0],x[0],y[0]);
		for (int i = 1; i < np; i++) {
			line.setLine(x[i-1], y[i-1], x[i], y[i]);
			if(line.intersects(r))return true;
		}
		return false;
	}
984569
function collides(element_one, element_two) {

	var result,
	    rect1,
	    rect2;

	if (element_one.nodeName) {
		rect1 = element_one.getBoundingClientRect();
	} else {
		rect1 = element_one;
	}

	if (element_two.nodeName) {
		rect2 = element_two.getBoundingClientRect();
	} else {
		rect2 = element_two;
	}

	result = !(
		rect1.top    > rect2.bottom ||
		rect1.right  < rect2.left ||
		rect1.bottom < rect2.top ||
		rect1.left   > rect2.right
	);

	return result;
}
418221
private boolean intersects(Rectangle other) {
		Rectangle box = other;
		Circle circle = this;
		
		if (box.contains(x+radius,y+radius)) {
			return true;
		}
		
		float x1 = box.getX();
		float y1 = box.getY();
		float x2 = box.getX() + box.getWidth();
		float y2 = box.getY() + box.getHeight();
		
		Line[] lines = new Line[4];
		lines[0] = new Line(x1,y1,x2,y1);
		lines[1] = new Line(x2,y1,x2,y2);
		lines[2] = new Line(x2,y2,x1,y2);
		lines[3] = new Line(x1,y2,x1,y1);
		
		float r2 = circle.getRadius() * circle.getRadius();
		
		Vector2f pos = new Vector2f(circle.getCenterX(), circle.getCenterY());
		
		for (int i=0;i<4;i++) {
			float dis = lines[i].distanceSquared(pos);
			if (dis < r2) {
				return true;
			}
		}
		
		return false;
	}
439184
def collides(self, other):
        """"""

        angle = self.angle
        width = self.width
        height = self.height

        if angle == 0:
            return other.collides(Rect(-0.5 * width,
                                       -0.5 * height, width, height))

        # Phase 1
        #
        #  * Form bounding box on tilted rectangle P.
        #  * Check whether bounding box and other intersect.
        #  * If not, then self and other do not intersect.
        #  * Otherwise proceed to Phase 2.

        # Now perform the standard rectangle intersection test.

        if self.is_bbox_not_intersecting(other):
            return False

        # Phase 2
        #
        # If we get here, check the edges of self to see
        #  * if one of them excludes all vertices of other.
        #  * If so, then self and other do not intersect.
        #  * (If not, then self and other do intersect.)

        return not self.is_edge_not_excluding_vertices(other)
233607
function getIntersectionRect (rect1, rect2) {
  const intersectRect = {
    topLeft: {},
    bottomRight: {}
  };

  if (!doesIntersect(rect1, rect2)) {
    return;
  }

  const rect1Points = rectToPoints(rect1);
  const rect2Points = rectToPoints(rect2);

  if (rect1.width >= 0) {
    if (rect2.width >= 0) {
      intersectRect.topLeft.x = Math.max(rect1Points.topLeft.x, rect2Points.topLeft.x);
      intersectRect.bottomRight.x = Math.min(rect1Points.bottomRight.x, rect2Points.bottomRight.x);
    } else {
      intersectRect.topLeft.x = Math.max(rect1Points.topLeft.x, rect2Points.bottomRight.x);
      intersectRect.bottomRight.x = Math.min(rect1Points.bottomRight.x, rect2Points.topLeft.x);
    }
  } else if (rect2.width >= 0) {
    intersectRect.topLeft.x = Math.min(rect1Points.topLeft.x, rect2Points.bottomRight.x);
    intersectRect.bottomRight.x = Math.max(rect1Points.bottomRight.x, rect2Points.topLeft.x);
  } else {
    intersectRect.topLeft.x = Math.min(rect1Points.topLeft.x, rect2Points.topLeft.x);
    intersectRect.bottomRight.x = Math.max(rect1Points.bottomRight.x, rect2Points.bottomRight.x);
  }

  if (rect1.height >= 0) {
    if (rect2.height >= 0) {
      intersectRect.topLeft.y = Math.max(rect1Points.topLeft.y, rect2Points.topLeft.y);
      intersectRect.bottomRight.y = Math.min(rect1Points.bottomRight.y, rect2Points.bottomRight.y);
    } else {
      intersectRect.topLeft.y = Math.max(rect1Points.topLeft.y, rect2Points.bottomRight.y);
      intersectRect.bottomRight.y = Math.min(rect1Points.bottomRight.y, rect2Points.topLeft.y);
    }
  } else if (rect2.height >= 0) {
    intersectRect.topLeft.y = Math.min(rect1Points.topLeft.y, rect2Points.bottomRight.y);
    intersectRect.bottomRight.y = Math.max(rect1Points.bottomRight.y, rect2Points.topLeft.y);
  } else {
    intersectRect.topLeft.y = Math.min(rect1Points.topLeft.y, rect2Points.topLeft.y);
    intersectRect.bottomRight.y = Math.max(rect1Points.bottomRight.y, rect2Points.bottomRight.y);
  }

  // Returns top-left and bottom-right points of intersected rectangle
  return intersectRect;

}
850414
public static boolean intersectsPointWithRectF(RectF _Rect, float _X, float _Y) {
        return _X > _Rect.left && _X < _Rect.right && _Y > _Rect.top && _Y < _Rect.bottom;
    }