BPoint

Derived from: none

Declared in: be/interface/Point.h

Library: libbe.so


Overview

[method summary]

BPoint objects represent points on a two-dimensional coordinate grid. Each object holds an x coordinate value and a y coordinate value declared as public data members. These values locate a specific point, (x, y), relative to a given coordinate system.

Because the BPoint class defines a basic data type for graphic operations, its data members are publicly accessible and it declares no virtual functions. It's a simple class that doesn't inherit from BArchivable or any other class and doesn't have any virtual functions, not even a destructor. In the Interface Kit, BPoint objects are typically passed and returned by value, not through pointers.

For an overview of coordinate geometry for the BeOS, see The Coordinate Space .


Data Members

float x
The coordinate value measured horizontally along the x-axis.

float y
The coordinate value measured vertically along the y-axis.


Constructor


BPoint()

      inline BPoint(float x, float y)
      inline BPoint(const BPoint& point)
      inline BPoint(void)

Initializes a new BPoint object to (x, y), or to the same values as point. For example:

   BPoint somePoint(155.7, 336.0);
   BPoint anotherPoint(somePoint);

Here, both somePoint and anotherPoint are initialized to (155.7, 336.0).

If no coordinate values are assigned to the BPoint when it's declared,

   BPoint emptyPoint;

its initial values are indeterminate.

BPoint objects can also be initialized or modified using the Set() function,

   emptyPoint.Set(155.7, 336.0);
   anotherPoint.Set(221.5, 67.8);

or the assignment operator:

   somePoint = anotherPoint;

See also: Set(), the assignment operator


Member Functions


ConstrainTo()

      void ConstrainTo(BRect rect)

Constrains the point so that it lies inside the rect rectangle. If the point is already contained in the rectangle, it remains unchanged. However, if it falls outside the rectangle, it's moved to the nearest edge. For example, this code

   BPoint point(54.9, 76.3);
   BRect rect(10.0, 20.0, 40.0, 80.0);
   point.Constrain(rect);

modifies the point to (40.0, 76.3).

See also: BRect::Contains()


PrintToStream()

      void PrintToStream(void) const

Prints the contents of the BPoint object to the standard output stream (stdout) in the form:

   "BPoint(x, y)"

where x and y stand for the current values of the BPoint's data members.


Set()

      inline void Set(float x, float y)

Assigns the coordinate values x and y to the BPoint object. For example, this code

   BPoint point;
   point.Set(27.0, 53.4);

is equivalent to:

   BPoint point;
   point.x = 27.0;
   point.y = 53.4;

See also: the BPoint constructor


Operators


= (assignment)

      inline BPoint& operator =(const BPoint&) 

Assigns the x and y values of one BPoint object to another BPoint:

   BPoint a, b;
   a.Set(21.5, 17.0);
   b = a;

Point b, like point a, is set to (21.5, 17.0).


== (equality)

      bool operator ==(const BPoint&) const

Compares the data members of two BPoint objects and returns true if each one exactly matches its counterpart in the other object, and false if not. In the following example, the equality operator would return false:

   BPoint a(21.5, 17.0);
   BPoint b(17.5, 21.0);
   if ( a == b )
      . . .


!= (inequality)

      bool operator !=(const BPoint&) const

Compares two BPoint objects and returns true unless their data members match exactly (the two points are the same), in which case it returns false. This operator is the inverse of the == (equality) operator.


+ (addition)

      BPoint operator +(const BPoint&) const

Combines two BPoint objects by adding the x coordinate of the second to the x coordinate of the first and the y coordinate of the second to the y coordinate of the first, and returns a BPoint object that holds the result. For example:

   BPoint a(77.0, 11.0);
   BPoint b(55.0, 33.0);
   BPoint c = a + b;

Point c is initialized to (132.0, 44.0).


+= (addition and assignment)

      BPoint& operator +=(const BPoint&)

Modifies a BPoint object by adding another point to it. As in the case of the + (addition) operator, the members of the second point are added to their counterparts in the first point:

   BPoint a(77.0, 11.0);
   BPoint b(55.0, 33.0);
   a += b;

Point a is modified to (132.0, 44.0).


- (subtraction)

      BPoint operator -(const BPoint&) const

Subtracts one BPoint object from another by subtracting the x coordinate of the second from the x coordinate of the first and the y coordinate of the second from the y coordinate of the first, and returns a BPoint object that holds the result. For example:

   BPoint a(99.0, 66.0);
   BPoint b(44.0, 88.0);
   BPoint c = a - b;

Point c is initialized to (55.0, -22.0).


-= (subtraction and assignment)

      BPoint& operator -=(const BPoint&)

Modifies a BPoint object by subtracting another point from it. As in the case of the - (subtraction) operator, the members of the second point are subtracted from their counterparts in the first point. For example:

   BPoint a(99.0, 66.0);
   BPoint b(44.0, 88.0);
   a -= b;

Point a is modified to (55.0, -22.0).






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

Copyright © 1998 Be, Inc. All rights reserved.

Last modified January 29, 1998.