31 #include "quaternion.h"
32 #include "MersenneTwister.h"
38 std::string _IOWrapper::ToStringImpl(
const _IOWrapper::BaseWrite& b,
39 std::streamsize precision)
41 std::ostringstream ost;
43 ost.precision(precision);
49 void _IOWrapper::FromStringImpl(_IOWrapper::BaseRead& b,
50 const std::string& s, std::streamsize precision)
52 std::istringstream ist(s);
54 ist.precision(precision);
68 std::istream& operator>>(std::istream& is,
Polygon<dim>& r)
72 std::list<PolyReader<dim> > read_list;
88 read_list.push_back(read);
101 typename std::list<PolyReader<dim> >::iterator i, end = read_list.end();
104 std::streamsize str_prec = is.precision();
106 while(--str_prec > 0)
110 r.m_orient = Poly2Orient<dim>();
112 if(read_list.size() < 3) {
113 for(i = read_list.begin(); i != end; ++i) {
114 succ = r.m_orient.expand(i->pd, i->p2, epsilon);
119 typename std::list<PolyReader<dim> >::iterator p1 = end, p2 = end, p3 = end, j;
122 for(i = read_list.begin(); i != end; ++i) {
123 for(j = i, ++j; j != end; ++j) {
124 CoordType new_dist = SloppyDistance(i->pd, j->pd);
125 if(new_dist > dist) {
138 for(i = read_list.begin(); i != end; ++i) {
140 if(i == p1 || i == p2)
142 CoordType new_dist = FloatMin(SloppyDistance(i->pd, p1->pd),
143 SloppyDistance(i->pd, p2->pd));
144 if(new_dist > dist) {
154 succ = r.m_orient.expand(p1->pd, p1->p2, epsilon);
156 succ = r.m_orient.expand(p2->pd, p2->p2, epsilon);
158 succ = r.m_orient.expand(p3->pd, p3->p2, epsilon);
163 for(i = read_list.begin(); i != end; ++i) {
164 if(i == p1 || i == p2 || i == p3)
166 succ = r.m_orient.expand(i->pd, i->p2, epsilon);
176 r.m_poly.resize(read_list.size());
179 for(i = read_list.begin(), pnum = 0; i != end; ++i, ++pnum)
180 r.m_poly[pnum] = i->p2;
186 inline std::ostream& operator<<(std::ostream& os,
const Polygon<dim>& r)
188 size_t size = r.m_poly.numCorners();
197 for(
size_t i = 0; i < size; ++i)
198 os << r.getCorner(i) << (i < (dim - 1) ?
',' :
')');
206 template std::ostream& operator<< <3>(std::ostream& os,
const Vector<3>& r);
207 template std::istream&
operator>> <3>(std::istream& is, Vector<3>& r);
208 template std::ostream& operator<< <2>(std::ostream& os,
const Vector<2>& r);
209 template std::istream&
operator>> <2>(std::istream& is, Vector<2>& r);
210 template std::ostream& operator<< <3>(std::ostream& os,
const Point<3>& r);
211 template std::istream&
operator>> <3>(std::istream& is, Point<3>& r);
212 template std::ostream& operator<< <2>(std::ostream& os,
const Point<2>& r);
213 template std::istream&
operator>> <2>(std::istream& is, Point<2>& r);
214 template std::ostream& operator<< <3>(std::ostream& os,
const RotMatrix<3>& r);
215 template std::istream&
operator>> <3>(std::istream& is, RotMatrix<3>& r);
216 template std::ostream& operator<< <2>(std::ostream& os,
const RotMatrix<2>& r);
217 template std::istream&
operator>> <2>(std::istream& is, RotMatrix<2>& r);
218 template std::ostream& operator<< <3>(std::ostream& os,
const AxisBox<3>& r);
219 template std::istream&
operator>> <3>(std::istream& is, AxisBox<3>& r);
220 template std::ostream& operator<< <2>(std::ostream& os,
const AxisBox<2>& r);
221 template std::istream&
operator>> <2>(std::istream& is, AxisBox<2>& r);
222 template std::ostream& operator<< <3>(std::ostream& os,
const Ball<3>& r);
223 template std::istream&
operator>> <3>(std::istream& is, Ball<3>& r);
224 template std::ostream& operator<< <2>(std::ostream& os,
const Ball<2>& r);
225 template std::istream&
operator>> <2>(std::istream& is, Ball<2>& r);
226 template std::ostream& operator<< <3>(std::ostream& os,
const Segment<3>& r);
227 template std::istream&
operator>> <3>(std::istream& is, Segment<3>& r);
228 template std::ostream& operator<< <2>(std::ostream& os,
const Segment<2>& r);
229 template std::istream&
operator>> <2>(std::istream& is, Segment<2>& r);
230 template std::ostream& operator<< <3>(std::ostream& os,
const RotBox<3>& r);
231 template std::istream&
operator>> <3>(std::istream& is, RotBox<3>& r);
232 template std::ostream& operator<< <2>(std::ostream& os,
const RotBox<2>& r);
233 template std::istream&
operator>> <2>(std::istream& is, RotBox<2>& r);
235 template std::ostream& operator<< <3>(std::ostream& os,
const Polygon<3>& r);
236 template std::istream&
operator>> <3>(std::istream& is, Polygon<3>& r);
238 void WriteCoordList(std::ostream& os,
const CoordType* d,
const int num)
242 for(
int i = 0; i < num; ++i)
243 os << d[i] << (i < (num - 1) ?
',' :
')');
246 void ReadCoordList(std::istream& is,
CoordType* d,
const int num)
255 for(
int i = 0; i < num; ++i) {
257 char want = (i == num - 1) ?
')' :
',';
265 std::streamsize str_prec = is.precision();
267 while(--str_prec > 0)
278 std::ostream& operator<<(std::ostream& os,
const Polygon<2>& r)
280 size_t size = r.m_points.size();
289 for(
size_t i = 0; i < size; ++i) {
290 os << r.m_points[i] << (i < (size - 1) ?
',' :
')');
297 std::istream& operator>>(std::istream& is, Polygon<2>& r)
309 }
while(next !=
'>');
312 }
while(next !=
'(');
316 r.m_points.push_back(p);
325 std::ostream& operator<<(std::ostream& os,
const Quaternion& q)
327 return os <<
"Quaternion: (" << q.m_w <<
',' << q.m_vec <<
')';
330 std::istream& operator>>(std::istream& is, Quaternion& q)
336 }
while(next !=
'(');
346 CoordType norm = q.m_w * q.m_w + q.m_vec.sqrMag();
348 norm = std::sqrt(norm);
360 std::ostream& operator<<(std::ostream& os, MTRand
const& mtrand)
362 return mtrand.save(os);
366 std::istream& operator>>(std::istream& is, MTRand& mtrand)
368 return mtrand.load(is);
A polygon, all of whose points lie in a plane, embedded in dim dimensions.
Generic library namespace.
double CoordType
Basic floating point type.
static FloatType epsilon()
This is the attempted precision of the library.