CASM  1.1.0
A Clusters Approach to Statistical Mechanics
Coordinates.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (c) 2009-2015 C.B. Barber. All rights reserved.
4 ** $Id: //main/2015/qhull/src/libqhullcpp/Coordinates.cpp#1 $$Change: 1981 $
5 ** $DateTime: 2015/09/28 20:26:32 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 #include "functionObjects.h"
10 #include "QhullError.h"
11 #include "Coordinates.h"
12 
13 #include <iostream>
14 #include <iterator>
15 #include <algorithm>
16 
17 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4
18 #endif
19 
20 namespace orgQhull {
21 
22 #
23 
24 #
25 
26 #
27 
28 // Inefficient without result-value-optimization or implicitly shared object
29 Coordinates Coordinates::
30 mid(countT idx, countT length) const
31 {
32  countT newLength= length;
33  if(length<0 || idx+length > count()){
34  newLength= count()-idx;
35  }
36  Coordinates result;
37  if(newLength>0){
38  std::copy(begin()+idx, begin()+(idx+newLength), std::back_inserter(result));
39  }
40  return result;
41 }//mid
42 
43 coordT Coordinates::
44 value(countT idx, const coordT &defaultValue) const
45 {
46  return ((idx < 0 || idx >= count()) ? defaultValue : (*this)[idx]);
47 }//value
48 
49 #
50 
51 Coordinates Coordinates::
52 operator+(const Coordinates &other) const
53 {
54  Coordinates result(*this);
55  std::copy(other.begin(), other.end(), std::back_inserter(result));
56  return result;
57 }//operator+
58 
59 Coordinates & Coordinates::
60 operator+=(const Coordinates &other)
61 {
62  if(&other==this){
63  Coordinates clone(other);
64  std::copy(clone.begin(), clone.end(), std::back_inserter(*this));
65  }else{
66  std::copy(other.begin(), other.end(), std::back_inserter(*this));
67  }
68  return *this;
69 }//operator+=
70 
71 #
72 
73 void Coordinates::
74 append(int pointDimension, coordT *c)
75 {
76  if(c){
77  coordT *p= c;
78  for(int i= 0; i<pointDimension; ++i){
79  coordinate_array.push_back(*p++);
80  }
81  }
82 }//append dim coordT
83 
84 coordT Coordinates::
85 takeAt(countT idx)
86 {
87  coordT c= at(idx);
88  erase(begin()+idx);
89  return c;
90 }//takeAt
91 
92 coordT Coordinates::
93 takeLast()
94 {
95  coordT c= last();
96  removeLast();
97  return c;
98 }//takeLast
99 
100 void Coordinates::
101 swap(countT idx, countT other)
102 {
103  coordT c= at(idx);
104  at(idx)= at(other);
105  at(other)= c;
106 }//swap
107 
108 #
109 
110 bool Coordinates::
111 contains(const coordT &t) const
112 {
113  CoordinatesIterator i(*this);
114  return i.findNext(t);
115 }//contains
116 
117 countT Coordinates::
118 count(const coordT &t) const
119 {
120  CoordinatesIterator i(*this);
121  countT result= 0;
122  while(i.findNext(t)){
123  ++result;
124  }
125  return result;
126 }//count
127 
128 countT Coordinates::
129 indexOf(const coordT &t, countT from) const
130 {
131  if(from<0){
132  from += count();
133  if(from<0){
134  from= 0;
135  }
136  }
137  if(from<count()){
138  const_iterator i= begin()+from;
139  while(i!=constEnd()){
140  if(*i==t){
141  return (static_cast<countT>(i-begin())); // WARN64 coordinate index
142  }
143  ++i;
144  }
145  }
146  return -1;
147 }//indexOf
148 
149 countT Coordinates::
150 lastIndexOf(const coordT &t, countT from) const
151 {
152  if(from<0){
153  from += count();
154  }else if(from>=count()){
155  from= count()-1;
156  }
157  if(from>=0){
158  const_iterator i= begin()+from+1;
159  while(i-- != constBegin()){
160  if(*i==t){
161  return (static_cast<countT>(i-begin())); // WARN64 coordinate index
162  }
163  }
164  }
165  return -1;
166 }//lastIndexOf
167 
168 void Coordinates::
169 removeAll(const coordT &t)
170 {
171  MutableCoordinatesIterator i(*this);
172  while(i.findNext(t)){
173  i.remove();
174  }
175 }//removeAll
176 
177 }//namespace orgQhull
178 
179 #
180 
181 using std::endl;
182 using std::istream;
183 using std::ostream;
184 using std::string;
185 using std::ws;
186 using orgQhull::Coordinates;
187 
188 ostream &
189 operator<<(ostream &os, const Coordinates &cs)
190 {
191  Coordinates::const_iterator c= cs.begin();
192  for(countT i=cs.count(); i--; ){
193  os << *c++ << " ";
194  }
195  return os;
196 }//operator<<
197 
ostream & operator<<(ostream &os, const Coordinates &cs)
Index count
Coordinate operator+(const Coordinate &LHS, const Coordinate &RHS)
Definition: Coordinate.hh:290
void swap(ConfigDoF &A, ConfigDoF &B)
Definition: ConfigDoF.cc:260
bool contains(const Container &container, const T &value)
Equivalent to container.end() != std::find(container.begin(), container.end(), value)
Definition: algorithm.hh:83
double length(const Eigen::MatrixBase< Derived > &value)
std::unique_ptr< T > clone(const T &obj)
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:20