本文整理汇总了Python中rectangle.Rectangle类的典型用法代码示例。如果您正苦于以下问题:Python Rectangle类的具体用法?Python Rectangle怎么用?Python Rectangle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Rectangle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
def update(viewAngleHorz):
print "update()"
# Get color image from camera
ret, img = camera.read() # img.shape 640x480 image
# Convert to hsv img
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# Keep only green objects
# higher s = less white, higher v = less black
lowerGreen = np.array([70, 70, 180])
upperGreen = np.array([110, 130,255])
filteredGreen = cv2.inRange(hsv, lowerGreen, upperGreen)
# Filter out small objects
filteredGreen = cv2.morphologyEx(filteredGreen, cv2.MORPH_OPEN, np.ones((3, 3)))
# Find all contours, counter is vector of points that are connected to make up a shape
contours, hierarchy = cv2.findContours(filteredGreen, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# Resetting values
foundHotTarget = False;
foundHorzTarget = False
# Parse contours, calculate distance and check if it's the hot target
for shape in contours:
target = Rectangle(*cv2.boundingRect(shape))
# Filter out small contours
if target.getArea() > 300 and target.getArea() < 10000:
# Compensate for horizontal view of the target
target.width = target.width / math.cos(viewAngle * math.PI / 180)
# If the width of the target is greater than its height then it's probably the hot target
if target.width >= target.height * 2.5:
foundHotTarget = True
distance = computeDistance(horizTarget.height, target.height)
if debugMode:
drawRect(img, target)
viewAngle = computeAngle(horizTarget.height, target.height, 228)
print "Distance: ", round(distance), ", Hot Target", viewAngle, viewAngleVert
# If the height of the target is greater than the its width its probably a vert target
if target.height >= target.width * 6:
foundHorzTarget = True
distance = computeDistance(vertTarget.height, target.height)
if debugMode:
drawRect(img, target)
viewAngle = computeAngle(vertTarget.height, target.height, 228)
print "Distance: ", round(distance), ", Vert Target", viewAngle, viewAngleVert
if debugMode:
cv2.imshow("color", img)
cv2.waitKey(10)
cv2.imshow("filtered", filteredGreen)
cv2.waitKey(10)
示例2: __init__
def __init__(self):
# self.id = random.uniform(0, 999999999)
Rectangle.__init__(self)
self.handler = Handler()
self.magnetos = Magnetos()
self.offset = Point()
self.pivot = Point()
self.selected = False
self.resizing = False
self.direction = NONE
self.control = AUTOMATIC
self.z = 0
self.hints = False
from ui.canvas import Canvas
self.canvas = Canvas()
self.handler.is_testing = self.canvas.is_testing
self.dash = []
self.thickness = 1.0
self.fill_style = COLOR
self.fill_color = Color(0.25, 0.25, 0.25, 0.25)
self.stroke_color = Color(0.25, 0.25, 0.25, 1.0)
self.gradient = Gradient()
示例3: add_rectangles_by_path
def add_rectangles_by_path(self, path1, path2, start_offset):
path_len = 0
for p in path1:
path_len += p.len
# path_len -= start_offset
first_shift = start_offset
second_shift = 0
pos_first_path = 0
pos_second_path = 0
first_len = first_shift
while first_len < path_len:
ed1 = path1[pos_first_path]
ed2 = path2[pos_second_path]
rectangle = Rectangle(ed1,ed2)
rectangle.add_diagonal(self.d, self.d + first_shift - second_shift)
rect_diag = rectangle.get_closest_diagonal(self.d + first_shift - second_shift)
self.add_diagonal_and_conj(rect_diag)
print "ADD DIAGS", rect_diag
if ed2.len - second_shift < ed1.len - first_shift:
pos_second_path += 1
first_shift += ed2.len - second_shift
first_len += ed2.len - second_shift
second_shift = 0
elif ed1.len - first_shift < ed2.len - second_shift:
pos_first_path += 1
first_len += ed1.len - first_shift
second_shift += ed1.len - first_shift
first_shift = 0
else:
first_len += ed1.len - first_shift
pos_second_path += 1
pos_first_path += 1
first_shift = 0
second_shift = 0
示例4: main
def main():
house = Point(10, 9)
print('House is at X:', house.x)
print('House is at Y:', house.y)
work = Point(5, 2)
print('House to work distance:', house.distance_to(work))
city = Rectangle(Point(5, 5), 10, 10)
print('City corner is:', city.bottom_left_corner)
print('City width:', city.w)
print('City height:', city.h)
print('House in city:', city.contains(house))
print('Work in city:', city.contains(work))
city_center = city.find_center()
print('City center:', city_center)
cats_house = Point(10, 9)
identical_city = Rectangle(Point(5, 5), 10, 10)
different_city = Rectangle(Point(13, 13), 10, 10)
print("My cat's house and mine are equal:", house == cats_house)
print('Two identical cities are equal:', city == identical_city)
print('Two different cities are equal:', city == different_city)
house.move_by(1, -1)
print('After moving my house:', house)
示例5: __init__
def __init__(self):
Rectangle.__init__(self)
self.hidden = False
self.position = 0.0
self.direction = NONE
self.control = Control()
self.control.limbus = True
示例6: main
def main(x0, y0, x1, y1):
rect = Rectangle(int(x0), int(y0), int(x1), int(y1))
msg = 'For the rectangle with corners located at ('
msg += str(x0) + ', ' + str(y0) + ') and ('
msg += str(x1) + ', ' + str(y1) + '):\n'
print(msg)
msg = 'The length is ' + str(rect.getLength())
msg += ' and the height is ' + str(rect.getHeight()) + '.'
print(msg)
msg = 'The area is ' + str(rect.getArea()) + '.'
print(msg)
示例7: move_rectangle
def move_rectangle(old_rec, dx, dy):
"""
Takes a rectangle and distances, and returns a new Rectangle object
moved by those coordinates.
"""
new_rec = Rectangle()
new_rec.height = old_rec.height
new_rec.width = old_rec.width
new_rec.corner = Point()
new_rec.corner.x = old_rec.corner.x + dx
new_rec.corner.y = old_rec.corner.y + dy
return new_rec
示例8: RectangleTest
class RectangleTest(unittest.TestCase):
def setUp(self):
self.rect = Rectangle()
def test_get_area(self):
area = self.rect.width * self.rect.height
self.assertEqual(self.rect.get_area(), area)
def test_get_perimeter(self):
perimeter = (self.rect.width + self.rect.height) * 2
self.assertEqual(self.rect.get_perimeter(), perimeter)
示例9: test_overlap
def test_overlap(self):
'''
Test overlap between circles and rectangles.
'''
new_rect1 = Rectangle(100, 100)
new_rect2 = Rectangle(50, 150, 50, 50)
circ1 = Circle(25)
circ2 = Circle(30, 0, -5)
self.assertEqual(-50, new_rect1.get_overlap(new_rect2))
self.assertEqual(new_rect1.get_overlap(new_rect2),
new_rect2.get_overlap(new_rect1))
self.assertEqual(-50, circ1.get_overlap(new_rect1))
self.assertEqual(circ1.get_overlap(new_rect1),
new_rect1.get_overlap(circ1))
self.assertAlmostEqual(math.sqrt(2)*25 - 25,
circ1.get_overlap(new_rect2))
self.assertEqual(circ1.get_overlap(new_rect2),
new_rect2.get_overlap(circ1))
self.assertEqual(-50, circ1.get_overlap(circ2))
self.assertEqual(circ1.get_overlap(circ2),
circ2.get_overlap(circ1))
circ1.set_position(80, 50)
self.assertEqual(-20, circ1.get_overlap(new_rect2))
self.assertEqual(circ1.get_overlap(new_rect2),
new_rect2.get_overlap(circ1))
示例10: __init__
def __init__(self):
Rectangle.__init__(self)
self.active = True
self.top = 0
self.left = 0
self.bottom = 0
self.right = 0
self.control = list()
index = 0
while index < 8:
control = Control()
self.control.append(control)
index += 1
示例11: add_diagonal_and_conj
def add_diagonal_and_conj(self, diag):
for old_diag in self.diagonals:
if diag.rectangle.e1 == old_diag.rectangle.e1 and diag.rectangle.e2 == old_diag.rectangle.e2:
if diag.D == old_diag.D:
return
rect = diag.rectangle
rect_conj = Rectangle(rect.e2.conj, rect.e1.conj)
conjugate(rect, rect_conj)
D = diag.D - diag.rectangle.e1.len + diag.rectangle.e2.len
pathset = diag.pathset.conj() if experimental.filter == experimental.Filter.pathsets else None
rect_conj.add_diagonal(self.d, D, pathset)
diag_conj = rect.conj.diagonals[D, pathset]
conjugate(diag, diag_conj)
return self.add_diagonal(diag)
示例12: __init__
def __init__(self,x, y, id):
self.sprite = Image(source=self.imageLocations[id])
self.sprite.allow_stretch = True
self.sprite.auto_bring_to_front = False
self.id = id
self.bounds = Rectangle(x,y,self.imageSizes[id].x,self.imageSizes[id].y)
self.setSize(self.imageSizes[id].x, self.imageSizes[id].y)
self.setPosition(x,y)
示例13: update
def update(prefSideLeft, isDebug):
logging.debug("update() {} {}".format(isDebug, imgNameIndex))
# Get color image from camera
ret, img = camera.read() # img.shape 640x480 image
# Convert to hsv img
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# Keep only green objects
# higher s = less white, higher v = less black
lowerGreen = np.array([70, 70, 180])
upperGreen = np.array([110, 130,255])
filteredGreen = cv2.inRange(hsv, lowerGreen, upperGreen)
# Filter out small objects
filteredGreen = cv2.morphologyEx(filteredGreen, cv2.MORPH_OPEN, np.ones((3, 3)))
# Find all contours, countours is vector of points that are connected to make up a shape
contours, hierarchy = cv2.findContours(filteredGreen, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# Resetting foundHotTarget
global foundHotTarget
foundHotTarget = False;
# Parse contours, calculate distance and check if it's the hot target
for shape in contours:
target = Rectangle(*cv2.boundingRect(shape))
# Filter out small contours
if target.getArea() > 300 and target.getArea() < 10000:
# If the width of the target is greater than its height then it's probably the hot target
if target.width >= target.height * 2.5:
foundHotTarget = inPrefSide(target.x + (target.width / 2), prefSideLeft)
if isDebug:
drawRect(img, target)
viewAngle = computeAngle(horizTarget.height, target.height, distanceFromTarget)
logging.debug("Hot Target: " + str(foundHotTarget) + ", New Angle: " + str(viewAngle))
# Save img so we can analyze it
if isDebug:
saveImg(img)
示例14: RectangleTest
class RectangleTest(TestCase):
def setUp(self):
self.rectangle = Rectangle(1, 2, 3, 4)
def test_getLength(self):
assert_equal(self.rectangle.getLength(), 2)
def test_getHeight(self):
assert_equal(self.rectangle.getHeight(), 2)
def test_getArea(self):
assert_equal(self.rectangle.getArea(), 4)
def test_move(self):
self.rectangle.move(4, 8)
self.test_getLength()
self.test_getHeight()
self.test_getArea()
示例15: test_rectangle_distance_from_frame
def test_rectangle_distance_from_frame(self):
'''
Test overlap between rectangles and frame.
'''
rect = Rectangle(50, 50, 175, 175)
self.assertAlmostEqual(200 - math.sqrt(2)*25,
rect.get_distance_from_frame(200), 2)
rect.set_position(200, 200)
self.assertAlmostEqual(200 - math.sqrt(2)*50,
rect.get_distance_from_frame(200), 2)
rect.set_position(0, 350)
self.assertAlmostEqual(200 - math.sqrt(2)*200,
rect.get_distance_from_frame(200), 2)