faunus
periodic_box.h
1 #ifndef VORONOTALT_PERIODIC_BOX_H_
2 #define VORONOTALT_PERIODIC_BOX_H_
3 
4 #include <vector>
5 
6 #include "basic_types_and_functions.h"
7 
8 namespace voronotalt
9 {
10 
12 {
13 public:
14  PeriodicBox() noexcept : enabled_(false)
15  {
16  }
17 
18  bool enabled() const noexcept
19  {
20  return enabled_;
21  }
22 
23  bool equals(const PeriodicBox& pb) const noexcept
24  {
25  return (enabled_==pb.enabled_ && point_equals_point(shift_direction_a_, pb.shift_direction_a_) && point_equals_point(shift_direction_b_, pb.shift_direction_b_) && point_equals_point(shift_direction_c_, pb.shift_direction_c_));
26  }
27 
28  const SimpleSphere shift_by_weighted_directions(const SimpleSphere& o, const Float wa, const Float wb, const Float wc) const
29  {
30  return SimpleSphere(
31  o.p.x+shift_direction_a_.x*wa+shift_direction_b_.x*wb+shift_direction_c_.x*wc,
32  o.p.y+shift_direction_a_.y*wa+shift_direction_b_.y*wb+shift_direction_c_.y*wc,
33  o.p.z+shift_direction_a_.z*wa+shift_direction_b_.z*wb+shift_direction_c_.z*wc,
34  o.r);
35  }
36 
37  static PeriodicBox create_periodic_box_from_corners(const std::vector<SimplePoint>& periodic_box_corners) noexcept
38  {
39  PeriodicBox pb;
40  if(periodic_box_corners.size()>=2)
41  {
42  pb.enabled_=true;
43  SimplePoint corner_min=periodic_box_corners[0];
44  SimplePoint corner_max=periodic_box_corners[0];
45  for(UnsignedInt i=1;i<periodic_box_corners.size();i++)
46  {
47  const SimplePoint& corner=periodic_box_corners[i];
48  corner_min.x=std::min(corner_min.x, corner.x);
49  corner_min.y=std::min(corner_min.y, corner.y);
50  corner_min.z=std::min(corner_min.z, corner.z);
51  corner_max.x=std::max(corner_max.x, corner.x);
52  corner_max.y=std::max(corner_max.y, corner.y);
53  corner_max.z=std::max(corner_max.z, corner.z);
54  }
55  pb.shift_direction_a_.x=corner_max.x-corner_min.x;
56  pb.shift_direction_b_.y=corner_max.y-corner_min.y;
57  pb.shift_direction_c_.z=corner_max.z-corner_min.z;
58  }
59  return pb;
60  }
61 
62  static PeriodicBox create_periodic_box_from_shift_directions(const std::vector<SimplePoint>& shift_directions) noexcept
63  {
64  PeriodicBox pb;
65  if(shift_directions.size()==3)
66  {
67  pb.enabled_=true;
68  pb.shift_direction_a_=shift_directions[0];
69  pb.shift_direction_b_=shift_directions[1];
70  pb.shift_direction_c_=shift_directions[2];
71  }
72  return pb;
73  }
74 
75  static PeriodicBox create_periodic_box_from_shift_directions_or_from_corners(const std::vector<SimplePoint>& shift_directions, const std::vector<SimplePoint>& periodic_box_corners) noexcept
76  {
77  PeriodicBox pb=create_periodic_box_from_shift_directions(shift_directions);
78  if(!pb.enabled())
79  {
80  pb=create_periodic_box_from_corners(periodic_box_corners);
81  }
82  return pb;
83  }
84 
85 private:
86  bool enabled_;
87  SimplePoint shift_direction_a_;
88  SimplePoint shift_direction_b_;
89  SimplePoint shift_direction_c_;
90 };
91 
92 }
93 
94 #endif /* VORONOTALT_PERIODIC_BOX_H_ */
Definition: basic_types_and_functions.h:34
Definition: periodic_box.h:11
Definition: basic_types_and_functions.h:19
Definition: basic_types_and_functions.h:49