SpaceVector.h


Dosyayı İndir
#ifndef SPACEVECTOR_H_INCLUDED
#define SPACEVECTOR_H_INCLUDED

#include <iostream>

#include "MathUtilities.h"

using namespace std;

#define DIMENSION_COUNT 4

#define X 0
#define Y 1
#define Z 2
#define W 3

class SpaceVector {
public:
    SpaceVector();
    SpaceVector(const double value);
    SpaceVector(const double x, const double y,const double z,const double w=1);
    SpaceVector(double values[DIMENSION_COUNT]);
    SpaceVector(const SpaceVector &another);
    ~SpaceVector();
    void setValues (double *values);
    double *getValues() const;
    void setValues (const double x, const double y,const double z,const double w=1);
    double getValue (int index) const;
    void setValue (int index,double value);
    int getElementCount() const;
    void print() const;
    double getX() const;
    void setX(double x);
    double getY() const;
    void setY(double y);
    double getZ() const;
    void setZ(double z);
    double getW() const;
    void setW(double w);
    double operator[] (int index) const;
    double &operator[] (int index);
    SpaceVector operator+(SpaceVector another) const;
    SpaceVector operator-(SpaceVector another) const;
    SpaceVector operator-() const ;
    SpaceVector operator/(double divisor) const;
protected:
    double *_array;
};
SpaceVector::SpaceVector(): SpaceVector(0,0,0,0){
}

SpaceVector:: SpaceVector(const double value) : SpaceVector(value,value,value,value)
{
}
SpaceVector:: SpaceVector(const double x, const double y,const double z,const double w)
{
    _array=new double[DIMENSION_COUNT];
    setValues(x,y,z,w);
}
SpaceVector::SpaceVector(double *values){
   setValues(values);
}
SpaceVector::SpaceVector(const SpaceVector &another){
    _array=vector_copy(another.getValues(),DIMENSION_COUNT);
}
SpaceVector::~SpaceVector(){
    delete  [] _array;
}

void SpaceVector::setValues(double *values){
   _array=values;
}
void SpaceVector::setValues(const double x, const double y,const double z,const double w)
{
    setValue(X,x);
    setValue(Y,y);
    setValue(Z,z);
    setValue(W,w);
}
double *SpaceVector::getValues() const{
    return _array;
}
int SpaceVector::getElementCount() const{
    return DIMENSION_COUNT;
}

double SpaceVector::getValue (int index) const{
    return _array[index];
}
void SpaceVector::setValue (int index,double value){
    _array[index]=value;
}
void SpaceVector::print() const{
    vector_print(cout,getValues(),getElementCount());
}
double SpaceVector::getX() const{
    return getValue(X);
}
void SpaceVector::setX(double x){
    setValue(X,x);
}
double SpaceVector::getY() const{
    return getValue(Y);
}
void SpaceVector::setY(double y){
    setValue(Y,y);
}
double SpaceVector::getZ() const{
    return getValue(Z);
}
void SpaceVector::setZ(double z){
    setValue(Z,z);
}
double SpaceVector::getW() const{
    return getValue(W);
}
void SpaceVector::setW(double w){
    setValue(W,w);
}

double SpaceVector::operator [] (int index) const{
    return _array[index];
}
double &SpaceVector::operator [] (int index) {
    return _array[index];
}
SpaceVector SpaceVector::operator+(SpaceVector another) const{
    return SpaceVector(vector_add(getValues(),another.getValues(),getElementCount()));

}
SpaceVector SpaceVector::operator-(SpaceVector another) const{
    return SpaceVector(vector_substract(getValues(),another.getValues(),getElementCount()));
}
SpaceVector SpaceVector::operator-() const {
      return SpaceVector(vector_negate(getValues(),getElementCount()));
 }
SpaceVector SpaceVector::operator/(double divisor) const{
    return SpaceVector(vector_divide(getValues(),divisor,getElementCount()));
}
#endif

				
Dosyayı İndir

Bu Sayfayı Paylaş:




Bu Sayfayı Paylaş:

İletişim Bilgileri

Takip Et

Her Hakkı Saklıdır. Bu sitede yayınlanan tüm bilgi ve fikirlerin kullanımından fibiler.com sorumlu değildir. Bu sitede üretilmiş , derlenmiş içerikleri, fibiler.com'u kaynak göstermek koşuluyla kendi sitenizde kullanılabilirsiniz. Ancak telif hakkı olan içeriklerin hakları sahiplerine aittir