@@ -31,11 +31,19 @@ def is_left(x_line_0, y_line_0, x_line_1, y_line_1, x_test, y_test):
31
31
"""
32
32
http://geomalgorithms.com/a03-_inclusion.html
33
33
isLeft(): tests if a point is Left|On|Right of an infinite line.
34
- Input: three points P0, P1, and P2
35
- Return: >0 for P2 left of the line through P0 and P1
36
- =0 for P2 on the line
37
- <0 for P2 right of the line
38
34
See: Algorithm 1 "Area of Triangles and Polygons"
35
+
36
+ :param float x_line_0:
37
+ :param float y_line_0:
38
+ :param float x_line_1:
39
+ :param float y_line_1:
40
+ :param float x_test:
41
+ :param float y_test:
42
+ :return: > 0 for P2 left of the line through P0 and P1
43
+ = 0 for P2 on the line
44
+ < 0 for P2 right of the line
45
+ :rtype: bool
46
+
39
47
"""
40
48
# Vector product
41
49
product = (x_line_1 - x_line_0 ) * (y_test - y_line_0 ) - (x_test - x_line_0 ) * (
@@ -46,6 +54,12 @@ def is_left(x_line_0, y_line_0, x_line_1, y_line_1, x_test, y_test):
46
54
47
55
@njit (cache = True )
48
56
def poly_contain_poly (xy_poly_out , xy_poly_in ):
57
+ """
58
+ :param vertice xy_poly_out:
59
+ :param vertice xy_poly_in:
60
+ :return: True if poly_in is in poly_out
61
+ :rtype: bool
62
+ """
49
63
nb_elt = xy_poly_in .shape [0 ]
50
64
x = xy_poly_in [:, 0 ]
51
65
x_ref = xy_poly_out [0 , 0 ]
@@ -61,7 +75,12 @@ def poly_contain_poly(xy_poly_out, xy_poly_in):
61
75
62
76
@njit (cache = True )
63
77
def poly_area (vertice ):
64
- p_area = 0
78
+ """
79
+ :param vertice vertice: polygon vertice
80
+ :return: area of polygon in coordinates unit
81
+ :rtype: float
82
+ """
83
+ p_area = vertice [0 , 0 ] * (vertice [1 , 1 ] - vertice [1 , - 2 ])
65
84
nb_elt = vertice .shape [0 ]
66
85
for i_elt in range (1 , nb_elt - 1 ):
67
86
p_area += vertice [i_elt , 0 ] * (vertice [1 + i_elt , 1 ] - vertice [i_elt - 1 , 1 ])
@@ -70,6 +89,15 @@ def poly_area(vertice):
70
89
71
90
@njit (cache = True )
72
91
def winding_number_poly (x , y , xy_poly ):
92
+ """
93
+ Check if x,y is in poly
94
+
95
+ :param float x: x to test
96
+ :param float y: y to test
97
+ :param vertice xy_poly: vertice of polygon
98
+ :return: wn == 0 if x,y is not in poly
99
+ :retype: int
100
+ """
73
101
nb_elt = xy_poly .shape [0 ]
74
102
wn = 0
75
103
# loop through all edges of the polygon
@@ -97,12 +125,17 @@ def winding_number_poly(x, y, xy_poly):
97
125
def winding_number_grid_in_poly (x_1d , y_1d , i_x0 , i_x1 , x_size , i_y0 , xy_poly ):
98
126
"""
99
127
http://geomalgorithms.com/a03-_inclusion.html
100
- wn_PnPoly(): winding number test for a point in a polygon
101
- Input: P = a point,
102
- V[] = vertex points of a polygon V[n+1] with V[n]=V[0]
103
- Return: wn = the winding number (=0 only when P is outside)
128
+
129
+ :param array x_1d: x of local grid
130
+ :param array y_1d: y of local grid
131
+ :param int i_x0: int to add at x index to have index in global grid
132
+ :param int i_x1: last index in global grid
133
+ :param int x_size: number of x in global grid
134
+ :param int i_y0: int to add at y index to have index in global grid
135
+ :param vertice xy_poly: vertices of polygon which must contain pixel
136
+ :return: Return index in xy_poly
137
+ :rtype: (int,int)
104
138
"""
105
- # the winding number counter
106
139
nb_x , nb_y = len (x_1d ), len (y_1d )
107
140
wn = empty ((nb_x , nb_y ), dtype = numba_types .bool_ )
108
141
for i in prange (nb_x ):
@@ -120,7 +153,15 @@ def winding_number_grid_in_poly(x_1d, y_1d, i_x0, i_x1, x_size, i_y0, xy_poly):
120
153
121
154
@njit (cache = True , fastmath = True )
122
155
def bbox_intersection (x0 , y0 , x1 , y1 ):
123
- """compute bbox to check if there are a bbox intersection
156
+ """
157
+ Compute bbox to check if there are a bbox intersection
158
+
159
+ :param array x0: x for polygon list 0
160
+ :param array y0: y for polygon list 0
161
+ :param array x1: x for polygon list 1
162
+ :param array y1: y for polygon list 1
163
+ :return: index of each polygon bbox which have an intersection
164
+ :rtype: (int, int)
124
165
"""
125
166
nb0 = x0 .shape [0 ]
126
167
nb1 = x1 .shape [0 ]
@@ -152,6 +193,12 @@ def bbox_intersection(x0, y0, x1, y1):
152
193
153
194
@njit (cache = True )
154
195
def create_vertice (x , y ):
196
+ """
197
+ :param array x:
198
+ :param array y:
199
+ :return: Return the vertice of polygon
200
+ :rtype: vertice
201
+ """
155
202
nb = x .shape [0 ]
156
203
v = empty ((nb , 2 ), dtype = x .dtype )
157
204
for i in range (nb ):
@@ -162,6 +209,15 @@ def create_vertice(x, y):
162
209
163
210
@njit (cache = True )
164
211
def create_vertice_from_2darray (x , y , index ):
212
+ """
213
+ Choose a polygon in x,y list and return vertice
214
+
215
+ :param array x:
216
+ :param array y:
217
+ :param int index:
218
+ :return: Return the vertice of polygon
219
+ :rtype: vertice
220
+ """
165
221
_ , nb = x .shape
166
222
v = empty ((nb , 2 ), dtype = x .dtype )
167
223
for i in range (nb ):
@@ -172,6 +228,17 @@ def create_vertice_from_2darray(x, y, index):
172
228
173
229
@njit (cache = True )
174
230
def get_wrap_vertice (x0 , y0 , x1 , y1 , i ):
231
+ """
232
+ Return a vertice for each polygon and check that use same reference coordinates
233
+
234
+ :param array x0: x for polygon list 0
235
+ :param array y0: y for polygon list 0
236
+ :param array x1: x for polygon list 1
237
+ :param array y1: y for polygon list 1
238
+ :param int i: index to use fot the 2 list
239
+ :return: return two compatible vertice
240
+ :rtype: (vertice, vertice)
241
+ """
175
242
x0_ , x1_ = x0 [i ], x1 [i ]
176
243
if abs (x0_ [0 ] - x1_ [0 ]) > 180 :
177
244
ref = x0_ [0 ] - x0 .dtype .type (180 )
@@ -180,6 +247,15 @@ def get_wrap_vertice(x0, y0, x1, y1, i):
180
247
181
248
182
249
def vertice_overlap (x0 , y0 , x1 , y1 , minimal_area = False ):
250
+ """
251
+ :param array x0: x for polygon list 0
252
+ :param array y0: y for polygon list 0
253
+ :param array x1: x for polygon list 1
254
+ :param array y1: y for polygon list 1
255
+ :param bool minimal_area: If True, function will compute intersection/little polygon, else intersection/union
256
+ :return: Result of cost function
257
+ :rtype: array
258
+ """
183
259
nb = x0 .shape [0 ]
184
260
cost = empty (nb )
185
261
for i in range (nb ):
@@ -199,6 +275,13 @@ def vertice_overlap(x0, y0, x1, y1, minimal_area=False):
199
275
200
276
201
277
def polygon_overlap (p0 , p1 , minimal_area = False ):
278
+ """
279
+ :param list(Polygon) p0: List of polygon to compare with p1 list
280
+ :param list(Polygon) p1: List of polygon to compare with p0 list
281
+ :param bool minimal_area: If True, function will compute intersection/little polygon, else intersection/union
282
+ :return: Result of cost function
283
+ :rtype: array
284
+ """
202
285
nb = len (p1 )
203
286
cost = empty (nb )
204
287
for i in range (nb ):
0 commit comments