31 #include "quaternion.h"
32 #include "MersenneTwister.h"
40 std::string _IOWrapper::ToStringImpl(
const _IOWrapper::BaseWrite& b,
41 std::streamsize precision)
43 std::ostringstream ost;
45 ost.precision(precision);
51 void _IOWrapper::FromStringImpl(_IOWrapper::BaseRead& b,
52 const std::string& s, std::streamsize precision)
54 std::istringstream ist(s);
56 ist.precision(precision);
70 std::istream& operator>>(std::istream& is,
Polygon<dim>& r)
74 std::list<PolyReader<dim> > read_list;
90 read_list.push_back(read);
103 typename std::list<PolyReader<dim> >::iterator i, end = read_list.end();
106 std::streamsize str_prec = is.precision();
108 while(--str_prec > 0)
112 r.m_orient = Poly2Orient<dim>();
114 if(read_list.size() < 3) {
115 for(i = read_list.begin(); i != end; ++i) {
116 succ = r.m_orient.expand(i->pd, i->p2, epsilon);
121 typename std::list<PolyReader<dim> >::iterator p1 = end, p2 = end, p3 = end, j;
124 for(i = read_list.begin(); i != end; ++i) {
125 for(j = i, ++j; j != end; ++j) {
126 CoordType new_dist = SloppyDistance(i->pd, j->pd);
127 if(new_dist > dist) {
140 for(i = read_list.begin(); i != end; ++i) {
142 if(i == p1 || i == p2)
144 CoordType new_dist = FloatMin(SloppyDistance(i->pd, p1->pd),
145 SloppyDistance(i->pd, p2->pd));
146 if(new_dist > dist) {
156 succ = r.m_orient.expand(p1->pd, p1->p2, epsilon);
158 succ = r.m_orient.expand(p2->pd, p2->p2, epsilon);
160 succ = r.m_orient.expand(p3->pd, p3->p2, epsilon);
165 for(i = read_list.begin(); i != end; ++i) {
166 if(i == p1 || i == p2 || i == p3)
168 succ = r.m_orient.expand(i->pd, i->p2, epsilon);
178 r.m_poly.resize(read_list.size());
181 for(i = read_list.begin(), pnum = 0; i != end; ++i, ++pnum)
182 r.m_poly[pnum] = i->p2;
188 inline std::ostream& operator<<(std::ostream& os,
const Polygon<dim>& r)
190 size_t size = r.m_poly.numCorners();
199 for(
size_t i = 0; i < size; ++i)
200 os << r.getCorner(i) << (i < (dim - 1) ?
',' :
')');
208 template std::ostream& operator<< <3>(std::ostream& os,
const Vector<3>& r);
209 template std::istream&
operator>> <3>(std::istream& is, Vector<3>& r);
210 template std::ostream& operator<< <2>(std::ostream& os,
const Vector<2>& r);
211 template std::istream&
operator>> <2>(std::istream& is, Vector<2>& r);
212 template std::ostream& operator<< <3>(std::ostream& os,
const Point<3>& r);
213 template std::istream&
operator>> <3>(std::istream& is, Point<3>& r);
214 template std::ostream& operator<< <2>(std::ostream& os,
const Point<2>& r);
215 template std::istream&
operator>> <2>(std::istream& is, Point<2>& r);
216 template std::ostream& operator<< <3>(std::ostream& os,
const RotMatrix<3>& r);
217 template std::istream&
operator>> <3>(std::istream& is, RotMatrix<3>& r);
218 template std::ostream& operator<< <2>(std::ostream& os,
const RotMatrix<2>& r);
219 template std::istream&
operator>> <2>(std::istream& is, RotMatrix<2>& r);
220 template std::ostream& operator<< <3>(std::ostream& os,
const AxisBox<3>& r);
221 template std::istream&
operator>> <3>(std::istream& is, AxisBox<3>& r);
222 template std::ostream& operator<< <2>(std::ostream& os,
const AxisBox<2>& r);
223 template std::istream&
operator>> <2>(std::istream& is, AxisBox<2>& r);
224 template std::ostream& operator<< <3>(std::ostream& os,
const Ball<3>& r);
225 template std::istream&
operator>> <3>(std::istream& is, Ball<3>& r);
226 template std::ostream& operator<< <2>(std::ostream& os,
const Ball<2>& r);
227 template std::istream&
operator>> <2>(std::istream& is, Ball<2>& r);
228 template std::ostream& operator<< <3>(std::ostream& os,
const Segment<3>& r);
229 template std::istream&
operator>> <3>(std::istream& is, Segment<3>& r);
230 template std::ostream& operator<< <2>(std::ostream& os,
const Segment<2>& r);
231 template std::istream&
operator>> <2>(std::istream& is, Segment<2>& r);
232 template std::ostream& operator<< <3>(std::ostream& os,
const RotBox<3>& r);
233 template std::istream&
operator>> <3>(std::istream& is, RotBox<3>& r);
234 template std::ostream& operator<< <2>(std::ostream& os,
const RotBox<2>& r);
235 template std::istream&
operator>> <2>(std::istream& is, RotBox<2>& r);
237 template std::ostream& operator<< <3>(std::ostream& os,
const Polygon<3>& r);
238 template std::istream&
operator>> <3>(std::istream& is, Polygon<3>& r);
240 void WriteCoordList(std::ostream& os,
const CoordType* d,
const int num)
244 for(
int i = 0; i < num; ++i)
245 os << d[i] << (i < (num - 1) ?
',' :
')');
248 void ReadCoordList(std::istream& is,
CoordType* d,
const int num)
257 for(
int i = 0; i < num; ++i) {
259 char want = (i == num - 1) ?
')' :
',';
267 std::streamsize str_prec = is.precision();
269 while(--str_prec > 0)
280 std::ostream& operator<<(std::ostream& os,
const Polygon<2>& r)
282 size_t size = r.m_points.size();
291 for(
size_t i = 0; i < size; ++i) {
292 os << r.m_points[i] << (i < (size - 1) ?
',' :
')');
299 std::istream& operator>>(std::istream& is, Polygon<2>& r)
311 }
while(next !=
'>');
314 }
while(next !=
'(');
318 r.m_points.push_back(p);
327 std::ostream& operator<<(std::ostream& os,
const Quaternion& q)
329 return os <<
"Quaternion: (" << q.m_w <<
',' << q.m_vec <<
')';
332 std::istream& operator>>(std::istream& is, Quaternion& q)
338 }
while(next !=
'(');
348 CoordType norm = q.m_w * q.m_w + q.m_vec.sqrMag();
350 norm = std::sqrt(norm);
362 std::ostream& operator<<(std::ostream& os, MTRand
const& mtrand)
364 return mtrand.save(os);
368 std::istream& operator>>(std::istream& is, MTRand& mtrand)
370 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.