@@ -363,7 +363,7 @@ def add_fields(self, fields=list(), array_fields=list()):
363363
364364 def add_rotation_type (self ):
365365 new = self .add_fields (("type_cyc" ,))
366- new .type_cyc = self .sign_type
366+ new .type_cyc [:] = self .sign_type
367367 return new
368368
369369 def circle_contour (self , only_virtual = False ):
@@ -1905,6 +1905,19 @@ def is_convex(self, intern=False):
19051905 xname , yname = self .intern (intern )
19061906 return convexs (self [xname ], self [yname ])
19071907
1908+ def contains (self , x , y , intern = False ):
1909+ """
1910+ Return index of contour which contain (x,y)
1911+
1912+ :param array x: longitude
1913+ :param array y: latitude
1914+ :param bool intern: If true use speed contour instead of effective contour
1915+ :return: indexs, -1 if no index
1916+ :rtype: array[int32]
1917+ """
1918+ xname , yname = self .intern (intern )
1919+ return poly_indexs (x , y , self [xname ], self [yname ])
1920+
19081921 def inside (self , x , y , intern = False ):
19091922 """
19101923 True for each point inside the effective contour of an eddy
@@ -2181,6 +2194,33 @@ def grid_count_pixel_in(
21812194 grid_count_ (grid , i , j )
21822195
21832196
2197+ @njit (cache = True )
2198+ def poly_indexs (x_p , y_p , x_c , y_c ):
2199+ """
2200+ index of contour for each postion inside a contour, -1 in case of no contour
2201+
2202+ :param array x_p: longitude to test
2203+ :param array y_p: latitude to test
2204+ :param array x_c: longitude of contours
2205+ :param array y_c: latitude of contours
2206+ """
2207+ nb_p = x_p .shape [0 ]
2208+ nb_c = x_c .shape [0 ]
2209+ indexs = - ones (nb_p , dtype = numba_types .int32 )
2210+ for i in range (nb_c ):
2211+ x_c_min , y_c_min = x_c [i ].min (), y_c [i ].min ()
2212+ x_c_max , y_c_max = x_c [i ].max (), y_c [i ].max ()
2213+ v = create_vertice (x_c [i ], y_c [i ])
2214+ for j in range (nb_p ):
2215+ if indexs [j ] != - 1 :
2216+ continue
2217+ x , y = x_p [j ], y_p [j ]
2218+ if x > x_c_min and x < x_c_max and y > y_c_min and y < y_c_max :
2219+ if winding_number_poly (x , y , v ) != 0 :
2220+ indexs [j ] = i
2221+ return indexs
2222+
2223+
21842224@njit (cache = True )
21852225def insidepoly (x_p , y_p , x_c , y_c ):
21862226 """
0 commit comments