Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 : * *
4 : * Author: The ALICE Off-line Project. *
5 : * Contributors are mentioned in the code where appropriate. *
6 : * *
7 : * Permission to use, copy, modify and distribute this software and its *
8 : * documentation strictly for non-commercial purposes is hereby granted *
9 : * without fee, provided that the above copyright notice appears in all *
10 : * copies and that both the copyright notice and this permission notice *
11 : * appear in the supporting documentation. The authors make no claims *
12 : * about the suitability of this software for any purpose. It is *
13 : * provided "as is" without express or implied warranty. *
14 : **************************************************************************/
15 :
16 : // $Id$
17 : // $MpId: AliMpArea.cxx,v 1.8 2006/05/24 13:58:29 ivana Exp $
18 : // Category: basic
19 :
20 : //-----------------------------------------------------------------------------
21 : // Class AliMpArea
22 : // ----------------
23 : // Class that defines a rectangle area positioned in plane..
24 : // Included in AliRoot: 2003/05/02
25 : // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
26 : //-----------------------------------------------------------------------------
27 :
28 : #include "AliMpArea.h"
29 :
30 : #include "AliLog.h"
31 : #include "AliMpConstants.h"
32 :
33 : #include <Riostream.h>
34 :
35 : using std::cout;
36 : using std::endl;
37 : /// \cond CLASSIMP
38 18 : ClassImp(AliMpArea)
39 : /// \endcond
40 :
41 : //_____________________________________________________________________________
42 : AliMpArea::AliMpArea(Double_t x, Double_t y,
43 : Double_t dx, Double_t dy)
44 920329 : : TObject(),
45 920329 : fPositionX(x),
46 920329 : fPositionY(y),
47 920329 : fDimensionX(dx),
48 920329 : fDimensionY(dy),
49 920329 : fValidity(true)
50 4601645 : {
51 : /// Standard constructor
52 :
53 : // Check dimensions
54 920329 : if ( fDimensionX < - AliMpConstants::LengthTolerance() ||
55 919929 : fDimensionY < - AliMpConstants::LengthTolerance() ||
56 919929 : ( fDimensionX < AliMpConstants::LengthTolerance() &&
57 0 : fDimensionY < AliMpConstants::LengthTolerance() ) )
58 : {
59 400 : fDimensionX = 0.;
60 400 : fDimensionY = 0.;
61 400 : fValidity = false;
62 400 : }
63 1840658 : }
64 :
65 : //_____________________________________________________________________________
66 : AliMpArea::AliMpArea()
67 234 : : TObject(),
68 234 : fPositionX(0.),
69 234 : fPositionY(0.),
70 234 : fDimensionX(0.),
71 234 : fDimensionY(0.),
72 234 : fValidity(false)
73 1170 : {
74 : /// Default constructor
75 468 : }
76 :
77 : //_____________________________________________________________________________
78 : AliMpArea::AliMpArea(const AliMpArea& rhs):
79 64 : TObject(rhs),
80 64 : fPositionX(rhs.fPositionX),
81 64 : fPositionY(rhs.fPositionY),
82 64 : fDimensionX(rhs.fDimensionX),
83 64 : fDimensionY(rhs.fDimensionY),
84 64 : fValidity(rhs.fValidity)
85 320 : {
86 : /// Copy constructor
87 128 : }
88 :
89 : //_____________________________________________________________________________
90 : AliMpArea::~AliMpArea()
91 1842166 : {
92 : /// Destructor
93 2762337 : }
94 :
95 : //
96 : // operators
97 : //
98 :
99 : //______________________________________________________________________________
100 : AliMpArea& AliMpArea::operator = (const AliMpArea& right)
101 : {
102 : /// Assignment operator
103 :
104 : // check assignment to self
105 288 : if (this == &right) return *this;
106 :
107 : // base class assignment
108 144 : TObject::operator=(right);
109 :
110 144 : fPositionX = right.fPositionX;
111 144 : fPositionY = right.fPositionY;
112 144 : fDimensionX = right.fDimensionX;
113 144 : fDimensionY = right.fDimensionY;
114 144 : fValidity = right.fValidity;
115 :
116 144 : return *this;
117 144 : }
118 :
119 : //
120 : // public methods
121 : //
122 :
123 : //_____________________________________________________________________________
124 : Double_t AliMpArea::LeftBorder() const
125 : {
126 : /// Return the position of the left edge.
127 :
128 1840132 : return fPositionX - fDimensionX;
129 : }
130 :
131 : //_____________________________________________________________________________
132 : Double_t AliMpArea::RightBorder() const
133 : {
134 : /// Return the position of right edge.
135 :
136 1841540 : return fPositionX + fDimensionX;
137 : }
138 :
139 : //_____________________________________________________________________________
140 : Double_t AliMpArea::UpBorder() const
141 : {
142 : /// Return the position of the up edge.
143 :
144 1831992 : return fPositionY + fDimensionY;
145 : }
146 :
147 : //_____________________________________________________________________________
148 : Double_t AliMpArea::DownBorder() const
149 : {
150 : /// Return the position of the down edge.
151 :
152 1831238 : return fPositionY - fDimensionY;
153 : }
154 :
155 : //_____________________________________________________________________________
156 : void AliMpArea::LeftDownCorner(Double_t& x, Double_t& y) const
157 : {
158 : /// Return position of the left down corner.
159 :
160 784 : x = LeftBorder();
161 392 : y = DownBorder();
162 392 : }
163 :
164 : //_____________________________________________________________________________
165 : void AliMpArea::LeftUpCorner(Double_t& x, Double_t& y) const
166 : {
167 : /// Return position of the left up corner.
168 :
169 0 : x = LeftBorder();
170 0 : y = UpBorder();
171 0 : }
172 :
173 : //_____________________________________________________________________________
174 : void AliMpArea::RightDownCorner(Double_t& x, Double_t& y) const
175 : {
176 : /// Return position of the right down corner.
177 :
178 0 : x = RightBorder();
179 0 : y = DownBorder();
180 0 : }
181 :
182 :
183 : //_____________________________________________________________________________
184 : void AliMpArea::RightUpCorner(Double_t& x, Double_t& y) const
185 : {
186 : /// Return position of the right up corner.
187 :
188 656 : x = RightBorder();
189 328 : y = UpBorder();
190 328 : }
191 :
192 : //_____________________________________________________________________________
193 : Bool_t AliMpArea::Contains(const AliMpArea& area) const
194 : {
195 : /// Whether area is contained within this
196 :
197 : // return
198 : // ( area.LeftBorder() > LeftBorder() - AliMpConstants::LengthTolerance() &&
199 : // area.RightBorder() < RightBorder() + AliMpConstants::LengthTolerance() &&
200 : // area.DownBorder() > DownBorder() - AliMpConstants::LengthTolerance() &&
201 : // area.UpBorder() < UpBorder() + AliMpConstants::LengthTolerance() );
202 :
203 2584 : if ( area.LeftBorder() < LeftBorder() ||
204 890 : area.RightBorder() > RightBorder() ||
205 616 : area.DownBorder() < DownBorder() ||
206 312 : area.UpBorder() > UpBorder() )
207 : {
208 1016 : return kFALSE;
209 : }
210 : else
211 : {
212 120 : return kTRUE;
213 : }
214 1136 : }
215 :
216 : //_____________________________________________________________________________
217 : AliMpArea AliMpArea::Intersect(const AliMpArea& area) const
218 : {
219 : /// Return the common part of area and this
220 :
221 0 : Double_t xmin = TMath::Max(area.LeftBorder(),LeftBorder());
222 0 : Double_t xmax = TMath::Min(area.RightBorder(),RightBorder());
223 0 : Double_t ymin = TMath::Max(area.DownBorder(),DownBorder());
224 0 : Double_t ymax = TMath::Min(area.UpBorder(),UpBorder());
225 :
226 0 : return AliMpArea( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ,
227 0 : (xmax-xmin)/2.0, (ymax-ymin)/2.0 );
228 0 : }
229 :
230 : //_____________________________________________________________________________
231 : Bool_t AliMpArea::Overlap(const AliMpArea& area) const
232 : {
233 : /// Return true if this overlaps with given area
234 :
235 0 : if ( LeftBorder() > area.RightBorder() - AliMpConstants::LengthTolerance() ||
236 0 : RightBorder() < area.LeftBorder() + AliMpConstants::LengthTolerance() )
237 : {
238 0 : return kFALSE;
239 : }
240 :
241 0 : if ( DownBorder() > area.UpBorder() - AliMpConstants::LengthTolerance() ||
242 0 : UpBorder() < area.DownBorder() + AliMpConstants::LengthTolerance() )
243 : {
244 0 : return kFALSE;
245 : }
246 0 : return kTRUE;
247 :
248 0 : }
249 :
250 : //_____________________________________________________________________________
251 : void
252 : AliMpArea::Print(Option_t* opt) const
253 : {
254 : /// Printing
255 : /// When option is set to B (borders), the area boreders will be printed
256 : /// instead of default parameters
257 :
258 :
259 0 : if ( opt[0] == 'B' ) {
260 0 : cout << "Area x-borders: ("
261 0 : << LeftBorder() << ", " << RightBorder() << ") "
262 0 : << " y-borders: ("
263 0 : << DownBorder() << ", " << UpBorder() << ") "
264 0 : << endl;
265 0 : return;
266 :
267 : }
268 :
269 0 : cout << (*this) << endl;
270 0 : }
271 :
272 : //_____________________________________________________________________________
273 : void
274 : AliMpArea::GetParameters(Double_t& x, Double_t& y,
275 : Double_t& dx, Double_t& dy) const
276 : {
277 : /// Fill the parameters: x, y position and dimensions
278 :
279 0 : x = fPositionX;
280 0 : y = fPositionY;
281 0 : dx = fDimensionX;
282 0 : dy = fDimensionY;
283 0 : }
284 :
285 : //_____________________________________________________________________________
286 : ostream& operator<< (ostream &stream,const AliMpArea& area)
287 : {
288 : /// Output streaming
289 :
290 0 : stream << "Area: position: ("
291 0 : << area.GetPositionX() << ", " << area.GetPositionY() << ") "
292 0 : << " dimensions: ("
293 0 : << area.GetDimensionX() << ", " << area.GetDimensionY() << ") "
294 0 : << " valid: " << (area.IsValid()==true ? "YES":"NO")
295 0 : << endl;
296 0 : return stream;
297 : }
298 :
|