39 #include <boost/serialization/vector.hpp>
40 #include <boost/serialization/base_object.hpp>
41 #include <boost/filesystem/path.hpp>
54 typedef std::size_t
sz;
55 typedef std::pair<fl, fl>
pr;
126 template<
class Archive>
133 return vec(s * v[0], s * v[1], s * v[2]);
137 return vec(a[1]*b[2] - a[2]*b[1],
138 a[2]*b[0] - a[0]*b[2],
139 a[0]*b[1] - a[1]*b[0]);
143 return vec(a[0] * b[0],
158 const fl&
operator()(sz i, sz j)
const { assert(i < 3); assert(j < 3);
return data[i + 3*j]; }
183 typedef std::pair<vec, vec>
vecp;
184 typedef std::vector<fl>
flv;
185 typedef std::vector<pr>
prv;
186 typedef std::vector<sz>
szv;
196 #define VINA_CHECK(P) do { if(!(P)) throw internal_error(__FILE__, __LINE__); } while(false)
198 #define VINA_CHECK(P) assert(P)
205 if(x >= max_sz)
return max_sz;
206 sz tmp =
static_cast<sz
>(x);
207 return (std::min)(tmp,
max_sz);
223 return eq(a[0], b[0]) &&
eq(a[1], b[1]) &&
eq(a[2], b[2]);
227 bool eq(
const std::vector<T>& a,
const std::vector<T>& b) {
228 if(a.size() != b.size())
return false;
235 const fl max_fl = (std::numeric_limits<fl>::max)();
236 const sz
max_sz = (std::numeric_limits<sz>::max)();
244 return (x < 0.1 * max_fl);
248 return sqr(a[0] - b[0]) + \
254 return sqr(v[0]) +
sqr(v[1]) +
sqr(v[2]);
259 sz old_size = x.size();
260 x.insert(x.end(), y.begin(), y.end());
268 if(i == 0 || v[i] < v[tmp])
275 fl n = ( x -
pi) / (2*pi);
276 x -= 2*pi*std::ceil(n);
280 fl n = (-x -
pi) / (2*pi);
281 x += 2*pi*std::ceil(n);
290 assert(x >= -pi && x <= pi);
300 std::string
to_string(
const T& x, std::streamsize width = 0,
char fill =
' ') {
301 std::ostringstream out;
304 out << std::setw(width);
310 T
sum(
const std::vector<T>& v) {
325 inline void print(
fl x, std::ostream& out = std::cout) {
329 inline void print(sz x, std::ostream& out = std::cout) {
333 inline void print(
const vec& v, std::ostream& out = std::cout) {
344 void print(
const std::vector<T>& v, std::ostream& out = std::cout) {
355 void printnl(
const T& x, std::ostream& out = std::cout) {
360 inline bool starts_with(
const std::string& str,
const std::string& start) {
361 return str.size() >= start.size() && str.substr(0, start.size()) == start;
365 bool has(
const std::vector<T>& v,
const T& element) {
366 return std::find(v.begin(), v.end(), element) != v.end();