# BBox2C

## Class hierarchy

BBox2C

## Overview

BBox2C class implements two dimensional box used as bounding box. When specifying a bounding box you must be careful to construct it so that it is normalized. In other words, the minimum values and maximum values has to be correct. If the bounding box is not normalized many methods will return incorrect results. If a method needs the box ot be normalized it is mentioned. To normalize non-normalized bounding box use the normalize method.

This class is implemented by the system.

Header: | BBox2C.h
Library: | core.lib

## Class members

`BBox2C( const Vector2C& rMin const Vector2C& rMax );`

#### Parameters

rMin
  Reference to the minimum of the bounding box.
rMax
  Reference to the maximum of the bounding box.

#### Remarks

Initialises the bounds of the box from specified maximum and minimum values.

`BBox2C( const BBox2C& rBBox );`

#### Parameters

rBBox
  Reference to the bounding box to copy.

#### Remarks

The copy constructor. Creates a new bounding box with the same values as the argument.

`float32 width() const;`

#### Return value

Width method returns the width of the bounding box. The returned value is absolute width, that is, even the min and max bounds are in wrong order width will return correct result.

`float32 height() const;`

#### Return value

Height method returns the height of the bounding box. The returned value is absolute height, that is, even the min and max bounds are in wrong order height returns correct height.

`Vector2C center() const;`

#### Return value

The center point of the bounding box. The center is calculated as: (min + max) / 2.

`Vector2C size() const;`

#### Return value

Size returns the size of the bounding box. Size is calculated as: max - min. You must normalize the bounding box to get correct size. You may normalize the box by calling the normalize method.

`bool contains( const Vector2C& rVec ) const;`

#### Parameters

rVec
  Reference to the point to be tested.

#### Return value

True if the point is inside the bounding box, else false.

#### Remarks

Determines wheter the specified point is inside the bounding box. The box has to be normalized or this method may fail. You may normalize the box by calling the normalize method.

`bool contains( const BBox2C& rBBox ) const;`

#### Parameters

rVec
  Reference to the box to be tested.

#### Return value

True if the specified bounding box is inside the bounding box, else false.

#### Remarks

Determines wheter the specified bounding box is inside the bounding box. Both boxes has to be normalized or this method may fail. You may normalize the box by calling the normalize method.

`BBox2C trim( const BBox2C& rBBox ) const;`

#### Parameters

rBBox
  Refernce to the trimming box.

#### Return value

The trimmed bounding box.

#### Remarks

Trims the bounding box by the specified bounding box and returns the trimmed bounding box. After trimming the bounding box will fit inside the trimming box.

`BBox2C normalize() const;`

#### Return value

The normalized bounding box.

#### Remarks

Normalizes the bounding box so that the minimum and maximum values are correct. This method is useful when dealing with bounding boxes which may be inverted.

`BBox2C offset( const Vector2C& rOffset ) const;`

#### Parameters

rOffset
  Reference to the 2D vector specifying the amount to move.

#### Return value

The transformed bounding box.

#### Remarks

Moves the bounding box by specified offset.

`BBox2C combine( const BBox2C& rBBox ) const;`

#### Parameters

rBBox
  reference to the bounding box specifying the second source.

#### Return value

The combined bounding box.

#### Remarks

Makes the dimension of a bounding box equal to the union of the bounding box and the other specified bounding box, and returns the union. The union is the smallest bounding box containing both bounding boxes.

`const Vector2C& get_min() const;`

#### Return value

Reference to the minimum of the bounding box.

#### Remarks

The return is guaranteed to be valid minimum only if the minimum is known to be correct or method normalize has been called.

`const Vector2C& get_max() const;`

#### Return value

Reference to the maximum of the bounding box.

#### Remarks

The return is guaranteed to be valid maximum only if the maximum is known to be correct or method normalize has been called.

`void set_min( const Vector2C& rVec );`

#### Parameters

rVec
  Reference to the point specifying the new minimum of the bounding box.

#### Remarks

Sets the minimum of the bounding box.

`void set_max( const Vector2C& rVec );`

#### Parameters

rVec
  Reference to the point specifying the new minimum of the bounding box.

#### Remarks

Sets the maximum of the bounding box.

`Vector2C& operator[]( int i );`

`const Vector2C& operator[]( int i ) const;`

#### Return value

If the specified index is 0 (zero) minimum is returned, else maximum is returned.

#### Remarks

This operator returns either minimum or maximum of the box. The returns value depends on the given index: 0 for minimum, 1 for maximum. The box has to be normalized or this method may return incorrect values. You may normalize the box by calling the normalize method. There are two versions of this method, the first enables to assign values using this the assignment operator and second is for retrieving the values.

`bool operator==( const BBox2C& rBBox ) const;`

#### Return value

True if both bounding boxes are equal, else false.

#### Remarks

This operator compares if both boxes are equal and returns true if they are equal. Both boxes have to be normalized or this method may fail. You may normalize the box by calling the normalize method.

`bool operator!=( const BBox2C& rBBox ) const;`

#### Return value

True if both bounding boxes are not equal, else false.

#### Remarks

This operator compares two boxes and returns true if they are not equal. Both boxes have to be normalized or this method may fail. You may normalize the box by calling the normalize method.

Copyright © 2000 Moppi Productions