# The Interface Kit: BPolygon

Derived from: none

Declared in: be/interface/Polygon.h

Library: libbe.so

## Overview

A BPolygon object represents a polygon--a closed, many-sided figure that describes an area within a two-dimensional coordinate system. It differs from a BRect object in that it can have any number of sides and the sides don't have to be aligned with the coordinate axes.

A BPolygon is defined as a series of connected points. Each point is a potential vertex in the polygon. An outline of the polygon could be constructed by tracing a straight line from the first point to the second, from the second point to the third, and so on through the whole series, then by connecting the first and last points if they're not identical.

The BView functions that draw a polygon--`StrokePolygon()` and `FillPolygon()`--take BPolygon objects as arguments. `StrokePolygon()` offers the option of leaving the polygon open--of not stroking the line that connects the first and last points in the list. The polygon therefore won't look like a polygon, but like an chain of lines fastened at their endpoints.

## Constructor and Destructor

### BPolygon()

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

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.

See also: `AddPoints()`

### ~BPolygon()

          virtual ~BPolygon()

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

## Member Functions

### AddPoints()

          void AddPoints(const BPoint *pointList, int32 numPoints)

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

See also: the BPolygon constructor

### CountPoints()

          int32 CountPoints(void) const

Returns the number of points that define the polygon.

### Frame()

          BRect Frame(void) const

Returns the polygon's frame rectangle--the smallest rectangle that encloses the entire polygon.

### MapTo()

          void 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 PrintToStream(void) 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

### = (assignment)

          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.

The Be Book, in lovely HTML, for BeOS Release 3.

Copyright © 1998 Be, Inc. All rights reserved.

Last modified March 26, 1998.