A bounding rectangle can describe the size and location of a node in a network, or the visible area or a network editor pane.

## Methods ¶

```
__init__(x1, y1, x2, y2)
```

Construct a new bounding rectangle with the specified bounds expressed as floating point numbers.

```
__init__(p1, p2)
```

Construct a new bounding rectangle with the specified bounds expressed as two hou.Vector2s.

```
setTo(bounds_sequence)
```

Given a sequence of (xmin, ymin, xmax, ymax) values, set the position of the bounding rectangle.

Raises hou.InvalidSize if the tuple does not contain four elements.

```
isValid()
```

→ ```
bool
```

Returns whether this bounding rectangle is valid, indicating it has been initialized in any way.

>>> hou.BoundingRect().isValid() False >>> hou.BoundingRect(0, 0, 0, 0).isValid() True >>> hou.BoundingRect(0, 0, 0, 0).isValid() True

```
isAlmostEqual(rect, tolerance=0.00001)
```

→ ```
bool
```

Returns whether this bounding rectangle is equal to another, subject to numerical tolerances.

>>> unitrect = hou.BoundingRect(0, 0, 1, 1) >>> subrect = hou.BoundingRect(0.001, 0.001, 0.999, 1.001) >>> unitrect.isAlmostEqual(subrect) False >>> unitrect.isAlmostEqual(subrect, 0.01) True

```
min()
```

→ hou.Vector2

Return a vector describing the corner of the rectangle with the smallest
`x`

and `y`

values.

```
max()
```

→ hou.Vector2

Return a vector describing the corner of the rectangle with the largest
`x`

and `y`

values.

```
size()
```

→ hou.Vector2

Return a vector describing the size of the rectangle in each of the
`x`

and `y`

axes.

This method can be implemented as follows:

def size(self): return self.max() - self.min()

```
center()
```

→ hou.Vector2

Return the position of the center of the bounding rectangle.

This method can be implemented as follows:

def center(self): return (self.min() + self.max()) * 0.5

```
contains(point)
```

→ bool

Given a sequence of 2 floats (such as a hou.Vector2) describing a position, return whether the position is inside the rectangle.

>>> unitrect = hou.BoundingRect(0, 0, 1, 1) >>> unitrect.contains((0.5, 0.5)) True >>> unitrect.contains((1, 1)) True >>> unitrect.contains((0, 0)) True >>> unitrect.contains((1.01, 0.5)) False

```
contains(rect)
```

→ bool

Given a hou.BoundingRect object, return whether that rectangle is inside the one described by this object.

>>> unitrect = hou.BoundingRect(0, 0, 1, 1) >>> unitrect.contains(hou.BoundingRect(0.5, 0.5, 1.0, 1.0)) True >>> unitrect.contains(hou.BoundingRect(0.5, 0.5, 1.5, 1.5)) False

```
intersects(point0, point1)
```

→ bool

Given a line defined by two end points (each of which is specified as a sequence of two floats), return True if the line intersects this rectangle.

>>> unitrect = hou.BoundingRect(0, 0, 1, 1) >>> unitrect.intersects((0.5, 1.5), (0.5, -0.5)) True >>> unitrect.intersects((0.5, 1.5), (-0.5, 1.5)) False

```
intersects(point0, point1, point2)
```

→ bool

Given a triangle defined by three points (each of which is specified as a sequence of two floats), return True if the triangle partially or fully overlaps this rectangle.

>>> unitrect = hou.BoundingRect(0, 0, 1, 1) >>> unitrect.intersects((-1.0, -1.0), (4.0, -1.0), (-1.0, 4.0)) True >>> unitrect.intersects((0.5, 2.0), (2.0, 0.5), (2.0, 2.0)) False

```
intersects(rect)
```

→ bool

Given a hou.BoundingRect object, return whether that rectangle partially or fully overlaps the one described by this object.

>>> unitrect = hou.BoundingRect(0, 0, 1, 1) >>> unitrect.intersects(hou.BoundingRect(0.5, 0.5, 1.0, 1.0)) True >>> unitrect.intersects(hou.BoundingRect(0.5, 0.5, 1.5, 1.5)) True >>> unitrect.intersects(hou.BoundingRect(1.5, 1.5, 2.5, 2.5)) False

```
closestPoint(point)
```

→ hou.Vector2

Given a sequence of 2 floats (such as a hou.Vector2) describing a position, return the position inside the rectangle that is closest to the provided point.

>>> unitrect = hou.BoundingRect(0, 0, 1, 1) >>> unitrect.closestPoint((0.5, 0.5)) <hou.Vector2 [0.5, 0.5]> >>> unitrect.closestPoint((100, 0.5)) <hou.Vector2 [1.0, 0.5]> >>> unitrect.closestPoint((-10, -5)) <hou.Vector2 [0, 0]>

```
getOffsetToAvoid(bounds, direction = None)
```

→ hou.Vector2

Return a vector describing the minimum distance this rectangle must be
translated to avoid any overlap with the `bounds`

rectangle. If
`direction`

is provided as a hou.Vector2, it indicates the specific
direction the returned offset should be. If the rectangles do not overlap,
the result will be `hou.Vector2(0.0, 0.0)`

.

>>> unitrect = hou.BoundingRect(0, 0, 1, 1) >>> subrect = hou.BoundingRect(0.2, 0.4, 0.8, 0.6) >>> unitrect.getOffsetToAvoid(subrect) <hou.Vector2 [0, 0.6]> >>> unitrect.getOffsetToAvoid(subrect, hou.Vector2(1.0, 0.0)) <hou.Vector2 [0.8, 0]> >>> unitrect.getOffsetToAvoid(subrect, hou.Vector2(1.0, 1.0)) <hou.Vector2 [0.6, 0.6]>

```
translate(offset)
```

Moves this rectangle by the amount specified in the two float tuple or hou.Vector2 passed as the offset parameter.

>>> rect = hou.BoundingRect(1, 1, 2, 2) >>> rect.translate(hou.Vector2(1, -1)) >>> rect <hou.BoundingRect [2, 0, 3, 1]>

```
scale(scale)
```

Scales this rectangle by the amount specified in the two float tuple or hou.Vector2 passed as the scale parameter. Note that scaling the rectangle by a negative value will result in an invlalid rectangle where the lower left corner is above or to the right of the upper right corner.

>>> rect = hou.BoundingRect(1, 1, 2, 2) >>> rect.scale(hou.Vector2(2, 3)) >>> rect <hou.BoundingRect [2, 3, 4, 6]> >>> rect.scale((-1, -1)) >>> rect <hou.BoundingRect [-2, -3, -4, -6]> >>> rect.isValid() False

```
expand(offset)
```

Moves the edges of the rectangle away from its center by the distances specified in the two float tuple or hou.Vector2 passed as the offset parameter. The offset is applied to both sides of the rectangle so actually changes the width and height of the rectangle by twice the passed in values.

Negative values can be passed into the offset to shrink the rectangle, but shrinking the rectangle by more than its current size will result in an invliad rectangle.

>>> rect = hou.BoundingRect(1, 1, 2, 2) >>> rect.expand((1, 1)) >>> rect <hou.BoundingRect [0, 0, 3, 3]> >>> rect.expand((0, -2)) >>> rect <hou.BoundingRect [0, 2, 3, 1]> >>> rect.isValid() False

```
enlargeToContain(point_or_rect)
```

Enlarge the bounding rectangle to contain the given element. The element may be a sequence of 2 floats (such as a hou.Vector2) describing a position or another bounding rectangle. If this rectangle does not need to grow because it already completely contains the element, it won’t be modified.

>>> unitrect = hou.BoundingRect(0, 0, 1, 1) >>> unitrect.enlargeToContain((2, 0.5)) >>> unitrect <hou.BoundingRect [0, 0, 2, 1]> >>> unitrect = hou.BoundingRect(0, 0, 1, 1) >>> unitrect.enlargeToContain(hou.BoundingRect(0.5, 0.5, 2, 1.5)) >>> unitrect <hou.BoundingRect [0, 0, 2, 1.5]>

```
intersect(rect)
```

Given a hou.BoundingRect object, updates the rectangle in this object to be the region where the two rectangles overlap.

>>> rect = hou.BoundingRect(0, 0, 1, 1) >>> rect.intersect(hou.BoundingRect(0.5, 0.5, 1.5, 1.5)) >>> rect <hou.BoundingRect [0.5, 0.5, 1, 1]>