Does the circle intersect with this rect?
192155
def intersects_circle(self, pt, radius):
    """"""
    # How this works: http://stackoverflow.com/a/402010
    rect_corner = self.size / 2  # relative to the rect center
    circle_center = (pt - self.center).abs()  # relative to the rect center

    # Is the circle far from the rect?
    if (circle_center.x > rect_corner.x + radius or
        circle_center.y > rect_corner.y + radius):
      return False

    # Is the circle center inside the rect or near one of the edges?
    if (circle_center.x <= rect_corner.x or
        circle_center.y <= rect_corner.y):
      return True

    # Does the circle contain the corner of the rect?
    return circle_center.dist_sq(rect_corner) <= radius**2
777401
def is_colliding(self, other):
        """"""
        if isinstance(other, AABoundingBox):
            if self.rect.colliderect(other.rect):
                return True
            return False
557688
def segments_touch_2D(ab, cd):
    '''
    
    '''
    return segments_colinear(ab, cd) | np.isfinite(segment_intersection_2D(ab, cd)[0])
678411
function circleCircleIntersection(p1, p2) {
        var d = distance(p1, p2),
            r1 = p1.radius,
            r2 = p2.radius;

        // if to far away, or self contained - can't be done
        if ((d >= (r1 + r2)) || (d <= Math.abs(r1 - r2))) {
            return [];
        }

        var a = (r1 * r1 - r2 * r2 + d * d) / (2 * d),
            h = Math.sqrt(r1 * r1 - a * a),
            x0 = p1.x + a * (p2.x - p1.x) / d,
            y0 = p1.y + a * (p2.y - p1.y) / d,
            rx = -(p2.y - p1.y) * (h / d),
            ry = -(p2.x - p1.x) * (h / d);

        return [{x: x0 + rx, y : y0 - ry },
                {x: x0 - rx, y : y0 + ry }];
    }
919876
public boolean intersect(Envelope3D other) {
		if (isEmpty() || other.isEmpty())
			return false;

		if (other.xmin > xmin)
			xmin = other.xmin;

		if (other.xmax < xmax)
			xmax = other.xmax;

		if (other.ymin > ymin)
			ymin = other.ymin;

		if (other.ymax < ymax)
			ymax = other.ymax;

		if (other.zmin > zmin)
			zmin = other.zmin;

		if (other.zmax < zmax)
			zmax = other.zmax;

		boolean bIntersecting = xmin <= xmax && ymin <= ymax && zmin <= zmax;

		if (!bIntersecting)
			setEmpty();

		return bIntersecting;
	}
268588
def circle_intersection(self, p: "Point2", r: Union[int, float]) -> Set["Point2"]:
        
        assert self != p
        distanceBetweenPoints = self.distance_to(p)
        assert r > distanceBetweenPoints / 2
        # remaining distance from center towards the intersection, using pythagoras
        remainingDistanceFromCenter = (r ** 2 - (distanceBetweenPoints / 2) ** 2) ** 0.5
        # center of both points
        offsetToCenter = Point2(((p.x - self.x) / 2, (p.y - self.y) / 2))
        center = self.offset(offsetToCenter)

        # stretch offset vector in the ratio of remaining distance from center to intersection
        vectorStretchFactor = remainingDistanceFromCenter / (distanceBetweenPoints / 2)
        v = offsetToCenter
        offsetToCenterStretched = Point2((v.x * vectorStretchFactor, v.y * vectorStretchFactor))

        # rotate vector by 90° and -90°
        vectorRotated1 = Point2((offsetToCenterStretched.y, -offsetToCenterStretched.x))
        vectorRotated2 = Point2((-offsetToCenterStretched.y, offsetToCenterStretched.x))
        intersect1 = center.offset(vectorRotated1)
        intersect2 = center.offset(vectorRotated2)
        return {intersect1, intersect2}
134369
def intersects(self, other_grid_coordinates):
        
        ogc = other_grid_coordinates  # alias
        # for explanation: http://stackoverflow.com/questions/306316/determine-if-two-rectangles-overlap-each-other
        # Note the flipped y-coord in this coord system.
        ax1, ay1, ax2, ay2 = self.ULC.lon, self.ULC.lat, self.LRC.lon, self.LRC.lat
        bx1, by1, bx2, by2 = ogc.ULC.lon, ogc.ULC.lat, ogc.LRC.lon, ogc.LRC.lat
        if ((ax1 <= bx2) and (ax2 >= bx1) and (ay1 >= by2) and (ay2 <= by1)):
            return True
        else:
            return False
322962
public boolean intersects(double x, double y, double w, double h) {
		return intersects(new Rectangle2D.Double(x, y, w, h));
	}
206200
@Pure
	private static boolean intersectsCoplanarTriangle(
			int i0, int i1, int con, double[] s1, double[] s2, double[] u1, double[] u2, double[] u3) {
		double Ax,Ay;

		Ax = s2[i0] - s1[i0];
		Ay = s2[i1] - s1[i1];

		// test edge U0,U1 against V0,V1
		if (intersectEdgeEdge(i0, i1, con, Ax, Ay, s1, u1, u2)) return true;
		// test edge U1,U2 against V0,V1
		if (intersectEdgeEdge(i0, i1, con, Ax, Ay, s1, u2, u3)) return true;
		// test edge U2,U1 against V0,V1
		if (intersectEdgeEdge(i0, i1, con, Ax, Ay, s1, u3, u1)) return true;

		return false;
	}
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;
	}
465258
static boolean isInCircle(float x, float y, float centerX, float centerY, float
            radius) {
        return Math.abs(x - centerX) < radius && Math.abs(y - centerY) < radius;
    }
847740
def intersects_segment(self, other):
		
		i = _bisect_left(self, other)
		return ((i != 0) and (other[0] < self[i-1][1])) or ((i != len(self)) and (other[1] > self[i][0]))
139219
boolean intersects(LongBitSet other) {
		// Depends on the ghost bits being clear!
		int pos = Math.min(numWords, other.numWords);
		while (--pos >= 0) {
			if ((bits[pos] & other.bits[pos]) != 0)
				return true;
		}
		return false;
	}
637565
function (ctx, x, y, radius, shadow) {
            // pi * r^2 = (2s)^2  =>  s = r * sqrt(pi)/2
            var size = radius * Math.sqrt(Math.PI) / 2;
            ctx.rect(x - size, y - size, size + size, size + size);
        }
499584
protected boolean intersectsX (IRay3 ray, float x) {
        IVector3 origin = ray.origin(), dir = ray.direction();
        float t = (x - origin.x()) / dir.x();
        if (t < 0f) {
            return false;
        }
        float iy = origin.y() + t*dir.y(), iz = origin.z() + t*dir.z();
        return iy >= _minExtent.y && iy <= _maxExtent.y &&
            iz >= _minExtent.z && iz <= _maxExtent.z;
    }
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)
588337
def isRectangular(self):
        
# if any two of the 4 corners are equal return false
        upper = (self.ur - self.ul).unit
        if not bool(upper):
            return False
        right = (self.lr - self.ur).unit
        if not bool(right):
            return False
        left  = (self.ll - self.ul).unit
        if not bool(left):
            return False
        lower = (self.lr - self.ll).unit
        if not bool(lower):
            return False
        eps = 1e-5
# we now have 4 sides of length 1. If 3 of them have 90 deg angles,
# then it is a rectangle -- we check via scalar product == 0
        return abs(sum(map(lambda x,y: x*y, upper, right))) <= eps and \
               abs(sum(map(lambda x,y: x*y, upper, left))) <= eps and \
               abs(sum(map(lambda x,y: x*y, left, lower))) <= eps