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


hpp-fcl
Author(s):
autogenerated on Fri Aug 2 2024 02:45:13