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 
87 {
88  coordT c= at(idx);
89  erase(begin()+idx);
90  return c;
91 }//takeAt
92 
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 {
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 
iterator erase(iterator idx)
Definition: Coordinates.h:111
QhullRidge – Qhull&#39;s ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
bool findNext(const coordT &t)
Definition: Coordinates.h:281
coordT & at(countT idx)
Definition: Coordinates.h:81
countT count() const
Definition: Coordinates.h:72
countT lastIndexOf(const coordT &t, countT from=-1) const
c
const_iterator constBegin() const
Definition: Coordinates.h:99
#define coordT
Definition: libqhull.h:80
bool findNext(const coordT &t)
Definition: Coordinates.h:251
Coordinates & operator+=(const Coordinates &other)
Definition: Coordinates.cpp:61
coordT value(countT idx, const coordT &defaultValue) const
Definition: Coordinates.cpp:45
void swap(countT idx, countT other)
Coordinates & operator<<(const Coordinates &other)
Definition: Coordinates.h:118
void removeAll(const coordT &t)
const_iterator constEnd() const
Definition: Coordinates.h:100
bool contains(const coordT &t) const
countT indexOf(const coordT &t, countT from=0) const
coordT takeAt(countT idx)
Definition: Coordinates.cpp:86
Coordinates operator+(const Coordinates &other) const
Definition: Coordinates.cpp:53
std::vector< coordT > coordinate_array
Definition: Coordinates.h:36
int countT
Definition: user_r.h:182
void append(int pointDimension, coordT *c)
Definition: Coordinates.cpp:75
Coordinates mid(countT idx, countT length=-1) const
Definition: Coordinates.cpp:31


hpp-fcl
Author(s):
autogenerated on Fri Jun 2 2023 02:39:00