Go to the documentation of this file.00001 #include "Map2DPosValue.h"
00002 #include <sstream>
00003
00004 #include <cmath>
00005
00006 using namespace std;
00007
00008 Map2DPosValue::Map2DPosValue(string varname, int x, int y, int height, double prob)
00009 {
00010 this->varName = varname;
00011 this->x = x;
00012 this->y = y;
00013 this->height = height;
00014 this->prob;
00015 }
00016
00017 Map2DPosValue::~Map2DPosValue(void)
00018 {
00019 }
00020
00021 string Map2DPosValue::ToString()
00022 {
00023 ostringstream ss;
00024 ss << "x" << x << "y"<< y;
00025 return ss.str();
00026 }
00027 int Map2DPosValue::getIndex()
00028 {
00029 return y*height + x;
00030 }
00031
00032 string Map2DPosValue::getVariableName()
00033 {
00034 return varName;
00035 }
00036 string Map2DPosValue::getValueName()
00037 {
00038 return this->ToString();
00039 }
00040
00041 double Map2DPosValue::getProb()
00042 {
00043 return prob;
00044 }
00045
00046 SharedPointer<Map2DPosValue> Map2DPosValue::duplicate()
00047 {
00048 SharedPointer<Map2DPosValue> result (new Map2DPosValue(this->getVariableName(), this->x, this->y, this->height));
00049 return result;
00050 }
00051 bool Map2DPosValue::isSamePos(SharedPointer<Map2DPosValue> dest)
00052 {
00053 if(this->x != dest->x)
00054 {
00055 return false;
00056 }
00057 if(this->y != dest->y)
00058 {
00059 return false;
00060 }
00061 if(this->varName.compare(dest->varName) != 0)
00062 {
00063 return false;
00064 }
00065 return true;
00066 }
00067 double Map2DPosValue::distanceTo(SharedPointer<Map2DPosValue> dest)
00068 {
00069 int xDiff = this->x - dest->x;
00070 int yDiff = this->y - dest->y;
00071
00072 double totalDiffSq = xDiff*xDiff + yDiff*yDiff;
00073 return sqrt(totalDiffSq);
00074 }
00075
00076 bool Map2DPosValue::equals(SharedPointer<IVariableValue> obj)
00077 {
00078 SharedPointer<Map2DPosValue> ptr = dynamic_pointer_cast<Map2DPosValue>(obj);
00079 bool result = true;
00080 result &= (this->x == ptr->x);
00081 result &= (this->y == ptr->y);
00082
00083 return result;
00084 }