Skip to content

Commit d5b6157

Browse files
committed
add docstring for polygon
1 parent 230d6d1 commit d5b6157

File tree

2 files changed

+95
-11
lines changed

2 files changed

+95
-11
lines changed

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Welcome to py-eddy-tracker's documentation!
4343
autodoc/eddy_feature
4444
autodoc/featured_tracking
4545
autodoc/poly
46+
autodoc/generic
4647

4748

4849
Indices and tables

src/py_eddy_tracker/poly.py

Lines changed: 94 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,19 @@ def is_left(x_line_0, y_line_0, x_line_1, y_line_1, x_test, y_test):
3131
"""
3232
http://geomalgorithms.com/a03-_inclusion.html
3333
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
3834
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+
3947
"""
4048
# Vector product
4149
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):
4654

4755
@njit(cache=True)
4856
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+
"""
4963
nb_elt = xy_poly_in.shape[0]
5064
x = xy_poly_in[:, 0]
5165
x_ref = xy_poly_out[0, 0]
@@ -61,7 +75,12 @@ def poly_contain_poly(xy_poly_out, xy_poly_in):
6175

6276
@njit(cache=True)
6377
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])
6584
nb_elt = vertice.shape[0]
6685
for i_elt in range(1, nb_elt - 1):
6786
p_area += vertice[i_elt, 0] * (vertice[1 + i_elt, 1] - vertice[i_elt - 1, 1])
@@ -70,6 +89,15 @@ def poly_area(vertice):
7089

7190
@njit(cache=True)
7291
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+
"""
73101
nb_elt = xy_poly.shape[0]
74102
wn = 0
75103
# loop through all edges of the polygon
@@ -97,12 +125,17 @@ def winding_number_poly(x, y, xy_poly):
97125
def winding_number_grid_in_poly(x_1d, y_1d, i_x0, i_x1, x_size, i_y0, xy_poly):
98126
"""
99127
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)
104138
"""
105-
# the winding number counter
106139
nb_x, nb_y = len(x_1d), len(y_1d)
107140
wn = empty((nb_x, nb_y), dtype=numba_types.bool_)
108141
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):
120153

121154
@njit(cache=True, fastmath=True)
122155
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)
124165
"""
125166
nb0 = x0.shape[0]
126167
nb1 = x1.shape[0]
@@ -152,6 +193,12 @@ def bbox_intersection(x0, y0, x1, y1):
152193

153194
@njit(cache=True)
154195
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+
"""
155202
nb = x.shape[0]
156203
v = empty((nb, 2), dtype=x.dtype)
157204
for i in range(nb):
@@ -162,6 +209,15 @@ def create_vertice(x, y):
162209

163210
@njit(cache=True)
164211
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+
"""
165221
_, nb = x.shape
166222
v = empty((nb, 2), dtype=x.dtype)
167223
for i in range(nb):
@@ -172,6 +228,17 @@ def create_vertice_from_2darray(x, y, index):
172228

173229
@njit(cache=True)
174230
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+
"""
175242
x0_, x1_ = x0[i], x1[i]
176243
if abs(x0_[0] - x1_[0]) > 180:
177244
ref = x0_[0] - x0.dtype.type(180)
@@ -180,6 +247,15 @@ def get_wrap_vertice(x0, y0, x1, y1, i):
180247

181248

182249
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+
"""
183259
nb = x0.shape[0]
184260
cost = empty(nb)
185261
for i in range(nb):
@@ -199,6 +275,13 @@ def vertice_overlap(x0, y0, x1, y1, minimal_area=False):
199275

200276

201277
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+
"""
202285
nb = len(p1)
203286
cost = empty(nb)
204287
for i in range(nb):

0 commit comments

Comments
 (0)