The Interface Kit: BPoint

The Interface Kit Table of Contents | The Interface Kit Index

# BPoint

Derived from: none

Declared in: be/interface/Point.h

Library: libbe.so

Allocation: Constructor or on the stack, typically the latter.

###### Summary

BPoint objects represent points on a two-dimensional coordinate grid. The object's coordinates are stored as public `x` and `y` data members. The BPoint class declares a global object, `B_ORIGIN`, that represents (0,0).

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

## 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`) `

Creates a new BPoint object that corresponds to the point (x, y), or that's copied from point. If no coordinate values are assigned, the BPoint's location is indeterminate.

See also: `Set()`, the assignment operator

## Member Functions

### ConstrainTo()

void `ConstrainTo(` BRect rect`) `

Ensures that the BPoint lies within rect. If it's already contained in the rectangle, the BPoint is unchanged; otherwise, it's moved to the rect's nearest edge.

See also: `BRect::Contains()`

### PrintToStream()

void `PrintToStream(`void`)` const

Prints the BPoint's coordinates to standard output in the form:

       "BPoint(x, y)"

### Set()

inline void `Set(`float x, float y`) `

Sets the BPoint's x and y coordinates.

See also: the BPoint constructor

## Operators

### = (assignment)

inline BPoint& `operator =(`const BPoint &from`)`

Copies from's coordinate data into the left-side object.

### == (equality), != (inequality)

bool `operator ==(`BPoint`)` const
bool `operator !=(`BPoint`)` const

== returns `true` if the two objects' point exactly coincide.

!= returns `true` if the two objects' points don't coincide.

### + (addition), += (addition and assignment)

BPoint `operator +(`const BPoint&`)` const
BPoint& `operator +=(`const BPoint&`)`

`+` creates and returns a new BPoint that adds the two operands together. The new object's `x` coordinate is the sum of the operands' `x` values; its `y` value is the sum of the operands' `y` values.

`+=` adds the operands together and stores the result in the left operand.

### – (subtraction), –= (subtraction and assignment)

BPoint `operator –(`const BPoint&`)` const
BPoint& `operator –=(`const BPoint&`) `

`-` creates and returns a new BPoint that subtracts the right operand from the left. The new object's `x` coordinate is the difference between the operands' `x` values; its `y` value is the difference between the operands' `y` values.

`-=` performs the subtraction and stores the result in the left operand.

## Global Objects

### B_ORIGIN

BPoint object that represents (0,0).

The Interface Kit Table of Contents | The Interface Kit Index

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

Copyright © 2000 Be, Inc. All rights reserved..