coords.Coords.test#

Coords.test(dir=0, min=None, max=None, atol=0.0)#

Flag points having coordinates between min and max.

Test the position of the points of the Coords with respect to one or two parallel planes. This method is very convenient in clipping a Coords in a specified direction. In most cases the clipping direction is one of the global coordinate axes, but a general direction may be used as well.

Testing along global axis directions is highly efficient. It tests whether the corresponding coordinate is above or equal to the min value and/or below or equal to the max value. Testing in a general direction tests whether the distance to the min plane is positive or zero and/or the distance to the max plane is negative or zero.

Parameters#

dir: a single int or a float array_like (3,)

The direction in which to measure distances. If an int, it is one of the global axes (0,1,2). Else it is a vector with 3 components. The default direction is the global x-axis.

min: float or point-like, optional

Position of the minimal clipping plane. If dir is an int, this is a single float giving the coordinate along the specified global axis. If dir is a vector, this must be a point and the minimal clipping plane is defined by this point and the normal vector dir. If not provided, there is no clipping at the minimal side.

max: float or point-like.

Position of the maximal clipping plane. If dir is an int, this is a single float giving the coordinate along the specified global axis. If dir is a vector, this must be a point and the maximal clipping plane is defined by this point and the normal vector dir. If not provided, there is no clipping at the maximal side.

atol: float

Tolerance value added to the tests to account for accuracy and rounding errors. A test will return True if the point’s distance from the min clipping plane is >= -atol and/or the distance from the max clipping plane is <= atol. Thus a positive atol widens the clipping planes.

Returns#

bool array with shape points_shape()

Array flagging whether the points for the Coords pass the test(s) or not. The return value can directly be used as an index to self to obtain a Coords with the points satisfying the test (or not).

Raises#

ValueError: At least one of min or max have to be specified

If neither min nor max are provided.

Examples#

>>> x = Coords([[[0.0, 0.0],[1.0, 0.0]],[[0.0, 1.0],[0.0, 2.0]]])
>>> print(x.test(min=0.5))
[[False  True]
 [False False]]
>>> t = x.test(dir=1,min=0.5,max=1.5)
>>> print(x[t])
[[0. 1. 0.]]
>>> print(x[~t])
[[0. 0. 0.]
 [1. 0. 0.]
 [0. 2. 0.]]