NLS Engine  v0.1
The Next Logical Step in game engine design.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
PointList.cpp
Go to the documentation of this file.
00001 
00011 #include "PointList.h"
00012 
00013 // System Library Includes
00014 
00015 // Application Library Includes
00016 
00017 // Local Includes
00018 
00019 // Forward Declarations
00020 
00021 // Typedefs and data structures
00022 
00023 // Constants
00024 
00025 // Class methods
00026 
00027 PointList::PointList() : index(0), loop(true) {
00028 
00029 }
00030 
00031 
00032 PointList::~PointList() {
00033 
00034 }
00035 
00036 void PointList::AddPoint( Point p ) {
00037   if (!PointExists(p)) {
00038     this->points.push_back(p);
00039   }
00040 }
00041 
00042 void PointList::RemovePoint( Point p ) {
00043   for (auto itr = this->points.begin(); itr != this->points.end(); ++itr) {
00044     if ((itr->x == p.x) && (itr->y == p.y)) {
00045       this->points.erase(itr);
00046       return;
00047     }
00048   }
00049 }
00050 
00051 bool PointList::PointExists( Point p ) {
00052   for (auto itr = this->points.begin(); itr != this->points.end(); ++itr) {
00053     if ((itr->x == p.x) && (itr->y == p.y)) {
00054       return true;
00055     }
00056   }
00057 
00058   return false;
00059 }
00060 
00061 Point PointList::FirstPoint() {
00062   this->index = 0;
00063 
00064   return CurrentPoint();
00065 }
00066 
00067 Point PointList::NextPoint() {
00068   if ((this->index + 1) < this->points.size()) {
00069     ++this->index;
00070   }
00071   else {
00072     if (loop == true) {
00073       this->index = 0;
00074     }
00075   }
00076 
00077   return CurrentPoint();
00078 }
00079 
00080 Point PointList::PeekNextPoint() {
00081   if (this->points.size() > 0) {
00082     if ((this->index + 1) < this->points.size()) {
00083       return this->points[this->index + 1];
00084     }
00085     else {
00086       if (loop == true) {
00087         return this->points[0];
00088       }
00089       else {
00090         return this->points[this->points.size() - 1];
00091       }
00092     }
00093   }
00094   return Point();
00095 }
00096 
00097 Point PointList::CurrentPoint() {
00098   if ((this->points.size() > 0) && (this->index < this->points.size())) {
00099     return this->points[this->index];
00100   }
00101   return Point();
00102 }
00103 
00104 Point PointList::IndexPoint( unsigned int i ) {
00105   if (i < (this->points.size() - 1)) {
00106     this->index = i;
00107   }
00108 
00109   return CurrentPoint();
00110 }
00111 Point PointList::GotoPoint( Point p ) {
00112   for (unsigned int i = 0; i < this->points.size(); ++i) {
00113     if ((this->points[i].x == p.x) && (this->points[i].y == p.y))   {
00114       this->index = i;
00115     }
00116   }
00117   return CurrentPoint();
00118 }
00119 
00120 
00121 Point PointList::PrevPoint() {
00122   if ((this->index - 1) > 0 ) {
00123     --this->index;
00124   }
00125   else {
00126     if (loop == true) {
00127       this->index = this->points.size() - 1;
00128     }
00129   }
00130 
00131   return CurrentPoint();
00132 }
00133 
00134 Point PointList::PeekPrevPoint() {
00135   if (this->points.size() > 0) {
00136     if ((this->index - 1) > 0) {
00137       return this->points[this->index - 1];
00138     }
00139     else {
00140       if (loop == true) {
00141         return this->points[this->points.size() - 1];
00142       }
00143       else {
00144         return this->points[0];
00145       }
00146     }
00147   }
00148   return Point();
00149 }
00150 
00151 
00152 Point PointList::LastPoint() {
00153   this->index = this->points.size() - 1;
00154 
00155   return CurrentPoint();
00156 }
00157 
00158 std::vector<Point>::iterator PointList::BeginPoint() {
00159   return this->points.begin();
00160 }
00161 
00162 std::vector<Point>::iterator PointList::NthPoint( unsigned int n ) {
00163   if (n < (this->points.size() - 1)) {
00164     return (this->points.begin() + n);
00165   }
00166 
00167   return this->points.end();
00168 }
00169 
00170 std::vector<Point>::iterator PointList::EndPoint() {
00171   return this->points.end();
00172 }
00173 unsigned int PointList::Size() {
00174   return this->points.size();
00175 }
00176 
00177 
00178 void PointList::Loop( bool loop ) {
00179   this->loop = loop;
00180 }
00181 
00182 void PointList::Clear() {
00183   this->points.clear();
00184 }