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/rotbox.h>
00030
00031 #include <wfmath/vector.h>
00032 #include <wfmath/point.h>
00033 #include <wfmath/axisbox.h>
00034 #include <wfmath/ball.h>
00035
00036 #include <cassert>
00037
00038 namespace WFMath {
00039
00040 template<int dim>
00041 inline Point<dim> RotBox<dim>::getCorner(size_t i) const
00042 {
00043 assert(i >= 0 && i < (1 << dim));
00044
00045 Vector<dim> dist;
00046
00047 if(i == 0)
00048 return m_corner0;
00049
00050 for(int j = 0; j < dim; ++j)
00051 dist[j] = (i & (1 << j)) ? m_size[j] : 0;
00052
00053 dist.setValid(m_size.isValid());
00054
00055 return m_corner0 + Prod(dist, m_orient);
00056 }
00057
00058 template<int dim>
00059 AxisBox<dim> RotBox<dim>::boundingBox() const
00060 {
00061 Point<dim> min = m_corner0, max = m_corner0;
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 for(int i = 0; i < dim; ++i) {
00082 for(int j = 0; j < dim; ++j) {
00083 CoordType value = m_orient.elem(j, i) * m_size[j];
00084 if(value < 0)
00085 min[i] += value;
00086 else
00087 max[i] += value;
00088 }
00089 }
00090
00091 bool valid = isValid();
00092
00093 min.setValid(valid);
00094 max.setValid(valid);
00095
00096 return AxisBox<dim>(min, max, true);
00097 }
00098
00099
00100
00101
00102 template<int dim>
00103 Point<dim> Point<dim>::toParentCoords(const RotBox<dim>& coords) const
00104 {
00105 return coords.corner0() + (*this - Point().setToOrigin()) * coords.orientation();
00106 }
00107
00108 template<int dim>
00109 Point<dim> Point<dim>::toLocalCoords(const RotBox<dim>& coords) const
00110 {
00111 return Point().setToOrigin() + coords.orientation() * (*this - coords.corner0());
00112 }
00113
00114 }
00115
00116 #endif // WFMATH_ROT_BOX_FUNCS_H