gnome.utilities.geometry.BBox

A Bounding Box object and assorted utilities , subclassed from a numpy array

FIXME: The constructor functions should be class methods.

It would be good to PEP8 the method names.

Module Contents

Classes

BBox

A Bounding Box object:

Functions

asBBox(data)

returns a BBox object.

fromPoints(Points)

fromPoints (Points).

fromBBArray(BBarray)

Builds a BBox object from an array of Bounding Boxes.

NullBBox()

Returns a BBox object with all NaN entries.

InfBBox()

Returns a BBox object with all -inf and inf entries

class gnome.utilities.geometry.BBox.BBox(shape, dtype=float, buffer=None, offset=0, strides=None, order=None)

Bases: numpy.ndarray

A Bounding Box object:

Takes Data as an array. Data is any python sequence that can be turned into a 2x2 numpy array of float64s:

[[MinX, MinY ],

[MaxX, MaxY ]]

It is a subclass of numpy.ndarray, so for the most part it can be used as an array, and arrays that fit the above description can be used in its place.

Usually created by the factory functions:

asBBox

and

fromPoints

Takes Data as an array. Data is any python sequence that can be turned into a 2x2 numpy array of float64s:

[[MinX, MinY ], [MaxX, MaxY ]]

You don’t usually call this directly. BBox objects are created with the factory functions:

asBBox

and

fromPoints

Left
Right
Bottom
Top
Width
Height
Center
Array__eq__
Overlaps(BB)

Overlap(BB):

Tests if the given Bounding Box overlaps with this one. Returns True is the Bounding boxes overlap, False otherwise If they are just touching, returns True

Inside(BB)

Inside(BB):

Tests if the given Bounding Box is entirely inside this one.

Returns True if it is entirely inside, or touching the border.

Returns False otherwise

PointInside(Point)

Inside(BB):

Tests if the given Point is entirely inside this one.

Returns True if it is entirely inside, or touching the border.

Returns False otherwise

Point is any length-2 sequence (tuple, list, array) or two numbers

Merge(BB)

Joins this bounding box with the one passed in, maybe making this one bigger

AsPoly()

Returns the four corners of the bounding box as polygon:

An 4X2 array of (x,y) coordinates of the corners

IsNull()
_getLeft()
_getRight()
_getBottom()
_getTop()
_getWidth()
_getHeight()
_getCenter()
__eq__(BB)

__eq__(BB) The equality operator

A == B if and only if all the entries are the same

gnome.utilities.geometry.BBox.asBBox(data)

returns a BBox object.

If object is a BBox, it is returned unaltered

If object is a numpy array, a BBox object is returned that shares a view of the data with that array. The numpy array should be of the correct format: a 2x2 numpy array of float64s:

[[MinX, MinY ],

[MaxX, MaxY ]]

gnome.utilities.geometry.BBox.fromPoints(Points)

fromPoints (Points).

reruns the bounding box of the set of points in Points. Points can be any python object that can be turned into a numpy NX2 array of float64s.

If a single point is passed in, a zero-size Bounding Box is returned.

gnome.utilities.geometry.BBox.fromBBArray(BBarray)

Builds a BBox object from an array of Bounding Boxes. The resulting Bounding Box encompases all the included BBs.

The BBarray is in the shape: (Nx2x2) where BBarray[n] is a 2x2 array that represents a BBox

gnome.utilities.geometry.BBox.NullBBox()

Returns a BBox object with all NaN entries.

This represents a Null BB box;

BB merged with it will return BB.

Nothing is inside it.

gnome.utilities.geometry.BBox.InfBBox()

Returns a BBox object with all -inf and inf entries