1 '''
 2 input: rect1, rect2, 均为list,其分别为
 3 xl(left),yb(bottom),xr(right),yt(top)
 4 '''
 5 def calc_area(rect1, rect2):
 6     xl1, yb1, xr1, yt1 = rect1
 7     xl2, yb2, xr2, yt2 = rect2
 8     xmin = max(xl1, xl2)
 9     ymin = max(yb1, yb2)
10     xmax = min(xr1, xr2)
11     ymax = min(yt1, yt2)
12     width = xmax - xmin
13     height = ymax - ymin
14     if width <= 0 or height <= 0:
15         return 0
16     cross_square = width * height
17     return cross_square

 

相关文章:

  • 2022-12-23
  • 2021-10-09
  • 2022-01-26
  • 2022-12-23
  • 2021-06-21
  • 2021-04-15
  • 2021-08-04
猜你喜欢
  • 2022-12-23
  • 2021-12-24
  • 2022-03-08
  • 2022-12-23
  • 2021-11-25
  • 2021-12-24
相关资源
相似解决方案