1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpArea.cxx,v 1.8 2006/05/24 13:58:29 ivana Exp $
20 //-----------------------------------------------------------------------------
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 //-----------------------------------------------------------------------------
28 #include "AliMpArea.h"
31 #include "AliMpConstants.h"
33 #include <Riostream.h>
39 //_____________________________________________________________________________
40 AliMpArea::AliMpArea(const TVector2& position, const TVector2& dimensions)
43 fDimensions(dimensions),
46 /// Standard constructor
49 if ( fDimensions.X() < - AliMpConstants::LengthTolerance() ||
50 fDimensions.Y() < - AliMpConstants::LengthTolerance() ||
51 ( fDimensions.X() < AliMpConstants::LengthTolerance() &&
52 fDimensions.Y() < AliMpConstants::LengthTolerance() ) )
54 fDimensions = TVector2();
59 //_____________________________________________________________________________
60 AliMpArea::AliMpArea()
62 fPosition(TVector2()),
63 fDimensions(TVector2()),
66 /// Default constructor
69 //_____________________________________________________________________________
70 AliMpArea::AliMpArea(const AliMpArea& rhs):
72 fPosition(rhs.fPosition),
73 fDimensions(rhs.fDimensions),
74 fValidity(rhs.fValidity)
79 //_____________________________________________________________________________
80 AliMpArea::~AliMpArea()
89 //______________________________________________________________________________
90 AliMpArea& AliMpArea::operator = (const AliMpArea& right)
92 /// Assignment operator
94 // check assignment to self
95 if (this == &right) return *this;
97 // base class assignment
98 TObject::operator=(right);
100 fPosition = right.fPosition;
101 fDimensions = right.fDimensions;
102 fValidity = right.fValidity;
111 //_____________________________________________________________________________
112 Double_t AliMpArea::LeftBorder() const
114 /// Return the position of the left edge.
116 return fPosition.X() - fDimensions.X();
119 //_____________________________________________________________________________
120 Double_t AliMpArea::RightBorder() const
122 /// Return the position of right edge.
124 return fPosition.X() + fDimensions.X();
127 //_____________________________________________________________________________
128 Double_t AliMpArea::UpBorder() const
130 /// Return the position of the up edge.
132 return fPosition.Y() + fDimensions.Y();
135 //_____________________________________________________________________________
136 Double_t AliMpArea::DownBorder() const
138 /// Return the position of the down edge.
140 return fPosition.Y() - fDimensions.Y();
143 //_____________________________________________________________________________
144 TVector2 AliMpArea::LeftDownCorner() const
146 /// Return position of the left down corner.
148 return TVector2(LeftBorder(), DownBorder());
151 //_____________________________________________________________________________
152 TVector2 AliMpArea::LeftUpCorner() const
154 /// Return position of the left up corner.
156 return TVector2(LeftBorder(), UpBorder());
159 //_____________________________________________________________________________
160 TVector2 AliMpArea::RightDownCorner() const
162 /// Return position of the right down corner.
164 return TVector2(RightBorder(), DownBorder());
168 //_____________________________________________________________________________
169 TVector2 AliMpArea::RightUpCorner() const
171 /// Return position of the right up corner.
173 return TVector2(RightBorder(), UpBorder());
176 //_____________________________________________________________________________
177 Bool_t AliMpArea::Contains(const AliMpArea& area) const
179 /// Whether area is contained within this
182 // ( area.LeftBorder() > LeftBorder() - AliMpConstants::LengthTolerance() &&
183 // area.RightBorder() < RightBorder() + AliMpConstants::LengthTolerance() &&
184 // area.DownBorder() > DownBorder() - AliMpConstants::LengthTolerance() &&
185 // area.UpBorder() < UpBorder() + AliMpConstants::LengthTolerance() );
187 if ( area.LeftBorder() < LeftBorder() ||
188 area.RightBorder() > RightBorder() ||
189 area.DownBorder() < DownBorder() ||
190 area.UpBorder() > UpBorder() )
200 //_____________________________________________________________________________
201 AliMpArea AliMpArea::Intersect(const AliMpArea& area) const
203 /// Return the common part of area and this
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());
210 return AliMpArea( TVector2( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ),
211 TVector2( (xmax-xmin)/2.0, (ymax-ymin)/2.0 ) );
214 //_____________________________________________________________________________
215 Bool_t AliMpArea::Overlap(const AliMpArea& area) const
217 /// Return true if this overlaps with given area
219 if ( LeftBorder() > area.RightBorder() - AliMpConstants::LengthTolerance() ||
220 RightBorder() < area.LeftBorder() + AliMpConstants::LengthTolerance() )
225 if ( DownBorder() > area.UpBorder() - AliMpConstants::LengthTolerance() ||
226 UpBorder() < area.DownBorder() + AliMpConstants::LengthTolerance() )
234 //_____________________________________________________________________________
236 AliMpArea::Print(Option_t* opt) const
239 /// When option is set to B (borders), the area boreders will be printed
240 /// instead of default parameters
243 if ( opt[0] == 'B' ) {
244 cout << "Area x-borders: ("
245 << LeftBorder() << ", " << RightBorder() << ") "
247 << DownBorder() << ", " << UpBorder() << ") "
253 cout << (*this) << endl;
256 //_____________________________________________________________________________
257 ostream& operator<< (ostream &stream,const AliMpArea& area)
261 stream << "Area: position: ("
262 << area.Position().X() << ", " << area.Position().Y() << ") "
264 << area.Dimensions().X() << ", " << area.Dimensions().Y() << ") "
265 << " valid: " << (area.IsValid()==true ? "YES":"NO")