Chaste  Release::3.4
ChasteEllipsoid.cpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #include "ChasteEllipsoid.hpp"
37 #include "Exception.hpp"
38 
39 template <unsigned SPACE_DIM>
41  : mCentre(rCentre),
42  mRadii(rRadii)
43 {
44  for (unsigned dim=0; dim<SPACE_DIM; dim++)
45  {
46  if (mRadii[dim] < 0.0)
47  {
48  EXCEPTION("Attempted to create an ellipsoid with a negative radius");
49  }
50  }
51 }
52 
57 template <>
58 bool ChasteEllipsoid<1>::DoesContain(const ChastePoint<1>& rPointToCheck) const
59 {
60  if (rPointToCheck[0] < mCentre[0] - mRadii[0] - 100.0 * DBL_EPSILON ||
61  rPointToCheck[0] > mCentre[0] + mRadii[0] + 100.0 * DBL_EPSILON )
62  {
63  return false;
64  }
65  else
66  {
67  return true;
68  }
69 }
79 template <>
80 bool ChasteEllipsoid<2>::DoesContain(const ChastePoint<2>& rPointToCheck) const
81 {
82  double x_distance = (rPointToCheck[0]-mCentre[0])/mRadii[0];
83  double y_distance = (rPointToCheck[1]-mCentre[1])/mRadii[1];
84 
85  if ( (x_distance*x_distance + y_distance*y_distance) > (1.0 + 100.0 * DBL_EPSILON) )
86  {
87  return false;
88  }
89  else
90  {
91  return true;
92  }
93 }
103 template <>
104 bool ChasteEllipsoid<3>::DoesContain(const ChastePoint<3>& rPointToCheck) const
105 {
106  double x_distance = (rPointToCheck[0]-mCentre[0])/mRadii[0];
107  double y_distance = (rPointToCheck[1]-mCentre[1])/mRadii[1];
108  double z_distance = (rPointToCheck[2]-mCentre[2])/mRadii[2];
109 
110  if ( (x_distance*x_distance + y_distance*y_distance + z_distance*z_distance) > (1.0 + 100.0 * DBL_EPSILON) )
111  {
112  return false;
113  }
114  else
115  {
116  return true;
117  }
118 }
124 template <unsigned SPACE_DIM>
126 {
127  return mCentre;
128 }
129 
130 template <unsigned SPACE_DIM>
132 {
133  return mRadii;
134 }
135 
136 
138 // Explicit instantiation
140 
141 template class ChasteEllipsoid<1>;
142 template class ChasteEllipsoid<2>;
143 template class ChasteEllipsoid<3>;
144 
145 // Serialization for Boost >= 1.36
#define EXCEPTION(message)
Definition: Exception.hpp:143
bool DoesContain(const ChastePoint< SPACE_DIM > &rPointToCheck) const
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
const ChastePoint< SPACE_DIM > & rGetRadii() const
ChastePoint< SPACE_DIM > mRadii
ChasteEllipsoid(ChastePoint< SPACE_DIM > &rCentre, ChastePoint< SPACE_DIM > &rRadii)
const ChastePoint< SPACE_DIM > & rGetCentre() const