CASM  1.1.0
A Clusters Approach to Statistical Mechanics
QhullPoint.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/QhullPoint.cpp#1 $$Change: 1981 $
5 ** $DateTime: 2015/09/28 20:26:32 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 #include "QhullPoint.h"
10 #include "QhullError.h"
11 #include "Qhull.h"
12 
13 #include <iostream>
14 #include <algorithm>
15 
16 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4
17 #endif
18 
19 namespace orgQhull {
20 
21 #
22 
23 
24 QhullPoint::
25 QhullPoint(const Qhull &q)
26 : point_coordinates(0)
27 , qh_qh(q.qh())
28 , point_dimension(q.hullDimension())
29 {
30 }//QhullPoint
31 
32 QhullPoint::
33 QhullPoint(const Qhull &q, coordT *c)
34 : point_coordinates(c)
35 , qh_qh(q.qh())
36 , point_dimension(q.hullDimension())
37 {
38  QHULL_ASSERT(q.hullDimension()>0);
39 }//QhullPoint dim, coordT
40 
41 QhullPoint::
42 QhullPoint(const Qhull &q, int pointDimension, coordT *c)
43 : point_coordinates(c)
44 , qh_qh(q.qh())
45 , point_dimension(pointDimension)
46 {
47 }//QhullPoint dim, coordT
48 
50 QhullPoint::
51 QhullPoint(const Qhull &q, Coordinates &c)
52 : point_coordinates(c.data())
53 , qh_qh(q.qh())
54 , point_dimension(c.count())
55 {
56 }//QhullPoint Coordinates
57 
58 #
59 
60 // See qt-qhull.cpp for QList conversion
61 
62 #ifndef QHULL_NO_STL
63 std::vector<coordT> QhullPoint::
64 toStdVector() const
65 {
66  QhullPointIterator i(*this);
67  std::vector<coordT> vs;
68  while(i.hasNext()){
69  vs.push_back(i.next());
70  }
71  return vs;
72 }//toStdVector
73 #endif //QHULL_NO_STL
74 
75 #
76 
81 bool QhullPoint::
82 operator==(const QhullPoint &other) const
83 {
84  if(point_dimension!=other.point_dimension){
85  return false;
86  }
87  const coordT *c= point_coordinates;
88  const coordT *c2= other.point_coordinates;
89  if(c==c2){
90  return true;
91  }
92  if(!c || !c2){
93  return false;
94  }
95  if(!qh_qh || qh_qh->hull_dim==0){
96  for(int k= point_dimension; k--; ){
97  if(*c++ != *c2++){
98  return false;
99  }
100  }
101  return true;
102  }
103  double dist2= 0.0;
104  for(int k= point_dimension; k--; ){
105  double diff= *c++ - *c2++;
106  dist2 += diff*diff;
107  }
108  dist2= sqrt(dist2);
109  return (dist2 < qh_qh->distanceEpsilon());
110 }//operator==
111 
112 #
113 
115 double QhullPoint::
116 distance(const QhullPoint &p) const
117 {
118  const coordT *c= point_coordinates;
119  const coordT *c2= p.point_coordinates;
120  int dim= point_dimension;
121  if(dim!=p.point_dimension){
122  throw QhullError(10075, "QhullPoint error: Expecting dimension %d for distance(). Got %d", dim, p.point_dimension);
123  }
124  if(!c || !c2){
125  throw QhullError(10076, "QhullPoint error: Cannot compute distance() for undefined point");
126  }
127  double dist;
128 
129  switch(dim){
130  case 2:
131  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]);
132  break;
133  case 3:
134  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]);
135  break;
136  case 4:
137  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]);
138  break;
139  case 5:
140  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]) + (c[4]-c2[4])*(c[4]-c2[4]);
141  break;
142  case 6:
143  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]) + (c[4]-c2[4])*(c[4]-c2[4]) + (c[5]-c2[5])*(c[5]-c2[5]);
144  break;
145  case 7:
146  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]) + (c[4]-c2[4])*(c[4]-c2[4]) + (c[5]-c2[5])*(c[5]-c2[5]) + (c[6]-c2[6])*(c[6]-c2[6]);
147  break;
148  case 8:
149  dist= (c[0]-c2[0])*(c[0]-c2[0]) + (c[1]-c2[1])*(c[1]-c2[1]) + (c[2]-c2[2])*(c[2]-c2[2]) + (c[3]-c2[3])*(c[3]-c2[3]) + (c[4]-c2[4])*(c[4]-c2[4]) + (c[5]-c2[5])*(c[5]-c2[5]) + (c[6]-c2[6])*(c[6]-c2[6]) + (c[7]-c2[7])*(c[7]-c2[7]);
150  break;
151  default:
152  dist= 0.0;
153  for(int k=dim; k--; ){
154  dist += (*c - *c2) * (*c - *c2);
155  ++c;
156  ++c2;
157  }
158  break;
159  }
160  return sqrt(dist);
161 }//distance
162 
163 }//namespace orgQhull
164 
165 #
166 
167 using std::ostream;
168 using orgQhull::QhullPoint;
169 
171 ostream &
172 operator<<(ostream &os, const QhullPoint::PrintPoint &pr)
173 {
174  QhullPoint p= *pr.point;
175  countT i= p.id();
176  if(pr.point_message){
177  if(*pr.point_message){
178  os << pr.point_message << " ";
179  }
180  if(pr.with_identifier && (i!=qh_IDunknown) && (i!=qh_IDnone)){
181  os << "p" << i << ": ";
182  }
183  }
184  const realT *c= p.coordinates();
185  for(int k=p.dimension(); k--; ){
186  realT r= *c++;
187  if(pr.point_message){
188  os << " " << r; // FIXUP QH11010 %8.4g
189  }else{
190  os << " " << r; // FIXUP QH11010 qh_REAL_1
191  }
192  }
193  os << std::endl;
194  return os;
195 }//printPoint
196 
197 ostream &
198 operator<<(ostream &os, const QhullPoint &p)
199 {
200  os << p.print("");
201  return os;
202 }//operator<<
Index count
ostream & operator<<(ostream &os, const QhullPoint::PrintPoint &pr)
Same as qh_printpointid [io.c].
Definition: QhullPoint.cpp:172
bool operator==(DoFSet const &A, DoFSet const &B)
Definition: DoFSet.hh:314
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:20