defaultepsilon.hh 4.67 KB
Newer Older
Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
1
2
3
4
5
6
7
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*****************************************************************************
 *   See the file COPYING for full copying permissions.                      *
 *                                                                           *
 *   This program is free software: you can redistribute it and/or modify    *
 *   it under the terms of the GNU General Public License as published by    *
Dennis Gläser's avatar
Dennis Gläser committed
8
 *   the Free Software Foundation, either version 3 of the License, or       *
Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
9
10
11
12
13
14
15
16
17
18
19
20
 *   (at your option) any later version.                                     *
 *                                                                           *
 *   This program is distributed in the hope that it will be useful,         *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
 *****************************************************************************/
/*!
 * \file
21
 * \ingroup Precision
Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
22
23
24
25
26
27
28
29
30
31
 * \brief Defines epsilons to be used for floating point
 *        arithmetic on geometries, e.g. to determine if
 *        a point lies on a geometry or for computing the
 *        intersection of two geometries. The values for
 *        the epsilons are computed based on the magnitude
 *        of the provided geometry.
 */
#ifndef FRACKIT_DEFAULT_EPSILON_HH
#define FRACKIT_DEFAULT_EPSILON_HH

32
#include <cmath>
33
34
35
#include <TopoDS_Shape.hxx>

#include <frackit/occ/breputilities.hh>
Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
36
37
38
39
#include <frackit/geometry/segment.hh>
#include <frackit/geometry/circle.hh>
#include <frackit/geometry/ellipse.hh>
#include <frackit/geometry/disk.hh>
40
#include <frackit/geometry/quadrilateral.hh>
Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
41
#include <frackit/geometry/cylindersurface.hh>
42
#include <frackit/geometry/box.hh>
43

Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
44
45
46
47
48
#include "precision.hh"

namespace Frackit {

/*!
49
 * \ingroup Precision
Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
50
51
52
53
54
55
56
57
58
 * \brief Default epsilon for geometries.
 *        We use the base epsilon here and provide
 *        overloads for geometries having a magnitude.
 */
template<class Geometry>
typename Geometry::ctype defaultEpsilon(const Geometry& geom)
{ return Precision<typename Geometry::ctype>::confusion(); }

/*!
59
 * \ingroup Precision
Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
60
61
62
63
 * \brief Default epsilon for operations on segments.
 */
template<class ctype, int worldDim>
ctype defaultEpsilon(const Segment<ctype, worldDim>& seg)
64
{ return Precision<ctype>::confusion()*seg.length(); }
Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
65
66

/*!
67
 * \ingroup Precision
Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
68
69
70
71
72
73
74
 * \brief Default epsilon for operations on circles.
 */
template<class ctype, int worldDim>
ctype defaultEpsilon(const Circle<ctype, worldDim>& circle)
{ return Precision<ctype>::confusion()*circle.radius(); }

/*!
75
 * \ingroup Precision
Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
76
77
78
79
80
81
82
83
84
85
 * \brief Default epsilon for operations on ellipses.
 */
template<class ctype, int worldDim>
ctype defaultEpsilon(const Ellipse<ctype, worldDim>& ellipse)
{
    return Precision<ctype>::confusion()
           *0.5*(ellipse.majorAxisLength() + ellipse.minorAxisLength());
}

/*!
86
 * \ingroup Precision
Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
87
88
89
90
91
92
 * \brief Default epsilon for operations on disks.
 */
template<class ctype>
ctype defaultEpsilon(const Disk<ctype>& disk)
{ return defaultEpsilon(disk.boundingEllipse()); }

93
/*!
94
 * \ingroup Precision
95
96
97
98
99
100
101
102
103
 * \brief Default epsilon for operations on quadrilaterals.
 */
template<class ctype>
ctype defaultEpsilon(const Quadrilateral<ctype, 3>& quad)
{
    using std::sqrt;
    return 0.5*sqrt(quad.area())*Precision<ctype>::confusion();
}

Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
104
/*!
105
 * \ingroup Precision
Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
106
107
108
109
110
111
112
113
114
 * \brief Default epsilon for operations on cylinder surfaces.
 */
template<class ctype>
ctype defaultEpsilon(const CylinderSurface<ctype>& cylSurface)
{
    return Precision<ctype>::confusion()
           *0.5*(cylSurface.radius() + cylSurface.height());
}

115
/*!
116
 * \ingroup Precision
117
118
119
120
121
122
123
124
125
 * \brief Default epsilon for operations on boxes.
 */
template<class ctype>
ctype defaultEpsilon(const Box<ctype>& box)
{
    const Segment<ctype, 3> diagSegment(box.corner(0), box.corner(7));
    return Precision<ctype>::confusion()*diagSegment.length();
}

126
/*!
127
 * \ingroup Precision
128
129
130
131
132
133
134
135
136
137
 * \brief Default epsilon for operations on shapes.
 */
template<class ctype = double>
ctype defaultEpsilon(const TopoDS_Shape& shape)
{
    const auto bbox = OCCUtilities::getBoundingBox(shape);
    const auto diagonalSeg = Segment<ctype, 3>(bbox.corner(0), bbox.corner(7));
    return diagonalSeg.length()*Precision<ctype>::confusion();
}

Dennis Gläser's avatar
cleanup  
Dennis Gläser committed
138
139
140
} // end namespace Frackit

#endif // FRACKIT_DEFAULT_EPSILON_HH