gtypes.h

This interface defines types for representing points, dimensions, and rectangles.
Types
GPoint This type contains real-valued x and y fields.
GDimension This type contains real-valued width and height fields.
GRectangle This type contains real-valued x, y, width, and height fields.
Functions
createGPoint(x, y) Creates a GPoint structure with the specified x and y coordinates.
getX(pt) Returns the x component of the GPoint.
getY(pt) Returns the y component of the GPoint.
createGDimension(width, height) Creates a GDimension value with the specified width and height coordinates.
getWidth(dim) Returns the width component of the GDimension.
getHeight(dim) Returns the width component of the GDimension.
createGRectangle(x, y, width, height) Creates a GRectangle value with the specified components.
getX(r) Returns the x component of the rectangle.
getY(r) Returns the y component of the rectangle.
getWidth(r) Returns the width component of the GRectangle.
getHeight(r) Returns the width component of the GRectangle.
isEmpty(r) Returns true if the rectangle is empty.
contains(r, pt) Returns true if the rectangle contains the given point.

Type detail


typedef struct {
   double x;
   double y;
} GPoint;
This type contains real-valued x and y fields. It is used to represent a location on the graphics plane.

typedef struct {
   double width;
   double height;
} GDimension;
This type contains real-valued width and height fields. It is used to indicate the size of a graphical object.

typedef struct {
   double x;
   double y;
   double width;
   double height;
} GRectangle;
This type contains real-valued x, y, width, and height fields. It is used to represent the bounding box of a graphical object.

Function detail


GPoint createGPoint(double x, double y);
Creates a GPoint structure with the specified x and y coordinates.

Usage:

pt = createGPoint(x, y);

double getX(GPoint pt);
Returns the x component of the GPoint.

Usage:

x = getX(pt);

double getY(GPoint pt);
Returns the y component of the GPoint.

Usage:

y = getY(pt);

GDimension createGDimension(double width, double height);
Creates a GDimension value with the specified width and height coordinates.

Usage:

dim = createGDimension(width, height);

double getWidth(GDimension dim);
Returns the width component of the GDimension.

Usage:

width = getWidth(dim);

double getHeight(GDimension dim);
Returns the width component of the GDimension.

Usage:

width = getHeight(dim);

GRectangle createGRectangle(double x, double y, double width, double height);
Creates a GRectangle value with the specified components.

Usage:

r = createGRectangle(x, y, width, height);

double getX(GRectangle r);
Returns the x component of the rectangle.

Usage:

double x = getX(r);

double getY(GRectangle r);
Returns the y component of the rectangle.

Usage:

double y = getY(r);

double getWidth(GRectangle r);
Returns the width component of the GRectangle.

Usage:

width = getWidth(r);

double getHeight(GRectangle r);
Returns the width component of the GRectangle.

Usage:

width = getHeight(r);

bool isEmpty(GRectangle r);
Returns true if the rectangle is empty.

Usage:

if (isEmpty(r)) . . .

bool contains(GRectangle r, GPoint pt);
Returns true if the rectangle contains the given point.

Usage:

if (contains(r, pt)) . . .