]>
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 | //_____________________________________________________________________________ | |
40 | AliMpArea::AliMpArea(const TVector2& position, const TVector2& dimensions) | |
41 | : TObject(), | |
42 | fPosition(position), | |
43 | fDimensions(dimensions), | |
dee1d5f1 | 44 | fValidity(true) |
45 | { | |
46 | /// Standard constructor | |
47 | ||
5f91c9e8 | 48 | // Check dimensions |
52dd0c39 | 49 | if ( fDimensions.X() < - AliMpConstants::LengthTolerance() || |
50 | fDimensions.Y() < - AliMpConstants::LengthTolerance() || | |
51 | ( fDimensions.X() < AliMpConstants::LengthTolerance() && | |
52 | fDimensions.Y() < AliMpConstants::LengthTolerance() ) ) | |
53 | { | |
5f91c9e8 | 54 | fDimensions = TVector2(); |
55 | fValidity = false; | |
56 | } | |
57 | } | |
58 | ||
59 | //_____________________________________________________________________________ | |
60 | AliMpArea::AliMpArea() | |
61 | : TObject(), | |
62 | fPosition(TVector2()), | |
63 | fDimensions(TVector2()), | |
dee1d5f1 | 64 | fValidity(false) |
65 | { | |
66 | /// Default constructor | |
5f91c9e8 | 67 | } |
68 | ||
69 | //_____________________________________________________________________________ | |
70 | AliMpArea::AliMpArea(const AliMpArea& rhs): | |
71 | TObject(rhs), | |
72 | fPosition(rhs.fPosition), | |
0471c97b | 73 | fDimensions(rhs.fDimensions), |
74 | fValidity(rhs.fValidity) | |
dee1d5f1 | 75 | { |
76 | /// Copy constructor | |
5f91c9e8 | 77 | } |
78 | ||
79 | //_____________________________________________________________________________ | |
dee1d5f1 | 80 | AliMpArea::~AliMpArea() |
81 | { | |
82 | /// Destructor | |
5f91c9e8 | 83 | } |
84 | ||
85 | // | |
86 | // operators | |
87 | // | |
88 | ||
89 | //______________________________________________________________________________ | |
90 | AliMpArea& AliMpArea::operator = (const AliMpArea& right) | |
91 | { | |
dee1d5f1 | 92 | /// Assignment operator |
5f91c9e8 | 93 | |
dee1d5f1 | 94 | // check assignment to self |
5f91c9e8 | 95 | if (this == &right) return *this; |
96 | ||
dee1d5f1 | 97 | // base class assignment |
5f91c9e8 | 98 | TObject::operator=(right); |
99 | ||
100 | fPosition = right.fPosition; | |
101 | fDimensions = right.fDimensions; | |
102 | fValidity = right.fValidity; | |
103 | ||
104 | return *this; | |
105 | } | |
106 | ||
107 | // | |
108 | // public methods | |
109 | // | |
110 | ||
111 | //_____________________________________________________________________________ | |
112 | Double_t AliMpArea::LeftBorder() const | |
113 | { | |
dee1d5f1 | 114 | /// Return the position of the left edge. |
5f91c9e8 | 115 | |
116 | return fPosition.X() - fDimensions.X(); | |
117 | } | |
118 | ||
119 | //_____________________________________________________________________________ | |
120 | Double_t AliMpArea::RightBorder() const | |
121 | { | |
dee1d5f1 | 122 | /// Return the position of right edge. |
5f91c9e8 | 123 | |
124 | return fPosition.X() + fDimensions.X(); | |
125 | } | |
126 | ||
127 | //_____________________________________________________________________________ | |
128 | Double_t AliMpArea::UpBorder() const | |
129 | { | |
dee1d5f1 | 130 | /// Return the position of the up edge. |
5f91c9e8 | 131 | |
132 | return fPosition.Y() + fDimensions.Y(); | |
133 | } | |
134 | ||
135 | //_____________________________________________________________________________ | |
136 | Double_t AliMpArea::DownBorder() const | |
137 | { | |
dee1d5f1 | 138 | /// Return the position of the down edge. |
5f91c9e8 | 139 | |
140 | return fPosition.Y() - fDimensions.Y(); | |
141 | } | |
142 | ||
143 | //_____________________________________________________________________________ | |
144 | TVector2 AliMpArea::LeftDownCorner() const | |
145 | { | |
dee1d5f1 | 146 | /// Return position of the left down corner. |
5f91c9e8 | 147 | |
148 | return TVector2(LeftBorder(), DownBorder()); | |
149 | } | |
150 | ||
151 | //_____________________________________________________________________________ | |
152 | TVector2 AliMpArea::LeftUpCorner() const | |
153 | { | |
dee1d5f1 | 154 | /// Return position of the left up corner. |
5f91c9e8 | 155 | |
156 | return TVector2(LeftBorder(), UpBorder()); | |
157 | } | |
158 | ||
159 | //_____________________________________________________________________________ | |
160 | TVector2 AliMpArea::RightDownCorner() const | |
161 | { | |
dee1d5f1 | 162 | /// Return position of the right down corner. |
5f91c9e8 | 163 | |
164 | return TVector2(RightBorder(), DownBorder()); | |
165 | } | |
166 | ||
167 | ||
168 | //_____________________________________________________________________________ | |
169 | TVector2 AliMpArea::RightUpCorner() const | |
170 | { | |
dee1d5f1 | 171 | /// Return position of the right up corner. |
5f91c9e8 | 172 | |
173 | return TVector2(RightBorder(), UpBorder()); | |
174 | } | |
175 | ||
94f2b22c | 176 | //_____________________________________________________________________________ |
177 | Bool_t AliMpArea::Contains(const AliMpArea& area) const | |
178 | { | |
179 | /// Whether area is contained within this | |
180 | ||
181 | // return | |
182 | // ( area.LeftBorder() > LeftBorder() - AliMpConstants::LengthTolerance() && | |
183 | // area.RightBorder() < RightBorder() + AliMpConstants::LengthTolerance() && | |
184 | // area.DownBorder() > DownBorder() - AliMpConstants::LengthTolerance() && | |
185 | // area.UpBorder() < UpBorder() + AliMpConstants::LengthTolerance() ); | |
186 | ||
187 | if ( area.LeftBorder() < LeftBorder() || | |
188 | area.RightBorder() > RightBorder() || | |
189 | area.DownBorder() < DownBorder() || | |
190 | area.UpBorder() > UpBorder() ) | |
191 | { | |
192 | return kFALSE; | |
193 | } | |
194 | else | |
195 | { | |
196 | return kTRUE; | |
197 | } | |
198 | } | |
199 | ||
200 | //_____________________________________________________________________________ | |
201 | AliMpArea AliMpArea::Intersect(const AliMpArea& area) const | |
202 | { | |
203 | /// Return the common part of area and this | |
204 | ||
205 | Double_t xmin = TMath::Max(area.LeftBorder(),LeftBorder()); | |
206 | Double_t xmax = TMath::Min(area.RightBorder(),RightBorder()); | |
207 | Double_t ymin = TMath::Max(area.DownBorder(),DownBorder()); | |
208 | Double_t ymax = TMath::Min(area.UpBorder(),UpBorder()); | |
209 | ||
210 | return AliMpArea( TVector2( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ), | |
211 | TVector2( (xmax-xmin)/2.0, (ymax-ymin)/2.0 ) ); | |
212 | } | |
213 | ||
214 | //_____________________________________________________________________________ | |
215 | Bool_t AliMpArea::Overlap(const AliMpArea& area) const | |
216 | { | |
217 | /// Return true if this overlaps with given area | |
218 | ||
219 | if ( LeftBorder() > area.RightBorder() - AliMpConstants::LengthTolerance() || | |
220 | RightBorder() < area.LeftBorder() + AliMpConstants::LengthTolerance() ) | |
221 | { | |
222 | return kFALSE; | |
223 | } | |
224 | ||
225 | if ( DownBorder() > area.UpBorder() - AliMpConstants::LengthTolerance() || | |
226 | UpBorder() < area.DownBorder() + AliMpConstants::LengthTolerance() ) | |
227 | { | |
228 | return kFALSE; | |
229 | } | |
230 | return kTRUE; | |
231 | ||
232 | } | |
233 | ||
52dd0c39 | 234 | //_____________________________________________________________________________ |
235 | void | |
ce5605e9 | 236 | AliMpArea::Print(Option_t* opt) const |
52dd0c39 | 237 | { |
71a2d3aa | 238 | /// Printing |
ce5605e9 | 239 | /// When option is set to B (borders), the area boreders will be printed |
240 | /// instead of default parameters | |
241 | ||
242 | ||
243 | if ( opt[0] == 'B' ) { | |
244 | cout << "Area x-borders: (" | |
245 | << LeftBorder() << ", " << RightBorder() << ") " | |
246 | << " y-borders: (" | |
247 | << DownBorder() << ", " << UpBorder() << ") " | |
248 | << endl; | |
249 | return; | |
250 | ||
251 | } | |
71a2d3aa | 252 | |
52dd0c39 | 253 | cout << (*this) << endl; |
254 | } | |
255 | ||
5f91c9e8 | 256 | //_____________________________________________________________________________ |
257 | ostream& operator<< (ostream &stream,const AliMpArea& area) | |
258 | { | |
dee1d5f1 | 259 | /// Output streaming |
260 | ||
5f91c9e8 | 261 | stream << "Area: position: (" |
262 | << area.Position().X() << ", " << area.Position().Y() << ") " | |
263 | << " dimensions: (" | |
264 | << area.Dimensions().X() << ", " << area.Dimensions().Y() << ") " | |
52dd0c39 | 265 | << " valid: " << (area.IsValid()==true ? "YES":"NO") |
5f91c9e8 | 266 | << endl; |
267 | return stream; | |
268 | } | |
269 |