AliRoot Core  edcc906 (edcc906)
AliMpArea.cxx
Go to the documentation of this file.
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;
38 ClassImp(AliMpArea)
40 
41 //_____________________________________________________________________________
42 AliMpArea::AliMpArea(Double_t x, Double_t y,
43  Double_t dx, Double_t dy)
44  : TObject(),
45  fPositionX(x),
46  fPositionY(y),
47  fDimensionX(dx),
48  fDimensionY(dy),
49  fValidity(true)
50 {
52 
53  // Check dimensions
54  if ( fDimensionX < - AliMpConstants::LengthTolerance() ||
55  fDimensionY < - AliMpConstants::LengthTolerance() ||
56  ( fDimensionX < AliMpConstants::LengthTolerance() &&
57  fDimensionY < AliMpConstants::LengthTolerance() ) )
58  {
59  fDimensionX = 0.;
60  fDimensionY = 0.;
61  fValidity = false;
62  }
63 }
64 
65 //_____________________________________________________________________________
67  : TObject(),
68  fPositionX(0.),
69  fPositionY(0.),
70  fDimensionX(0.),
71  fDimensionY(0.),
72  fValidity(false)
73 {
75 }
76 
77 //_____________________________________________________________________________
79  TObject(rhs),
84  fValidity(rhs.fValidity)
85 {
87 }
88 
89 //_____________________________________________________________________________
91 {
93 }
94 
95 //
96 // operators
97 //
98 
99 //______________________________________________________________________________
101 {
103 
104  // check assignment to self
105  if (this == &right) return *this;
106 
107  // base class assignment
108  TObject::operator=(right);
109 
110  fPositionX = right.fPositionX;
111  fPositionY = right.fPositionY;
112  fDimensionX = right.fDimensionX;
113  fDimensionY = right.fDimensionY;
114  fValidity = right.fValidity;
115 
116  return *this;
117 }
118 
119 //
120 // public methods
121 //
122 
123 //_____________________________________________________________________________
124 Double_t AliMpArea::LeftBorder() const
125 {
127 
128  return fPositionX - fDimensionX;
129 }
130 
131 //_____________________________________________________________________________
132 Double_t AliMpArea::RightBorder() const
133 {
135 
136  return fPositionX + fDimensionX;
137 }
138 
139 //_____________________________________________________________________________
140 Double_t AliMpArea::UpBorder() const
141 {
143 
144  return fPositionY + fDimensionY;
145 }
146 
147 //_____________________________________________________________________________
148 Double_t AliMpArea::DownBorder() const
149 {
151 
152  return fPositionY - fDimensionY;
153 }
154 
155 //_____________________________________________________________________________
156 void AliMpArea::LeftDownCorner(Double_t& x, Double_t& y) const
157 {
159 
160  x = LeftBorder();
161  y = DownBorder();
162 }
163 
164 //_____________________________________________________________________________
165 void AliMpArea::LeftUpCorner(Double_t& x, Double_t& y) const
166 {
168 
169  x = LeftBorder();
170  y = UpBorder();
171 }
172 
173 //_____________________________________________________________________________
174 void AliMpArea::RightDownCorner(Double_t& x, Double_t& y) const
175 {
177 
178  x = RightBorder();
179  y = DownBorder();
180 }
181 
182 
183 //_____________________________________________________________________________
184 void AliMpArea::RightUpCorner(Double_t& x, Double_t& y) const
185 {
187 
188  x = RightBorder();
189  y = UpBorder();
190 }
191 
192 //_____________________________________________________________________________
193 Bool_t AliMpArea::Contains(const AliMpArea& area) const
194 {
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  if ( area.LeftBorder() < LeftBorder() ||
204  area.RightBorder() > RightBorder() ||
205  area.DownBorder() < DownBorder() ||
206  area.UpBorder() > UpBorder() )
207  {
208  return kFALSE;
209  }
210  else
211  {
212  return kTRUE;
213  }
214 }
215 
216 //_____________________________________________________________________________
218 {
220 
221  Double_t xmin = TMath::Max(area.LeftBorder(),LeftBorder());
222  Double_t xmax = TMath::Min(area.RightBorder(),RightBorder());
223  Double_t ymin = TMath::Max(area.DownBorder(),DownBorder());
224  Double_t ymax = TMath::Min(area.UpBorder(),UpBorder());
225 
226  return AliMpArea( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ,
227  (xmax-xmin)/2.0, (ymax-ymin)/2.0 );
228 }
229 
230 //_____________________________________________________________________________
231 Bool_t AliMpArea::Overlap(const AliMpArea& area) const
232 {
234 
237  {
238  return kFALSE;
239  }
240 
243  {
244  return kFALSE;
245  }
246  return kTRUE;
247 
248 }
249 
250 //_____________________________________________________________________________
251 void
252 AliMpArea::Print(Option_t* opt) const
253 {
257 
258 
259  if ( opt[0] == 'B' ) {
260  cout << "Area x-borders: ("
261  << LeftBorder() << ", " << RightBorder() << ") "
262  << " y-borders: ("
263  << DownBorder() << ", " << UpBorder() << ") "
264  << endl;
265  return;
266 
267  }
268 
269  cout << (*this) << endl;
270 }
271 
272 //_____________________________________________________________________________
273 void
274 AliMpArea::GetParameters(Double_t& x, Double_t& y,
275  Double_t& dx, Double_t& dy) const
276 {
278 
279  x = fPositionX;
280  y = fPositionY;
281  dx = fDimensionX;
282  dy = fDimensionY;
283 }
284 
285 //_____________________________________________________________________________
286 ostream& operator<< (ostream &stream,const AliMpArea& area)
287 {
289 
290  stream << "Area: position: ("
291  << area.GetPositionX() << ", " << area.GetPositionY() << ") "
292  << " dimensions: ("
293  << area.GetDimensionX() << ", " << area.GetDimensionY() << ") "
294  << " valid: " << (area.IsValid()==true ? "YES":"NO")
295  << endl;
296  return stream;
297 }
298 
Double_t GetDimensionY() const
Return y dimensions.
Definition: AliMpArea.h:81
Double_t GetPositionY() const
Return y position.
Definition: AliMpArea.h:77
Double_t LeftBorder() const
Definition: AliMpArea.cxx:124
Double_t fPositionY
y position
Definition: AliMpArea.h:62
A rectangle area positioned in plane..
Definition: AliMpArea.h:20
virtual ~AliMpArea()
Definition: AliMpArea.cxx:90
void LeftUpCorner(Double_t &x, Double_t &y) const
Definition: AliMpArea.cxx:165
static Double_t LengthTolerance()
Return the length precision for tests.
Double_t fDimensionY
y dimension (half lengths)
Definition: AliMpArea.h:64
Double_t fPositionX
x position
Definition: AliMpArea.h:61
void Print(Option_t *opt="") const
Definition: AliMpArea.cxx:252
Double_t GetDimensionX() const
Return x dimensions.
Definition: AliMpArea.h:79
void LeftDownCorner(Double_t &x, Double_t &y) const
Definition: AliMpArea.cxx:156
AliMpArea Intersect(const AliMpArea &area) const
Definition: AliMpArea.cxx:217
AliMpArea & operator=(const AliMpArea &right)
Definition: AliMpArea.cxx:100
Double_t UpBorder() const
Definition: AliMpArea.cxx:140
Bool_t fValidity
validity
Definition: AliMpArea.h:65
Double_t GetPositionX() const
Return x position.
Definition: AliMpArea.h:75
void RightDownCorner(Double_t &x, Double_t &y) const
Definition: AliMpArea.cxx:174
Double_t fDimensionX
x dimension (half lengths)
Definition: AliMpArea.h:63
Double_t DownBorder() const
Definition: AliMpArea.cxx:148
void RightUpCorner(Double_t &x, Double_t &y) const
Definition: AliMpArea.cxx:184
Bool_t IsValid() const
Return validity.
Definition: AliMpArea.h:83
void GetParameters(Double_t &x, Double_t &y, Double_t &dx, Double_t &dy) const
Definition: AliMpArea.cxx:274
Bool_t Overlap(const AliMpArea &area) const
Definition: AliMpArea.cxx:231
Bool_t Contains(const AliMpArea &area) const
Definition: AliMpArea.cxx:193
Double_t RightBorder() const
Definition: AliMpArea.cxx:132
ostream & operator<<(ostream &stream, const AliMpArea &area)
Definition: AliMpArea.cxx:286