Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "functionObjects.h"
00010 #include "QhullError.h"
00011 #include "Coordinates.h"
00012
00013 #include <iostream>
00014 #include <iterator>
00015 #include <algorithm>
00016
00017 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4
00018 #endif
00019
00020 namespace orgQhull {
00021
00022 #//! Coordinates -- vector of coordT (normally double)
00023
00024 #//Element access
00025
00026
00027 Coordinates Coordinates::
00028 mid(int idx, int length) const
00029 {
00030 int newLength= length;
00031 if(length<0 || idx+length > count()){
00032 newLength= count()-idx;
00033 }
00034 Coordinates result;
00035 if(newLength>0){
00036 std::copy(begin()+idx, begin()+(idx+newLength), std::back_inserter(result));
00037 }
00038 return result;
00039 }
00040
00041 coordT Coordinates::
00042 value(int idx, const coordT &defaultValue) const
00043 {
00044 return ((idx < 0 || idx >= count()) ? defaultValue : (*this)[idx]);
00045 }
00046
00047 #//Operator
00048
00049 Coordinates Coordinates::
00050 operator+(const Coordinates &other) const
00051 {
00052 Coordinates result(*this);
00053 std::copy(other.begin(), other.end(), std::back_inserter(result));
00054 return result;
00055 }
00056
00057 Coordinates & Coordinates::
00058 operator+=(const Coordinates &other)
00059 {
00060 if(&other==this){
00061 Coordinates clone(other);
00062 std::copy(clone.begin(), clone.end(), std::back_inserter(*this));
00063 }else{
00064 std::copy(other.begin(), other.end(), std::back_inserter(*this));
00065 }
00066 return *this;
00067 }
00068
00069 #//Read-write
00070
00071 coordT Coordinates::
00072 takeAt(int idx)
00073 {
00074 coordT c= at(idx);
00075 erase(begin()+idx);
00076 return c;
00077 }
00078
00079 coordT Coordinates::
00080 takeLast()
00081 {
00082 coordT c= last();
00083 removeLast();
00084 return c;
00085 }
00086
00087 void Coordinates::
00088 swap(int idx, int other)
00089 {
00090 coordT c= at(idx);
00091 at(idx)= at(other);
00092 at(other)= c;
00093 }
00094
00095 #//Search
00096
00097 bool Coordinates::
00098 contains(const coordT &t) const
00099 {
00100 CoordinatesIterator i(*this);
00101 return i.findNext(t);
00102 }
00103
00104 int Coordinates::
00105 count(const coordT &t) const
00106 {
00107 CoordinatesIterator i(*this);
00108 int result= 0;
00109 while(i.findNext(t)){
00110 ++result;
00111 }
00112 return result;
00113 }
00114
00115 int Coordinates::
00116 indexOf(const coordT &t, int from) const
00117 {
00118 if(from<0){
00119 from += count();
00120 if(from<0){
00121 from= 0;
00122 }
00123 }
00124 if(from<count()){
00125 const_iterator i= begin()+from;
00126 while(i!=constEnd()){
00127 if(*i==t){
00128 return (static_cast<int>(i-begin()));
00129 }
00130 ++i;
00131 }
00132 }
00133 return -1;
00134 }
00135
00136 int Coordinates::
00137 lastIndexOf(const coordT &t, int from) const
00138 {
00139 if(from<0){
00140 from += count();
00141 }else if(from>=count()){
00142 from= count()-1;
00143 }
00144 if(from>=0){
00145 const_iterator i= begin()+from+1;
00146 while(i-- != constBegin()){
00147 if(*i==t){
00148 return (static_cast<int>(i-begin()));
00149 }
00150 }
00151 }
00152 return -1;
00153 }
00154
00155 void Coordinates::
00156 removeAll(const coordT &t)
00157 {
00158 MutableCoordinatesIterator i(*this);
00159 while(i.findNext(t)){
00160 i.remove();
00161 }
00162 }
00163
00164 }
00165
00166 #//Global functions
00167
00168 using std::endl;
00169 using std::istream;
00170 using std::ostream;
00171 using std::string;
00172 using std::ws;
00173 using orgQhull::Coordinates;
00174
00175 ostream &
00176 operator<<(ostream &os, const Coordinates &cs)
00177 {
00178 Coordinates::const_iterator c= cs.begin();
00179 for(int i=cs.count(); i--; ){
00180 os << *c++ << " ";
00181 }
00182 return os;
00183 }
00184