BPolygon

Constructor and Destructor

BPolygon()

BPolygon::BPolygon(const BPoint *pointList, int32 numPoints)
BPolygon::BPolygon(const BPolygon *polygon)
BPolygon::BPolygon()

Initializes the BPolygon by copying numPoints from pointList, or by copying the list of points from another polygon. If one polygon is constructed from another, the original and the copy won’t share any data; independent memory is allocated for the copy to hold a duplicate list of points.

If a BPolygon is constructed without a point list, points must be set with the AddPoints() function.

~BPolygon()

virtual BPolygon::~BPolygon()

Frees all the memory allocated to hold the list of points.

Member Functions

AddPoints()

void BPolygon::AddPoints(const BPoint *pointList, int32 numPoints)

Appends numPoints from pointList to the list of points that already define the polygon.

CountPoints()

int32 BPolygon::CountPoints() const

Returns the number of points that define the polygon.

Frame()

BRect BPolygon::Frame() const

Returns the polygon’s frame rectangle—the smallest rectangle that encloses the entire polygon.

MapTo()

void BPolygon::MapTo(BRect source, BRect destination)

Modifies the polygon so that it fits the destination rectangle exactly as it originally fit the source rectangle. Each vertex of the polygon is modified so that it has the same proportional position relative to the sides of the destination rectangle as it originally had to the sides of the source rectangle.

The polygon doesn’t have to be contained in either rectangle. However, to modify a polygon so that it’s exactly inscribed in the destination rectangle, you should pass its frame rectangle as the source:

BRect frame = myPolygon->Frame();
myPolygon->MapTo(frame, anotherRect);

PrintToStream()

void BPolygon::PrintToStream() const

Prints the BPolygon’s point list to the standard output stream (stdout). The BPoint version of this function is called to report each point as a string in the form

"BPoint(x, y)"

where x and y stand for the coordinate values of the point in question.

See also: BPoint::PrintToStream()

Operators

BPolygon &operator=(const BPolygon&)

Copies the point list of one BPolygon object and assigns it to another BPolygon. After the assignment, the two objects describe the same polygon, but are independent of each other. Destroying one of the objects won’t affect the other.