Basic Concepts for 2D Graphics

This section describes basic concepts for 2D graphics:

Understanding these features and mechanisms help you use the 2D Graphics framework more effectively.

2D Coordinate System and Unit Resolution

The 2D geometry classes are specified in x and y coordinate units. As shown in the figure, the default 2D coordinate system is left-handed (y-axis going down). The 2D Graphics Framework uses left-handed 2D coordinate system as a default because a typical document page starts at the top and extends downward. This is referred to as World Coordinate space through out this guide.

NOTE: The enumerated type EDeviceCoordinateSystem defined in IExtendedRootGrafPort allows you specify left or right handed coordinate system. If the kLefthand value is used, the 2D Graphics Framework uses the left-handed coordinate system. If the kRighthand value is used, the 2DGraphics Framework uses the right-handed coordinate system.

Positive coordinate units along the x-axis lie to the right of the origin and positive coordinate units along the y-axis lie below the origin. The grid lines represent where points in coordinate units lie. For example, the point (5, 3) is five grid lines in the positive x direction, and three grid lines in the positive y direction. The position of the origin (0,0) is in the upper-left corner of the view.

The resolution of any coordinate or dimension is assumed to be one pixel on a screen display. For printing and other devices, this coordinate unit is defined as 1/72 inch (one seventy-second of an inch) to equal 1 point. A point is the unit of measurement used by printers, graphic designers, and type setters. Therefore, when printing a graphic view of a one inch window on the 96 dpi CRT display, the resulting area on paper is 1.25 (one and one-quarter) inch in size, with a transform being identity because it is common and convenient for desktop publishing system to assume that 1 pixel equals 1 point. For user interface design on screen, it is essential to have exact number of pixels as the unit rather than other units.

Numeric and Arithmetic Data Types

2D geometry is based on IEEE double-precision floating point numerical values. The system has the following benefits and reduces the risk of numeric errors:

The following data types define the variables used in 2D calculations.

GCoordinate

typedef double GCoordinate;

GCoordinate expresses values defined or measured in 2D coordinate units such as positions or lengths. It maps directly to pixels on the screen and logical 1/72 inch on printers. If metric fidelity is required between the screen and printer, use IMetricGrafPort. Variables of type GCoordinate are used in all of the geometry classes to allow for smooth curves. GCoordinate provides sufficient range and precision for large documents, complex curves, and matrix operations.

GDegrees

typedef double GDegrees;

GDegrees measures angles in degrees and is used when an angle needs to be specified or returned. Angles start with 0 degrees at the +x-axis, and they increase from 0 degrees to 360 degrees going clockwise in 2D (because the +y-axis points down). Angles greater than 360 degrees are interpreted as modulo 360 degrees. Negative angles are added to a multiple of 360 degrees.

GParametric

typedef double GParametric;

GParametric represents the parameter of a parametric curve, loop, or surface. The parametric curve or loop is represented by the function P(u) that returns point P on the curve for a particular value of the parameter u. P(0) returns the point at the start of the curve, and P(1) returns the point at the end of the curve

GIntensity

typedef float GIntensity;

GIntensity is a 32-bit data type that represents a range between 0 and 1.0 that is used in most device color spaces to represent color intensity. This data type is found in the IBasicColor class.