geometry/doc/doxygen_output/html/math_8hpp_source.html
Barend Gehrels 363580fbf6 Added old doxygen docs
[SVN r59777]
2010-02-20 15:57:12 +00:00

174 lines
13 KiB
HTML
Raw Blame History

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Boost.Geometry (aka GGL, Generic Geometry Library)</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head>
<table cellpadding="2" width="100%">
<tbody>
<tr>
<td valign="top">
<img alt="Boost.Geometry" src="images/ggl-logo-big.png" height="80" width="200">
&nbsp;&nbsp;
</td>
<td valign="top" align="right">
<a href="http://www.boost.org">
<img alt="Boost C++ Libraries" src="images/accepted_by_boost.png" height="80" width="230" border="0">
</a>
</td>
</tr>
</tbody>
</table>
<!-- Generated by Doxygen 1.5.9 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
<div class="tabs">
<ul>
<li><a href="files.html"><span>File&nbsp;List</span></a></li>
<li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
</ul>
</div>
<h1>boost/geometry/util/math.hpp</h1><a href="math_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Boost.Geometry (aka GGL, Generic Geometry Library)</span>
<a name="l00002"></a>00002 <span class="comment">//</span>
<a name="l00003"></a>00003 <span class="comment">// Copyright Barend Gehrels 2007-2009, Geodan, Amsterdam, the Netherlands.</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright Bruno Lalande 2008, 2009</span>
<a name="l00005"></a>00005 <span class="comment">// Use, modification and distribution is subject to the Boost Software License,</span>
<a name="l00006"></a>00006 <span class="comment">// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span>
<a name="l00007"></a>00007 <span class="comment">// http://www.boost.org/LICENSE_1_0.txt)</span>
<a name="l00008"></a>00008
<a name="l00009"></a>00009 <span class="preprocessor">#ifndef BOOST_GEOMETRY_UTIL_MATH_HPP</span>
<a name="l00010"></a>00010 <span class="preprocessor"></span><span class="preprocessor">#define BOOST_GEOMETRY_UTIL_MATH_HPP</span>
<a name="l00011"></a>00011 <span class="preprocessor"></span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;cmath&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;limits&gt;</span>
<a name="l00014"></a>00014
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;boost/math/constants/constants.hpp&gt;</span>
<a name="l00016"></a>00016
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;<a class="code" href="select__most__precise_8hpp.html">boost/geometry/util/select_most_precise.hpp</a>&gt;</span>
<a name="l00018"></a>00018
<a name="l00019"></a>00019 <span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>geometry
<a name="l00020"></a>00020 {
<a name="l00021"></a>00021
<a name="l00022"></a>00022
<a name="l00023"></a>00023 <span class="preprocessor">#ifndef DOXYGEN_NO_DETAIL</span>
<a name="l00024"></a>00024 <span class="preprocessor"></span><span class="keyword">namespace </span>detail { <span class="keyword">namespace </span>math {
<a name="l00025"></a>00025
<a name="l00026"></a>00026
<a name="l00027"></a>00027 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T, <span class="keywordtype">bool</span> Floating&gt;
<a name="l00028"></a>00028 <span class="keyword">struct </span><a class="code" href="group__equals.html#ge18e3cb2ad5b7fbc8f0ce9e0f92397bc" title="Detect if two geometries are spatially equal.">equals</a>
<a name="l00029"></a>00029 {
<a name="l00030"></a>00030 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> apply(T <span class="keyword">const</span>&amp; a, T <span class="keyword">const</span>&amp; b)
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032 <span class="keywordflow">return</span> a == b;
<a name="l00033"></a>00033 }
<a name="l00034"></a>00034 };
<a name="l00035"></a>00035
<a name="l00036"></a>00036 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00037"></a>00037 <span class="keyword">struct </span><a class="code" href="group__equals.html#ge18e3cb2ad5b7fbc8f0ce9e0f92397bc" title="Detect if two geometries are spatially equal.">equals</a>&lt;T, true&gt;
<a name="l00038"></a>00038 {
<a name="l00039"></a>00039 <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> apply(T <span class="keyword">const</span>&amp; a, T <span class="keyword">const</span>&amp; b)
<a name="l00040"></a>00040 {
<a name="l00041"></a>00041 <span class="comment">// See http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.17,</span>
<a name="l00042"></a>00042 <span class="comment">// FUTURE: replace by some boost tool or boost::test::close_at_tolerance</span>
<a name="l00043"></a>00043 <span class="keywordflow">return</span> std::abs(a - b) &lt;= std::numeric_limits&lt;T&gt;::epsilon() * std::abs(a);
<a name="l00044"></a>00044 }
<a name="l00045"></a>00045 };
<a name="l00046"></a>00046
<a name="l00047"></a>00047
<a name="l00048"></a>00048 }} <span class="comment">// namespace detail::math</span>
<a name="l00049"></a>00049 <span class="preprocessor">#endif</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span>
<a name="l00051"></a><a class="code" href="namespaceboost_1_1geometry_1_1math.html">00051</a> <span class="keyword">namespace </span>math
<a name="l00052"></a>00052 {
<a name="l00053"></a>00053
<a name="l00054"></a>00054
<a name="l00055"></a>00055 <span class="comment">// Maybe replace this by boost equals or boost ublas numeric equals or so</span>
<a name="l00056"></a>00056
<a name="l00070"></a>00070 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T1, <span class="keyword">typename</span> T2&gt;
<a name="l00071"></a><a class="code" href="group__utility.html#g8d2104edb28c2cecaa93e0a7e6308b77">00071</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="group__utility.html#g8d2104edb28c2cecaa93e0a7e6308b77" title="returns true if both arguments are equal.">equals</a>(T1 <span class="keyword">const</span>&amp; a, T2 <span class="keyword">const</span>&amp; b)
<a name="l00072"></a>00072 {
<a name="l00073"></a>00073 <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="structboost_1_1geometry_1_1select__most__precise.html" title="Meta-function to select, of two types, the most accurate type for calculations.">select_most_precise&lt;T1, T2&gt;::type</a> select_type;
<a name="l00074"></a>00074 <span class="keywordflow">return</span> <a class="code" href="group__equals.html#ge18e3cb2ad5b7fbc8f0ce9e0f92397bc" title="Detect if two geometries are spatially equal.">detail::math::equals</a>
<a name="l00075"></a>00075 &lt;
<a name="l00076"></a>00076 select_type,
<a name="l00077"></a>00077 boost::is_floating_point&lt;select_type&gt;::type::value
<a name="l00078"></a>00078 &gt;::apply(a, b);
<a name="l00079"></a>00079 }
<a name="l00080"></a>00080
<a name="l00081"></a>00081
<a name="l00082"></a>00082 <span class="comment">// TODO: The idea is to replace "double const globals" with inline</span>
<a name="l00083"></a>00083 <span class="comment">// template functions, so code/data is generated if not necessary.</span>
<a name="l00084"></a>00084 <span class="comment">// --mloskot</span>
<a name="l00085"></a>00085 <span class="comment">//template &lt;typename T&gt;</span>
<a name="l00086"></a>00086 <span class="comment">//inline T pi()</span>
<a name="l00087"></a>00087 <span class="comment">//{</span>
<a name="l00088"></a>00088 <span class="comment">// return boost::math::constants::pi&lt;T&gt;();</span>
<a name="l00089"></a>00089 <span class="comment">//}</span>
<a name="l00090"></a>00090 <span class="comment">//</span>
<a name="l00091"></a>00091 <span class="comment">//template &lt;&gt;</span>
<a name="l00092"></a>00092 <span class="comment">//inline double pi&lt;double&gt;()</span>
<a name="l00093"></a>00093 <span class="comment">//{</span>
<a name="l00094"></a>00094 <span class="comment">// return boost::math::constants::pi&lt;double&gt;();</span>
<a name="l00095"></a>00095 <span class="comment">//}</span>
<a name="l00096"></a><a class="code" href="namespaceboost_1_1geometry_1_1math.html#6bd0bb6f318f8a5cce5299989c16d715">00096</a> <span class="keywordtype">double</span> <span class="keyword">const</span> <a class="code" href="namespaceboost_1_1geometry_1_1math.html#6bd0bb6f318f8a5cce5299989c16d715">pi</a> = boost::math::constants::pi&lt;double&gt;();
<a name="l00097"></a><a class="code" href="namespaceboost_1_1geometry_1_1math.html#8b375c90f297a5c187ee81cb4f5a9d4e">00097</a> <span class="keywordtype">double</span> <span class="keyword">const</span> <a class="code" href="namespaceboost_1_1geometry_1_1math.html#8b375c90f297a5c187ee81cb4f5a9d4e">two_pi</a> = 2.0 * <a class="code" href="namespaceboost_1_1geometry_1_1math.html#6bd0bb6f318f8a5cce5299989c16d715">pi</a>;
<a name="l00098"></a><a class="code" href="namespaceboost_1_1geometry_1_1math.html#30bc90a8362ff173027c1bd4ec722cc8">00098</a> <span class="keywordtype">double</span> <span class="keyword">const</span> <a class="code" href="namespaceboost_1_1geometry_1_1math.html#30bc90a8362ff173027c1bd4ec722cc8">d2r</a> = <a class="code" href="namespaceboost_1_1geometry_1_1math.html#6bd0bb6f318f8a5cce5299989c16d715">pi</a> / 180.0;
<a name="l00099"></a><a class="code" href="namespaceboost_1_1geometry_1_1math.html#bc89a0d091b79fd7e5ed12cee570354c">00099</a> <span class="keywordtype">double</span> <span class="keyword">const</span> <a class="code" href="namespaceboost_1_1geometry_1_1math.html#bc89a0d091b79fd7e5ed12cee570354c">r2d</a> = 1.0 / <a class="code" href="namespaceboost_1_1geometry_1_1math.html#30bc90a8362ff173027c1bd4ec722cc8">d2r</a>;
<a name="l00100"></a>00100
<a name="l00107"></a>00107 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00108"></a><a class="code" href="group__utility.html#g8b37d61a2eeaf39b8f02805de8426b98">00108</a> <span class="keyword">inline</span> T <a class="code" href="group__utility.html#g8b37d61a2eeaf39b8f02805de8426b98" title="Calculates the haversine of an angle.">hav</a>(T <span class="keyword">const</span>&amp; theta)
<a name="l00109"></a>00109 {
<a name="l00110"></a>00110 <span class="keyword">using</span> boost::math::constants::half;
<a name="l00111"></a>00111 T <span class="keyword">const</span> sn = std::sin(half&lt;T&gt;() * theta);
<a name="l00112"></a>00112 <span class="keywordflow">return</span> sn * sn;
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114
<a name="l00121"></a>00121 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00122"></a><a class="code" href="group__utility.html#g86fd178809413ffae07cbfd827fa1684">00122</a> <span class="keyword">inline</span> T <a class="code" href="group__utility.html#g86fd178809413ffae07cbfd827fa1684" title="Short utility to return the square.">sqr</a>(T <span class="keyword">const</span>&amp; value)
<a name="l00123"></a>00123 {
<a name="l00124"></a>00124 <span class="keywordflow">return</span> value * value;
<a name="l00125"></a>00125 }
<a name="l00126"></a>00126
<a name="l00127"></a>00127 } <span class="comment">// namespace math</span>
<a name="l00128"></a>00128
<a name="l00129"></a>00129
<a name="l00130"></a>00130 }} <span class="comment">// namespace boost::geometry</span>
<a name="l00131"></a>00131
<a name="l00132"></a>00132 <span class="preprocessor">#endif // BOOST_GEOMETRY_UTIL_MATH_HPP</span>
</pre></div></div>
<hr size="1">
<table width="100%">
<tbody>
<tr>
<td align="left"><small>
<p>December 1, 2009</p>
</small></td>
<td align="right">
<small>Copyright <20> 1995-2009 Barend Gehrels, Geodan, Amsterdam<br>
Copyright <20> 2008-2009 Bruno Lalande, Paris<br>
Copyright <20> 2009 Mateusz Loskot, Cadcorp, London<br>
</small>
</td>
</tr>
</tbody>
</table>
<address style="text-align: right;"><small>
Documentation is generated by&nbsp;<a href="http://www.doxygen.org/index.html">Doxygen</a>
</small></address>
</body>
</html>