@@ -331,42 +331,38 @@ def flush(self) -> None:
331
331
def get_coordinate_pointers (
332
332
self , coordinates : Sequence [float ]
333
333
) -> tuple [float , float ]:
334
- try :
335
- iter (coordinates )
336
- except TypeError :
337
- raise TypeError ("Bounds must be a sequence" )
338
334
dimension = self .properties .dimension
335
+ coordinates = list (coordinates )
339
336
340
- mins = ctypes .c_double * dimension
341
- maxs = ctypes .c_double * dimension
342
-
343
- if not self .interleaved :
344
- coordinates = Index .interleave (coordinates )
337
+ arr = ctypes .c_double * dimension
338
+ mins = arr ()
345
339
346
- # it's a point make it into a bbox. [x, y] => [x, y, x, y]
340
+ # Point
347
341
if len (coordinates ) == dimension :
348
- coordinates = * coordinates , * coordinates
342
+ mins [:] = coordinates
343
+ maxs = mins
344
+ # Bounding box
345
+ else :
346
+ maxs = arr ()
349
347
350
- if len (coordinates ) != dimension * 2 :
351
- raise RTreeError (
352
- "Coordinates must be in the form "
353
- "(minx, miny, maxx, maxy) or (x, y) for 2D indexes"
354
- )
348
+ # Interleaved box
349
+ if self .interleaved :
350
+ p = coordinates [:dimension ]
351
+ q = coordinates [dimension :]
352
+ # Non-interleaved box
353
+ else :
354
+ p = coordinates [::2 ]
355
+ q = coordinates [1 ::2 ]
355
356
356
- # so here all coords are in the form:
357
- # [xmin, ymin, zmin, xmax, ymax, zmax]
358
- for i in range ( dimension ):
359
- if not coordinates [ i ] <= coordinates [ i + dimension ] :
357
+ mins [:] = p
358
+ maxs [:] = q
359
+
360
+ if not p <= q :
360
361
raise RTreeError (
361
362
"Coordinates must not have minimums more than maximums"
362
363
)
363
364
364
- p_mins = mins (* [ctypes .c_double (coordinates [i ]) for i in range (dimension )])
365
- p_maxs = maxs (
366
- * [ctypes .c_double (coordinates [i + dimension ]) for i in range (dimension )]
367
- )
368
-
369
- return (p_mins , p_maxs )
365
+ return mins , maxs
370
366
371
367
@staticmethod
372
368
def _get_time_doubles (times ):
@@ -1231,16 +1227,14 @@ def py_next_item(p_id, p_mins, p_maxs, p_dimension, p_data, p_length):
1231
1227
return - 1
1232
1228
1233
1229
if self .interleaved :
1234
- coordinates = Index .deinterleave (coordinates )
1235
-
1236
- # this code assumes the coords are not interleaved.
1237
- # xmin, xmax, ymin, ymax, zmin, zmax
1238
- for i in range (dimension ):
1239
- mins [i ] = coordinates [i * 2 ]
1240
- maxs [i ] = coordinates [(i * 2 ) + 1 ]
1230
+ mins [:] = coordinates [:dimension ]
1231
+ maxs [:] = coordinates [dimension :]
1232
+ else :
1233
+ mins [:] = coordinates [::2 ]
1234
+ maxs [:] = coordinates [1 ::2 ]
1241
1235
1242
- p_mins [0 ] = ctypes . cast ( mins , ctypes . POINTER ( ctypes . c_double ))
1243
- p_maxs [0 ] = ctypes . cast ( maxs , ctypes . POINTER ( ctypes . c_double ))
1236
+ p_mins [0 ] = mins
1237
+ p_maxs [0 ] = maxs
1244
1238
1245
1239
# set the dimension
1246
1240
p_dimension [0 ] = dimension
@@ -1510,9 +1504,15 @@ def __str__(self) -> str:
1510
1504
return pprint .pformat (self .as_dict ())
1511
1505
1512
1506
def get_index_type (self ) -> int :
1513
- return core .rt .IndexProperty_GetIndexType (self .handle )
1507
+ try :
1508
+ return self ._type
1509
+ except AttributeError :
1510
+ type = core .rt .IndexProperty_GetIndexType (self .handle )
1511
+ self ._type : int = type
1512
+ return type
1514
1513
1515
1514
def set_index_type (self , value : int ) -> None :
1515
+ self ._type = value
1516
1516
return core .rt .IndexProperty_SetIndexType (self .handle , value )
1517
1517
1518
1518
type = property (get_index_type , set_index_type )
@@ -1531,11 +1531,17 @@ def set_variant(self, value: int) -> None:
1531
1531
:data:`RT_Linear`, :data:`RT_Quadratic`, and :data:`RT_Star`"""
1532
1532
1533
1533
def get_dimension (self ) -> int :
1534
- return core .rt .IndexProperty_GetDimension (self .handle )
1534
+ try :
1535
+ return self ._dimension
1536
+ except AttributeError :
1537
+ dim = core .rt .IndexProperty_GetDimension (self .handle )
1538
+ self ._dimension : int = dim
1539
+ return dim
1535
1540
1536
1541
def set_dimension (self , value : int ) -> None :
1537
1542
if value <= 0 :
1538
1543
raise RTreeError ("Negative or 0 dimensional indexes are not allowed" )
1544
+ self ._dimension = value
1539
1545
return core .rt .IndexProperty_SetDimension (self .handle , value )
1540
1546
1541
1547
dimension = property (get_dimension , set_dimension )
0 commit comments