Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 4th, 2020 145 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Geometry
  2.  
  3.  
  4. class Solution:
  5.     def checkOverlap(
  6.         self,
  7.         radius: int,
  8.         x_center: int,
  9.         y_center: int,
  10.         x1: int,
  11.         y1: int,
  12.         x2: int,
  13.         y2: int,
  14.     ) -> bool:
  15.         if x1 <= x_center <= x2 and y1 <= y_center <= y2:
  16.             return True
  17.  
  18.         def notOverlaps(start1, end1, start2, end2):
  19.             return end1 < start2 or end2 < start1
  20.  
  21.         def overlaps(start1, end1, start2, end2):
  22.             return not notOverlaps(start1, end1, start2, end2)
  23.  
  24.         def shift(interval, delta):
  25.             if interval is None:
  26.                 return None
  27.             (start, end) = interval
  28.             return (start + delta, end + delta)
  29.  
  30.         def circleLine(r, d):
  31.             if d < 0 or r < d:
  32.                 return None
  33.             w = (r ** 2 - d ** 2) ** 0.5
  34.             return [-w, w]
  35.  
  36.         segments = [
  37.             (x1, x2),
  38.             (x1, x2),
  39.             (y1, y2),
  40.             (y1, y2),
  41.         ]
  42.         circleSegments = [
  43.             shift(circleLine(radius, y1 - y_center), x_center),
  44.             shift(circleLine(radius, y_center - y2), x_center),
  45.             shift(circleLine(radius, x1 - x_center), y_center),
  46.             shift(circleLine(radius, x_center - x2), y_center),
  47.         ]
  48.         for int1, int2 in zip(segments, circleSegments):
  49.             if int2 is None:
  50.                 continue
  51.             (start1, end1) = int1
  52.             (start2, end2) = int2
  53.             if overlaps(start1, end1, start2, end2):
  54.                 return True
  55.         return False
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top