CS488 PA2
|
#include <Vector.h>
Public Member Functions | |
Vector (int size) | |
Vector (int size, char orientation) | |
Vector (const Vector &original) | |
~Vector () | |
double | get (int i) const |
char | getOrientation () const |
int | getSize () const |
double & | operator() (int i) |
Vector & | operator= (std::initializer_list< double > values) |
Vector & | operator= (const Vector &other) |
Static Public Attributes | |
static const char | COLUMN = 'C' |
static const char | ROW = 'R' |
Protected Member Functions | |
void | allocateMemory () |
void | deallocateMemory () |
void | setSize (int size, char orientation) |
void | setValues (double value) |
void | setValues (const double *values) |
Protected Attributes | |
char | orientation |
double * | values |
int | size |
Friends | |
double | norm (const Vector &a) |
Vector | normalized (const Vector &a) |
Vector | operator+ (const Vector &a, const Vector &b) |
Vector | operator- (const Vector &a, const Vector &b) |
double | operator* (const Vector &a, const Vector &b) |
Vector | operator* (double k, const Vector &a) |
Vector | operator* (const Vector &a, double k) |
bool | operator== (const Vector &a, const Vector &b) |
bool | operator!= (const Vector &a, const Vector &b) |
Vector | trans (const Vector &a) |
The Vector class is an encapsulation of both n-dimensional points and n-dimensional direction vectors.
|
explicit |
Vector::Vector | ( | int | size, |
char | orientation | ||
) |
Construct a column or row vector of given size.
Example of use:
size | The size of the Vector |
orientation | The orientation (either COLUMN or ROW) |
Vector::Vector | ( | const Vector & | original | ) |
Vector::~Vector | ( | ) |
Destructor.
|
protected |
Allocate memory for this Vector.
|
protected |
Deallocate the memory used by this Vector.
double Vector::get | ( | int | i | ) | const |
Get a particular element of this Vector.
i | The index of the element |
out_of_range | exception |
char Vector::getOrientation | ( | ) | const |
Get the orientation of this Vector.
int Vector::getSize | ( | ) | const |
Get the size of this Vector.
double & Vector::operator() | ( | int | i | ) |
Access an element of this Vector using the function-call operator.
Note: This method returns by reference so that this operator can be used on the left side of the assignment operator. Though this can be dangerous in general (since the value being referred to may not always exist), in this case it shouldn't cause any problems.
Examples of use:
i | The index of the element |
out_of_range | exception |
Vector & Vector::operator= | ( | std::initializer_list< double > | values | ) |
Assign an initializer_list to this Vector.
Examples of use:
Note: This method is not void so that one can write x = y = {1,2} (which first assigns {1,2} to y and then assigns the result of that assignment to x). It returns the result by reference because there is no chance that this will not refer to something.
values | The initializer_list containing the values |
length_error | if the number of values is incorrect |
Assign another Vector to this Vector.
The two Vectors must have the same size and orientation.
Note: This method is not void so that one can write x = y = z (which first assigns z to y and then assigns the result of that assignment to x). It returns the result by reference because there is no concern that this will not refer to something.
other | The right-side Vector |
length_error | if the sizes or orientations don't match |
|
protected |
Set the size (and orientation) of this Vector. Note: This method should only be called by constructors.
size | The size (default is 1); |
orientation | The orientation (default is COLUMN) |
|
protected |
Set all the elements of this Vector to a given value.
value | The value |
|
protected |
Set the values of the elements of this Vector to the corresponding values in an array.
values | The values |
|
friend |
Multiply two Vectors (i.e., find the dot/inner product)
The two Vectors must have the same size and same orientation
length_error | if the sizes or orientations don't match |
Subtract the Vector b from the Vector a (component by component).
The two Vectors must have the same size and orientation.
Note: This method must return by value because the result Vector is a local variable.
length_error | if the sizes or orientations don't match |
|
static |
Constant indicating a column Vector.
|
protected |
The orientation of this Vector (COLUMN or ROW).
|
static |
Constant indicating a row Vector.
|
protected |
The size of this Vector.
|
protected |
The elements of this Vector.