WWC snapshot of http://www.alw.nih.gov/Docs/NIHCL/nihcl_38.html taken on Sat Jun 10 19:13:57 1995

Go to the previous, next section.

Point--X-Y Coordinate Pair

#include <nihcl/Point.h>

SYNOPSIS

BASE CLASS

Object

DERIVED CLASSES

None

RELATED CLASSES

None

DESCRIPTION

Instances of class Point represent x-y coordinate pairs. By (Smalltalk-80) convention, Point(0,0) is the top left corner of the display, with x increasing to the right and y increasing to the bottom.

CONSTRUCTORS

Point()
Constructs an instance of class Point initialized to (0,0).

Point(short newx, short newy)
Constructs an instance of class Point initialized to (newx,newy).

ACCESSING POINTS

short x() const
short y() const
Returns the x or y coordinate value of this Point.

short x(short newx)
short y(short newy)
Sets the x or y coordinate value of this Point to newx or newy, respectively, and returns the new value.

SEARCHING

virtual unsigned hash() const
Returns a value suitable for use as a hash table probe.

RELATIONAL OPERATORS

bool operator==(const Point&) const
bool operator!=(const Point&) const
Returns YES if the left Point operand is equal to (or not equal to) the right Point operand.

bool operator<(const Point&) const
bool operator<=(const Point&) const
bool operator>(const Point&) const
bool operator>=(const Point&) const
Returns YES if the relation holds between both the x and y coordinates of the operands. For example, point (Ax,Ay) < point (Bx,By) if Ax < Bx and Ay < By.

ARITHMETIC OPERATORS

Point operator-() const
Returns a Point with x and y coordinate values opposite in sign from the x and y coordinate values of the operand Point. For example, -Point(1,2) is (-1,-2).

Point operator+(const Point&) const
Point operator-(const Point&) const
Returns a Point with x and y coordinate values that are the sum or difference of the x and y coordinate values of the operand Points. For example, Point(1,2) + Point(3,4) is (4,6).

friend Point operator*(const Point& p, int i)
friend Point operator*(int i, const Point& p)
Scales the x and y coordinates of Point p by the integer i. For example, 2 * Point(1,2) is (2,4).

int operator*(const Point&) const
Returns the sum of the products of the x and y coordinate values of the operand Points. For example, Point(1,2) * Point(3,4) is 1*3 + 2*4 = 11.

void operator+=(const Point&)
void operator-=(const Point&)
Replaces this Point by one that is the sum or difference of the x and y coordinates of this Point and those of the right operand Point. For example

Point p(1,2);
p += Point(3,4);
cout << p << endl;

prints (4,6).

void operator*=(int s)
Replaces this Point by one with the x and y coordinates each multiplied by s. For example:

Point p(1,2);
p *= 10;
cout << p << endl;

prints (10,20).

COMPARING POINTS

Point max(const Point& p) const
Point min(const Point& p) const
Returns a Point whose x coordinate is the larger (smaller) of this Point's x coordinate and that of p, and whose y coordinate is the larger (smaller) of this Point's y coordinate and that of p.

virtual int compare(const Object& ob) const
Compares this Point with the argument object ob, which must also be an instance of class Point. Returns a negative result if this Point is less than ob, zero if this Point equals ob, and a positive result if this Point is greater than ob. One point is considered greater than another if its y coordinate is greater, or if its y coordinate is equal and its x coordinate is greater.

TESTING POINTS

bool isBelow(const Point& p) const { return yc > p.yc; }
bool isAbove(const Point& p) const { return yc < p.yc; }
Returns YES if the y coordinate of this Point is greater than (or less than, respectively) the y coordinate of Point p.

bool isRight(const Point& p) const { return xc > p.xc; }
bool isLeft(const Point& p) const { return xc < p.xc; }
Returns YES if the x coordinate of this Point is greater than (or less than, respectively) the x coordinate of Point p.

virtual bool isEqual(const Object& ob) const
Returns YES if ob is of species Point and equals this Point.

CONVERTING POINTS

double dist(const Point& p) const
Returns the distance between this Point and the Point p.

Point transpose() const
Returns a Point whose x coordinate is equal to the y coordinate of this Point and whose y coordinate is equal to the x coordinate of this Point.

COPYING POINTS

virtual void deepenShallowCopy()
This function is a no-op for class Point.

READING AND PRINTING POINTS

virtual void printOn(ostream& strm =cout) const
Prints this Point on the output stream strm in the format (x,y).

POINT SPECIES

virtual const Class* species() const
Returns a pointer to the class descriptor for class Point.

PROTECTED MEMBERS

Member Variables

short xc,yc;
The x and y coordinates of this Point.

Object I/O

virtual void storer(OIOofd& fd) const
virtual void storer(OIOout& strm) const
Stores this Point on fd or strm.

EXCEPTIONS RAISED

None

Go to the previous, next section.