]>
Commit | Line | Data |
---|---|---|
370be031 | 1 | // -*- C++ -*- |
2 | /////////////////////////////////////////////////////////////////////////////// | |
3 | // File: geom_2d.h // | |
4 | // Description: header file for two-dimensional geometry tools // | |
5 | // This file is part of the SISCone project. // | |
6 | // WARNING: this is not the main SISCone trunk but // | |
7 | // an adaptation to spherical coordinates // | |
8 | // For more details, see http://projects.hepforge.org/siscone // | |
9 | // // | |
10 | // Copyright (c) 2006-2008 Gavin Salam and Gregory Soyez // | |
11 | // // | |
12 | // This program is free software; you can redistribute it and/or modify // | |
13 | // it under the terms of the GNU General Public License as published by // | |
14 | // the Free Software Foundation; either version 2 of the License, or // | |
15 | // (at your option) any later version. // | |
16 | // // | |
17 | // This program is distributed in the hope that it will be useful, // | |
18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
20 | // GNU General Public License for more details. // | |
21 | // // | |
22 | // You should have received a copy of the GNU General Public License // | |
23 | // along with this program; if not, write to the Free Software // | |
24 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA // | |
25 | // // | |
26 | // $Revision:: 268 $// | |
27 | // $Date:: 2009-03-12 21:24:16 +0100 (Thu, 12 Mar 2009) $// | |
28 | /////////////////////////////////////////////////////////////////////////////// | |
29 | ||
30 | #ifndef __SPH_GEOM_2D_H__ | |
31 | #define __SPH_GEOM_2D_H__ | |
32 | ||
33 | #include <iostream> | |
34 | #include <math.h> | |
35 | #include <siscone/defines.h> | |
36 | #include <siscone/geom_2d.h> | |
37 | ||
38 | #ifndef M_PI | |
39 | #define M_PI 3.141592653589793238462643383279502884197 | |
40 | #endif | |
41 | ||
42 | namespace siscone_spherical{ | |
43 | ||
44 | /** | |
45 | * \class CSphtheta_phi_range | |
46 | * \brief class for holding a covering range in eta-phi | |
47 | * | |
48 | * This class deals with ranges in the eta-phi plane. It | |
49 | * implements methods to test if two ranges overlap and | |
50 | * to take the union of two overlapping intervals. | |
51 | */ | |
52 | class CSphtheta_phi_range{ | |
53 | public: | |
54 | /// default ctor | |
55 | CSphtheta_phi_range(); | |
56 | ||
57 | /// ctor with initialisation | |
58 | /// we initialise with a centre (in theta,phi) and a radius | |
59 | /// \param c_theta theta coordinate of the centre | |
60 | /// \param c_phi phi coordinate of the centre | |
61 | /// \param R radius | |
62 | CSphtheta_phi_range(double c_theta, double c_phi, double R); | |
63 | ||
64 | /// assignment of range | |
65 | /// \param r range to assign to current one | |
66 | CSphtheta_phi_range& operator = (const CSphtheta_phi_range &r); | |
67 | ||
68 | /// add a particle to the range | |
69 | /// \param theta theta coordinate of the particle | |
70 | /// \param phi phi coordinate of the particle | |
71 | /// \return 0 on success, 1 on error | |
72 | int add_particle(const double theta, const double phi); | |
73 | ||
74 | /// theta range as a binary coding of covered cells | |
75 | unsigned int theta_range; | |
76 | ||
77 | /// phi range as a binary coding of covered cells | |
78 | unsigned int phi_range; | |
79 | ||
80 | /// extremal value for theta | |
81 | static double theta_min; ///< minimal value for theta (set to 0) | |
82 | static double theta_max; ///< maximal value for theta (set to pi) | |
83 | ||
84 | private: | |
85 | /// return the cell index corrsponding to an theta value | |
86 | inline unsigned int get_theta_cell(double theta){ | |
87 | return (unsigned int) (1 << ((int) (32*((theta-theta_min)/(theta_max-theta_min))))); | |
88 | } | |
89 | ||
90 | /// return the cell index corrsponding to a phi value | |
91 | inline unsigned int get_phi_cell(double phi){ | |
92 | return (unsigned int) (1 << ((int) (32*phi/twopi+16)%32)); | |
93 | } | |
94 | }; | |
95 | ||
96 | /// test overlap | |
97 | /// \param r1 first range | |
98 | /// \param r2 second range | |
99 | /// \return true if overlap, false otherwise. | |
100 | bool is_range_overlap(const CSphtheta_phi_range &r1, const CSphtheta_phi_range &r2); | |
101 | ||
102 | /// compute union | |
103 | /// Note: we assume that the two intervals overlap | |
104 | /// \param r1 first range | |
105 | /// \param r2 second range | |
106 | /// \return union of the two ranges | |
107 | const CSphtheta_phi_range range_union(const CSphtheta_phi_range &r1, const CSphtheta_phi_range &r2); | |
108 | ||
109 | } | |
110 | ||
111 | #endif |