ChasteEllipsoid.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #include "ChasteEllipsoid.hpp"
00030 #include "Exception.hpp"
00031 
00032 template <unsigned SPACE_DIM>
00033 ChasteEllipsoid<SPACE_DIM>::ChasteEllipsoid(ChastePoint<SPACE_DIM>& rCentre, ChastePoint<SPACE_DIM>& rRadii)
00034     : mCentre(rCentre),
00035       mRadii(rRadii)
00036 {
00037     for (unsigned dim=0; dim<SPACE_DIM; dim++)
00038     {
00039         if (mRadii[dim] < 0.0)
00040         {
00041             EXCEPTION("Attempted to create an ellipsoid with a negative radius");
00042         }
00043     }
00044 }
00045 
00050 template <>
00051 bool ChasteEllipsoid<1>::DoesContain(const ChastePoint<1>& rPointToCheck) const
00052 {
00053     if (rPointToCheck[0] < mCentre[0] - mRadii[0] - 100.0 * DBL_EPSILON ||
00054         rPointToCheck[0] > mCentre[0] + mRadii[0] + 100.0 * DBL_EPSILON )
00055     {
00056         return false;
00057     }
00058     else
00059     {
00060         return true;
00061     }
00062 }
00072 template <>
00073 bool ChasteEllipsoid<2>::DoesContain(const ChastePoint<2>& rPointToCheck) const
00074 {
00075     double x_distance = (rPointToCheck[0]-mCentre[0])/mRadii[0];
00076     double y_distance = (rPointToCheck[1]-mCentre[1])/mRadii[1];
00077 
00078     if ( (x_distance*x_distance + y_distance*y_distance) > (1.0 + 100.0 * DBL_EPSILON) )
00079     {
00080         return false;
00081     }
00082     else
00083     {
00084         return true;
00085     }
00086 }
00096 template <>
00097 bool ChasteEllipsoid<3>::DoesContain(const ChastePoint<3>& rPointToCheck) const
00098 {
00099     double x_distance = (rPointToCheck[0]-mCentre[0])/mRadii[0];
00100     double y_distance = (rPointToCheck[1]-mCentre[1])/mRadii[1];
00101     double z_distance = (rPointToCheck[2]-mCentre[2])/mRadii[2];
00102 
00103     if ( (x_distance*x_distance + y_distance*y_distance + z_distance*z_distance) > (1.0 + 100.0 * DBL_EPSILON) )
00104     {
00105         return false;
00106     }
00107     else
00108     {
00109         return true;
00110     }
00111 }
00117 template <unsigned SPACE_DIM>
00118 const ChastePoint<SPACE_DIM>& ChasteEllipsoid<SPACE_DIM>::rGetCentre() const
00119 {
00120     return mCentre;
00121 }
00122 
00123 template <unsigned SPACE_DIM>
00124 const ChastePoint<SPACE_DIM>& ChasteEllipsoid<SPACE_DIM>::rGetRadii() const
00125 {
00126     return mRadii;
00127 }
00128 
00129 
00131 // Explicit instantiation
00133 
00134 template class ChasteEllipsoid<1>;
00135 template class ChasteEllipsoid<2>;
00136 template class ChasteEllipsoid<3>;
00137 
00138 // Serialization for Boost >= 1.36
00139 #include "SerializationExportWrapperForCpp.hpp"
00140 EXPORT_TEMPLATE_CLASS_SAME_DIMS(ChasteEllipsoid)
Generated on Thu Dec 22 13:00:16 2011 for Chaste by  doxygen 1.6.3