Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
ChasteEllipsoid.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, 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
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF 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
39template <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
57template <>
58bool 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}
79template <>
80bool 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}
103template <>
104bool 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}
124template <unsigned SPACE_DIM>
126{
127 return mCentre;
128}
129
130template <unsigned SPACE_DIM>
132{
133 return mRadii;
134}
135
136
138
139template class ChasteEllipsoid<1>;
140template class ChasteEllipsoid<2>;
141template class ChasteEllipsoid<3>;
142
143// Serialization for Boost >= 1.36
#define EXCEPTION(message)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
ChastePoint< SPACE_DIM > mRadii
ChasteEllipsoid(ChastePoint< SPACE_DIM > &rCentre, ChastePoint< SPACE_DIM > &rRadii)
const ChastePoint< SPACE_DIM > & rGetCentre() const
bool DoesContain(const ChastePoint< SPACE_DIM > &rPointToCheck) const
const ChastePoint< SPACE_DIM > & rGetRadii() const