forked from OmkarPathak/pygorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrect_broad_phase.py
More file actions
61 lines (46 loc) · 1.25 KB
/
rect_broad_phase.py
File metadata and controls
61 lines (46 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Author: ALEXEY SARAPULOV
Created On: 23 August 2017
"""
# To test if two rectangle intersect, we only have to find out
# if their projections intersect on all of the coordinate axes
import inspect
class Coord:
"""Coord
Class to initialize Coordinate of one point
"""
def __init__(self, x, y):
self.x = x
self.y = y
class SimpleRectangle:
"""SimpleRectangle
Class to initialize Body of Object
"""
def __init__(self, coord1, coord2):
"""
:type coord1: object of class Coord
:type coord2: object of class Coord
"""
self.min_x = coord1.x
self.min_y = coord1.y
self.max_x = coord2.x
self.max_y = coord2.y
def broad_phase(simpleRect1, simpleRect2):
"""
:type simpleRect1: object
:type simpleRect2: object
"""
d1x = simpleRect2.min_x - simpleRect1.max_x
d1y = simpleRect2.min_y - simpleRect1.max_y
d2x = simpleRect1.min_x - simpleRect2.max_x
d2y = simpleRect1.min_y - simpleRect2.max_y
if d1x > 0 or d1y > 0:
return False
if d2x > 0 or d2y > 0:
return False
return True
def get_code():
"""
returns the code for the broad phase function
"""
return inspect.getsource(broad_phase)