### Computational Geometry Classes

Computational geometry classes consist of basic definitions for completing geometric computations. Computational geometry is used for calculations. It is not rendered directly except IGRect2D, which is filled and framed like other area-enclosing geometry. Use these classes for constructing other types of geometry.

### Points

The IGPoint2D class defines (x, y) coordinates that represent a point or vector on the 2D coordinate plane. The IGRPoint2D class defines (x, y, w) coordinate values that represent a homogeneous (rational) point or vector on the 2D coordinate plane. The IGPoint2D and IGRPoint2D member functions are summarized here:

IGPoint2D:

- crossProduct
- dotProduct
- interpolate
- setPolarCoordinates
- setVectorLength
- setVectorAngle
- vectorLength
- vectorAngle

IGRPoint2D

- divW
- dropW

### IGPoint2D

IGPoint2D defines points on the coordinate plane. Some functions also treat IGPoint2Ds as vectors. IGPoint2Ds are used as the basic building blocks for most of the geometric primitives, and as a computational type for many types of geometric calculations.

This is a primitive type, and is not intended to be subclassed. IGPoint2Ds are treated much like numbers, with the typical operators (+, -, *, /) defined for them and acting component-wise on the fX and fY variables.

For example,

IGPoint2D a, b, c;
c = a + b;

Is equivalent to:

IGPoint2D a, b, c;
c.fX = a.fX + b.fX;
c.fY = a.fY + b.fY;

The complete list of operators defined for points is:

+, -, *, /, +=, -=, *=, /=, ==, !=, []

A numeric value can be supplied with the * and / operators to work as a scalar multiply; (for example, it is treated as a point with both fX and fY set to the value). The [ ] operator indexes the components (p[0] returns fX, p[1] returns fY). IGPoint2D's member variables, fX and fY are public, and designed to be directly accessed.

Mathematics makes distinction between points and vectors. Because their representation is the same, the 2D Graphics framework uses IGPoint2D in both roles.

### IGRPoint2D

IGRPoint2D defines rational points containing a third coordinate, fW. They are most commonly used for defining rational or homogeneous coordinates in IGCurve2D. Curves use the rational coordinates to accurately represent conic sections (curves, arcs, ellipses, and so on). Rational points are also occasionally useful for situations where you need to keep track of a "perspective" term. Typically, you do not deal directly with IGRPoint2Ds, because the curve and transformation implementation manage the mathematical details.

Unlike IGPoint2D, the only operators defined for IGRPoint2D are ==, != and []. The [] operator indexes the fX, fY and fW components (p[0] returns fX, p[1] returns fY, and p[2] returns fW).

You can construct IGRPoint2Ds directly from IGPoint2Ds. In this case the value of the rational component fW is set to 1.0. Conversion from IGRPoint2Ds to IGPoint2Ds must be done explicitly via the divW and dropW methods.

### IGRect2D

The IGRect2D class defines an axis-aligned rectangle defined by four coordinates, the top, left, bottom and right. Like IGPoint2D, IGRect2D is a "primitive" type, and not intended to be subclassed or extended. Also like IGPoint2D, the member variables of IGRect2D are public for ease of access. An IGRect2D is renderable by the IGrafPort as both a filled and a framed object.

When IGrafPort renders a filled and framed rectangle, the frame occupies the exterior boundary of the rectangle and the filled area occupies the entire rectangle except for the right and the lower exterior boundaries. For example, the frame for an IGRect2D with the dimensions (0,0) - (5,5) consists of four lines running from (0,0) to (5,0) to (5,5) to (0,5) to (0,0). The filled area for the rectangle occupies all the elements from (0,0) to (4,0), (0,1) to (4,1), down to and including (0,4) to (4,4). Thus, the filled area overlaps the upper and left frame lines, but not the lower and right frame lines.

An IGRect2D is considered to be "empty" if fRight <= fLeft or fBottom <= fTop. Empty IGRect2Ds do not fill, and the extendTo ignores them. To find out if a rectangle is empty, call the isEmpty function.