SELECT "tbl"."" AS "col"
FROM (VALUES (1), (2), (3)) AS "tbl"
我试图看看两个矩形是否相交。至少有一个点必须在矩形中才能与它们相交。当我在python shell中运行我的代码时:
class Point:
'class that represents a point in the plane'
def __init__(self, xcoord=0, ycoord=0):
''' (Point,number, number) -> None
initialize point coordinates to (xcoord, ycoord)'''
self.x = xcoord
self.y = ycoord
class Rectangle:
def __init__(self, bottom_left, top_right, colour):
self.bottom_left = bottom_left
self.top_right = top_right
self.colour = colour
self.length = self.top_right.x - self.bottom_left.x
self.width = self.top_right.y - self.bottom_left.y
def intersects(self, given_rectangle):
if (self.bottom_left.x <= given_rectangle.bottom_left.x <= self.top_right.x) and (
self.bottom_left.y <= given_rectangle.bottom_left.y <= self.top_right.y):
return True
if (self.bottom_left.x <= given_rectangle.top_right.x <= self.top_right.x) and (
self.bottom_left.y <= given_rectangle.top_right.y <= self.top_right.y):
return True
return False
这应打印r1=Rectangle(Point(1,1), Point(2,2), "blue")
r2=Rectangle(Point(2,2.5), Point(3,3), "blue")
r3=Rectangle(Point(1.5,0),Point(1.7,3),"red")
r1.intersects(r3)
,但会打印True