Bare Metal Programming Tool Kit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Static Public Member Functions | Related Functions | List of all members
bmptk::graphics::vector Class Reference

a relative or absolute (= relative to (0,0)) location on a grid More...

#include <graphics.h>

Public Member Functions

 vector ()
 construct a vector, the value defaults to (0,0)
 
 vector (short int x, short int y)
 construct a vector from its x and y coordinates
 
short int x_get () const
 get the x component
 
short int y_get () const
 get the y component
 
vector operator+ (const vector p) const
 add two vectors by adding the x and y coordinates
 
vector operator+= (const vector p)
 add a vector to an existing vector
 
vector operator+ (void) const
 return the vector unmodified
 
vector operator- (const vector p) const
 subtract two vectors by subtracting the coordinates
 
vector operator-= (const vector p)
 subtract a vector from an existing vector
 
vector operator- (void) const
 returns the negative of the vector (point-mirrored in the origin)
 
vector operator/ (int n) const
 divides a vector by an integer by dividing the coordinates
 
vectoroperator/= (int n)
 divides an existing vector by an integer
 
vector operator* (int n) const
 multiplies a vector by an integer by multiplying the coordinates
 
vectoroperator*= (int n)
 multiplies an existing vector by an integer
 
vector operator* (const vector rhs) const
 multiplying two vectors multiplies their X and Y components
 
bool operator== (const vector p) const
 reports whether two vectors are equal
 
bool operator!= (const vector p) const
 reports whether two vectors are unequal
 
vector direction (void) const
 returns the direction of a vector
 
vector abs (void) const
 returns the absolute of a vector
 
vector x_projection (void) const
 returns the projection of the vector on the x axis
 
vector y_projection (void) const
 returns the projection of the vector on the y axis
 
vector mirrored (void) const
 returns with x and y swapped
 
bool is_within (const vector p) const
 reports whether te vector is within the box [0,p>
 

Static Public Member Functions

static vector origin ()
 the vector (0,0)
 
static vector zero ()
 the vector (0,0)
 
static vector one ()
 the vector (1,1)
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &s, const vector p)
 prints a vector
 

Detailed Description

a relative or absolute (= relative to (0,0)) location on a grid

A vector is a pair of 16-bit integer values that are the x and y coordinates of an absolute or relative location on an integer grid. A vector can be constructed from its x and y values. When no values are supplied a vector defaults to (0,0).

Vectors are intended to represent a location, displacement, or size on a garphics screen. 16 bits should be more than enough for this purpose.

When a vector is used to identify a pixel on a screen (0,0) is the top-left pixel.

lcd_pixel_coordinates.bmp

Two vectors can be added or subtracted to yield a new vector. A vector can be multiplied or divided by an integer to yield a new vector. Vectors can be compared for equality and inequality. The x_projection() and y_projection() functions return the projection of the vector on the two axises. The function is_within() tests whether a vector is within the box bounded by the origin and the argument.

For debugging, a << operator is provided to print a vector.

A vector fits in a single (32 bits) word. It has no references to other objects.

Definition at line 52 of file graphics.h.

Member Function Documentation

vector bmptk::graphics::vector::abs ( void  ) const
inline

returns the absolute of a vector

The absolute of a vector is the original vector, mirrored into the first quadrant by the x and y axises. In other words, the x and y of the absolute are the absolutes of the original x and y.

Definition at line 156 of file graphics.h.

vector bmptk::graphics::vector::direction ( void  ) const
inline

returns the direction of a vector

The direction of a vector is a vector that, for both its x and y component, has the value 1 or -1, and the same sign as the original vector.

Definition at line 147 of file graphics.h.

bool bmptk::graphics::vector::is_within ( const vector  p) const
inline

reports whether te vector is within the box [0,p>

The call a.is_within(b) returns true iff a is within the rectangle [(0,0),b], where the boundary lines that go through (0,0) are included, but the boundaries that go through b are excluded.

Definition at line 187 of file graphics.h.

vector bmptk::graphics::vector::mirrored ( void  ) const
inline

returns with x and y swapped

In other words, the return vector as mirrored in the y=x line.

Definition at line 178 of file graphics.h.

vector bmptk::graphics::vector::x_projection ( void  ) const
inline

returns the projection of the vector on the x axis

In other words, the vector with y set to 0.

Definition at line 166 of file graphics.h.

vector bmptk::graphics::vector::y_projection ( void  ) const
inline

returns the projection of the vector on the y axis

In other words, the vector with x set to 0.

Definition at line 172 of file graphics.h.

Friends And Related Function Documentation

std::ostream & operator<< ( std::ostream &  s,
const vector  p 
)
related

prints a vector

This operator prints a vector in the (%d,%d) format.


The documentation for this class was generated from the following file: