]>
Commit | Line | Data |
---|---|---|
dee1d5f1 | 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 | ||
5f91c9e8 | 16 | // $Id$ |
13985652 | 17 | // $MpId: AliMpArea.cxx,v 1.8 2006/05/24 13:58:29 ivana Exp $ |
5f91c9e8 | 18 | // Category: basic |
3d1463c8 | 19 | |
20 | //----------------------------------------------------------------------------- | |
5f91c9e8 | 21 | // Class AliMpArea |
22 | // ---------------- | |
23 | // Class that defines a rectangle area positioned in plane.. | |
3ffe1a93 | 24 | // Included in AliRoot: 2003/05/02 |
5f91c9e8 | 25 | // Authors: David Guez, Ivana Hrivnacova; IPN Orsay |
3d1463c8 | 26 | //----------------------------------------------------------------------------- |
5f91c9e8 | 27 | |
5f91c9e8 | 28 | #include "AliMpArea.h" |
94f2b22c | 29 | |
30 | #include "AliLog.h" | |
52dd0c39 | 31 | #include "AliMpConstants.h" |
5f91c9e8 | 32 | |
2c605e66 | 33 | #include <Riostream.h> |
34 | ||
13985652 | 35 | /// \cond CLASSIMP |
5f91c9e8 | 36 | ClassImp(AliMpArea) |
13985652 | 37 | /// \endcond |
5f91c9e8 | 38 | |
39 | //_____________________________________________________________________________ | |
6e97fbb8 | 40 | AliMpArea::AliMpArea(Double_t x, Double_t y, |
41 | Double_t dx, Double_t dy) | |
5f91c9e8 | 42 | : TObject(), |
6e97fbb8 | 43 | fPositionX(x), |
44 | fPositionY(y), | |
45 | fDimensionX(dx), | |
46 | fDimensionY(dy), | |
dee1d5f1 | 47 | fValidity(true) |
48 | { | |
49 | /// Standard constructor | |
50 | ||
5f91c9e8 | 51 | // Check dimensions |
6e97fbb8 | 52 | if ( fDimensionX < - AliMpConstants::LengthTolerance() || |
53 | fDimensionY < - AliMpConstants::LengthTolerance() || | |
54 | ( fDimensionX < AliMpConstants::LengthTolerance() && | |
55 | fDimensionY < AliMpConstants::LengthTolerance() ) ) | |
52dd0c39 | 56 | { |
6e97fbb8 | 57 | fDimensionX = 0.; |
58 | fDimensionY = 0.; | |
5f91c9e8 | 59 | fValidity = false; |
60 | } | |
61 | } | |
62 | ||
63 | //_____________________________________________________________________________ | |
64 | AliMpArea::AliMpArea() | |
65 | : TObject(), | |
6e97fbb8 | 66 | fPositionX(0.), |
67 | fPositionY(0.), | |
68 | fDimensionX(0.), | |
69 | fDimensionY(0.), | |
dee1d5f1 | 70 | fValidity(false) |
71 | { | |
72 | /// Default constructor | |
5f91c9e8 | 73 | } |
74 | ||
75 | //_____________________________________________________________________________ | |
76 | AliMpArea::AliMpArea(const AliMpArea& rhs): | |
77 | TObject(rhs), | |
6e97fbb8 | 78 | fPositionX(rhs.fPositionX), |
79 | fPositionY(rhs.fPositionY), | |
80 | fDimensionX(rhs.fDimensionX), | |
81 | fDimensionY(rhs.fDimensionY), | |
0471c97b | 82 | fValidity(rhs.fValidity) |
dee1d5f1 | 83 | { |
84 | /// Copy constructor | |
5f91c9e8 | 85 | } |
86 | ||
87 | //_____________________________________________________________________________ | |
dee1d5f1 | 88 | AliMpArea::~AliMpArea() |
89 | { | |
90 | /// Destructor | |
5f91c9e8 | 91 | } |
92 | ||
93 | // | |
94 | // operators | |
95 | // | |
96 | ||
97 | //______________________________________________________________________________ | |
98 | AliMpArea& AliMpArea::operator = (const AliMpArea& right) | |
99 | { | |
dee1d5f1 | 100 | /// Assignment operator |
5f91c9e8 | 101 | |
dee1d5f1 | 102 | // check assignment to self |
5f91c9e8 | 103 | if (this == &right) return *this; |
104 | ||
dee1d5f1 | 105 | // base class assignment |
5f91c9e8 | 106 | TObject::operator=(right); |
107 | ||
6e97fbb8 | 108 | fPositionX = right.fPositionX; |
109 | fPositionY = right.fPositionY; | |
110 | fDimensionX = right.fDimensionX; | |
111 | fDimensionY = right.fDimensionY; | |
5f91c9e8 | 112 | fValidity = right.fValidity; |
113 | ||
114 | return *this; | |
115 | } | |
116 | ||
117 | // | |
118 | // public methods | |
119 | // | |
120 | ||
121 | //_____________________________________________________________________________ | |
122 | Double_t AliMpArea::LeftBorder() const | |
123 | { | |
dee1d5f1 | 124 | /// Return the position of the left edge. |
5f91c9e8 | 125 | |
6e97fbb8 | 126 | return fPositionX - fDimensionX; |
5f91c9e8 | 127 | } |
128 | ||
129 | //_____________________________________________________________________________ | |
130 | Double_t AliMpArea::RightBorder() const | |
131 | { | |
dee1d5f1 | 132 | /// Return the position of right edge. |
5f91c9e8 | 133 | |
6e97fbb8 | 134 | return fPositionX + fDimensionX; |
5f91c9e8 | 135 | } |
136 | ||
137 | //_____________________________________________________________________________ | |
138 | Double_t AliMpArea::UpBorder() const | |
139 | { | |
dee1d5f1 | 140 | /// Return the position of the up edge. |
5f91c9e8 | 141 | |
6e97fbb8 | 142 | return fPositionY + fDimensionY; |
5f91c9e8 | 143 | } |
144 | ||
145 | //_____________________________________________________________________________ | |
146 | Double_t AliMpArea::DownBorder() const | |
147 | { | |
dee1d5f1 | 148 | /// Return the position of the down edge. |
5f91c9e8 | 149 | |
6e97fbb8 | 150 | return fPositionY - fDimensionY; |
5f91c9e8 | 151 | } |
152 | ||
153 | //_____________________________________________________________________________ | |
6e97fbb8 | 154 | void AliMpArea::LeftDownCorner(Double_t& x, Double_t& y) const |
5f91c9e8 | 155 | { |
dee1d5f1 | 156 | /// Return position of the left down corner. |
5f91c9e8 | 157 | |
6e97fbb8 | 158 | x = LeftBorder(); |
159 | y = DownBorder(); | |
5f91c9e8 | 160 | } |
161 | ||
162 | //_____________________________________________________________________________ | |
6e97fbb8 | 163 | void AliMpArea::LeftUpCorner(Double_t& x, Double_t& y) const |
5f91c9e8 | 164 | { |
dee1d5f1 | 165 | /// Return position of the left up corner. |
5f91c9e8 | 166 | |
6e97fbb8 | 167 | x = LeftBorder(); |
168 | y = UpBorder(); | |
5f91c9e8 | 169 | } |
170 | ||
171 | //_____________________________________________________________________________ | |
6e97fbb8 | 172 | void AliMpArea::RightDownCorner(Double_t& x, Double_t& y) const |
5f91c9e8 | 173 | { |
dee1d5f1 | 174 | /// Return position of the right down corner. |
5f91c9e8 | 175 | |
6e97fbb8 | 176 | x = RightBorder(); |
177 | y = DownBorder(); | |
5f91c9e8 | 178 | } |
179 | ||
180 | ||
181 | //_____________________________________________________________________________ | |
6e97fbb8 | 182 | void AliMpArea::RightUpCorner(Double_t& x, Double_t& y) const |
5f91c9e8 | 183 | { |
dee1d5f1 | 184 | /// Return position of the right up corner. |
5f91c9e8 | 185 | |
6e97fbb8 | 186 | x = RightBorder(); |
187 | y = UpBorder(); | |
5f91c9e8 | 188 | } |
189 | ||
94f2b22c | 190 | //_____________________________________________________________________________ |
191 | Bool_t AliMpArea::Contains(const AliMpArea& area) const | |
192 | { | |
193 | /// Whether area is contained within this | |
194 | ||
195 | // return | |
196 | // ( area.LeftBorder() > LeftBorder() - AliMpConstants::LengthTolerance() && | |
197 | // area.RightBorder() < RightBorder() + AliMpConstants::LengthTolerance() && | |
198 | // area.DownBorder() > DownBorder() - AliMpConstants::LengthTolerance() && | |
199 | // area.UpBorder() < UpBorder() + AliMpConstants::LengthTolerance() ); | |
200 | ||
201 | if ( area.LeftBorder() < LeftBorder() || | |
202 | area.RightBorder() > RightBorder() || | |
203 | area.DownBorder() < DownBorder() || | |
204 | area.UpBorder() > UpBorder() ) | |
205 | { | |
206 | return kFALSE; | |
207 | } | |
208 | else | |
209 | { | |
210 | return kTRUE; | |
211 | } | |
212 | } | |
213 | ||
214 | //_____________________________________________________________________________ | |
215 | AliMpArea AliMpArea::Intersect(const AliMpArea& area) const | |
216 | { | |
217 | /// Return the common part of area and this | |
218 | ||
219 | Double_t xmin = TMath::Max(area.LeftBorder(),LeftBorder()); | |
220 | Double_t xmax = TMath::Min(area.RightBorder(),RightBorder()); | |
221 | Double_t ymin = TMath::Max(area.DownBorder(),DownBorder()); | |
222 | Double_t ymax = TMath::Min(area.UpBorder(),UpBorder()); | |
223 | ||
6e97fbb8 | 224 | return AliMpArea( (xmin+xmax)/2.0, (ymin+ymax)/2.0 , |
225 | (xmax-xmin)/2.0, (ymax-ymin)/2.0 ); | |
94f2b22c | 226 | } |
227 | ||
228 | //_____________________________________________________________________________ | |
229 | Bool_t AliMpArea::Overlap(const AliMpArea& area) const | |
230 | { | |
231 | /// Return true if this overlaps with given area | |
232 | ||
233 | if ( LeftBorder() > area.RightBorder() - AliMpConstants::LengthTolerance() || | |
234 | RightBorder() < area.LeftBorder() + AliMpConstants::LengthTolerance() ) | |
235 | { | |
236 | return kFALSE; | |
237 | } | |
238 | ||
239 | if ( DownBorder() > area.UpBorder() - AliMpConstants::LengthTolerance() || | |
240 | UpBorder() < area.DownBorder() + AliMpConstants::LengthTolerance() ) | |
241 | { | |
242 | return kFALSE; | |
243 | } | |
244 | return kTRUE; | |
245 | ||
246 | } | |
247 | ||
52dd0c39 | 248 | //_____________________________________________________________________________ |
249 | void | |
ce5605e9 | 250 | AliMpArea::Print(Option_t* opt) const |
52dd0c39 | 251 | { |
71a2d3aa | 252 | /// Printing |
ce5605e9 | 253 | /// When option is set to B (borders), the area boreders will be printed |
254 | /// instead of default parameters | |
255 | ||
256 | ||
257 | if ( opt[0] == 'B' ) { | |
258 | cout << "Area x-borders: (" | |
259 | << LeftBorder() << ", " << RightBorder() << ") " | |
260 | << " y-borders: (" | |
261 | << DownBorder() << ", " << UpBorder() << ") " | |
262 | << endl; | |
263 | return; | |
264 | ||
265 | } | |
71a2d3aa | 266 | |
52dd0c39 | 267 | cout << (*this) << endl; |
268 | } | |
269 | ||
6e97fbb8 | 270 | //_____________________________________________________________________________ |
271 | void | |
272 | AliMpArea::GetParameters(Double_t& x, Double_t& y, | |
273 | Double_t& dx, Double_t& dy) const | |
cddcc1f3 | 274 | { |
275 | /// Fill the parameters: x, y position and dimensions | |
276 | ||
6e97fbb8 | 277 | x = fPositionX; |
278 | y = fPositionY; | |
279 | dx = fDimensionX; | |
280 | dy = fDimensionY; | |
281 | } | |
282 | ||
5f91c9e8 | 283 | //_____________________________________________________________________________ |
284 | ostream& operator<< (ostream &stream,const AliMpArea& area) | |
285 | { | |
dee1d5f1 | 286 | /// Output streaming |
287 | ||
5f91c9e8 | 288 | stream << "Area: position: (" |
6e97fbb8 | 289 | << area.GetPositionX() << ", " << area.GetPositionY() << ") " |
5f91c9e8 | 290 | << " dimensions: (" |
6e97fbb8 | 291 | << area.GetDimensionX() << ", " << area.GetDimensionY() << ") " |
52dd0c39 | 292 | << " valid: " << (area.IsValid()==true ? "YES":"NO") |
5f91c9e8 | 293 | << endl; |
294 | return stream; | |
295 | } | |
296 |