00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef WFMATH_ROT_BOX_FUNCS_H
00027 #define WFMATH_ROT_BOX_FUNCS_H
00028
00029 #include <wfmath/const.h>
00030 #include <wfmath/vector.h>
00031 #include <wfmath/point.h>
00032 #include <wfmath/axisbox.h>
00033 #include <wfmath/ball.h>
00034 #include <wfmath/rotbox.h>
00035
00036 namespace WFMath {
00037
00038 template<const int dim>
00039 inline RotBox<dim>& RotBox<dim>::operator=(const RotBox<dim>& a)
00040 {
00041 m_corner0 = a.m_corner0;
00042 m_size = a.m_size;
00043 m_orient = a.m_orient;
00044
00045 return *this;
00046 }
00047
00048 template<const int dim>
00049 inline bool RotBox<dim>::isEqualTo(const RotBox<dim>& b, double epsilon) const
00050 {
00051 return Equal(m_corner0, b.m_corner0, epsilon)
00052 && Equal(m_size, b.m_size, epsilon)
00053 && Equal(m_orient, b.m_orient, epsilon);
00054 }
00055
00056 template<const int dim>
00057 inline Point<dim> RotBox<dim>::getCorner(int i) const
00058 {
00059 assert(i >= 0 && i < (1 << dim));
00060
00061 Vector<dim> dist;
00062
00063 if(i == 0)
00064 return m_corner0;
00065
00066 for(int j = 0; j < dim; ++j)
00067 dist[j] = (i & (1 << j)) ? m_size[j] : 0;
00068
00069 dist.setValid(m_size.isValid());
00070
00071 return m_corner0 + Prod(dist, m_orient);
00072 }
00073
00074 template<const int dim>
00075 AxisBox<dim> RotBox<dim>::boundingBox() const
00076 {
00077 Point<dim> min = m_corner0, max = m_corner0;
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 for(int i = 0; i < dim; ++i) {
00098 for(int j = 0; j < dim; ++j) {
00099 CoordType value = m_orient.elem(j, i) * m_size[j];
00100 if(value < 0)
00101 min[i] += value;
00102 else
00103 max[i] += value;
00104 }
00105 }
00106
00107 bool valid = isValid();
00108
00109 min.setValid(valid);
00110 max.setValid(valid);
00111
00112 return AxisBox<dim>(min, max, true);
00113 }
00114
00115
00116
00117
00118 template<const int dim>
00119 Point<dim> Point<dim>::toParentCoords(const RotBox<dim>& coords) const
00120 {
00121 return coords.corner0() + (*this - Point().setToOrigin()) * coords.orientation();
00122 }
00123
00124 template<const int dim>
00125 Point<dim> Point<dim>::toLocalCoords(const RotBox<dim>& coords) const
00126 {
00127 return Point().setToOrigin() + coords.orientation() * (*this - coords.corner0());
00128 }
00129
00130 }
00131
00132 #endif // WFMATH_ROT_BOX_FUNCS_H