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>
41 //_____________________________________________________________________________
42 AliMpArea::AliMpArea(Double_t x, Double_t y,
43 Double_t dx, Double_t dy)
51 /// Standard constructor
54 if ( fDimensionX < - AliMpConstants::LengthTolerance() ||
55 fDimensionY < - AliMpConstants::LengthTolerance() ||
56 ( fDimensionX < AliMpConstants::LengthTolerance() &&
57 fDimensionY < AliMpConstants::LengthTolerance() ) )
65 //_____________________________________________________________________________
66 AliMpArea::AliMpArea()
74 /// Default constructor
77 //_____________________________________________________________________________
78 AliMpArea::AliMpArea(const AliMpArea& rhs):
80 fPositionX(rhs.fPositionX),
81 fPositionY(rhs.fPositionY),
82 fDimensionX(rhs.fDimensionX),
83 fDimensionY(rhs.fDimensionY),
84 fValidity(rhs.fValidity)
89 //_____________________________________________________________________________
90 AliMpArea::~AliMpArea()
99 //______________________________________________________________________________
100 AliMpArea& AliMpArea::operator = (const AliMpArea& right)
102 /// Assignment operator
104 // check assignment to self
105 if (this == &right) return *this;
107 // base class assignment
108 TObject::operator=(right);
110 fPositionX = right.fPositionX;
111 fPositionY = right.fPositionY;
112 fDimensionX = right.fDimensionX;
113 fDimensionY = right.fDimensionY;
114 fValidity = right.fValidity;
123 //_____________________________________________________________________________
124 Double_t AliMpArea::LeftBorder() const
126 /// Return the position of the left edge.
128 return fPositionX - fDimensionX;
131 //_____________________________________________________________________________
132 Double_t AliMpArea::RightBorder() const
134 /// Return the position of right edge.
136 return fPositionX + fDimensionX;
139 //_____________________________________________________________________________
140 Double_t AliMpArea::UpBorder() const
142 /// Return the position of the up edge.
144 return fPositionY + fDimensionY;
147 //_____________________________________________________________________________
148 Double_t AliMpArea::DownBorder() const
150 /// Return the position of the down edge.
152 return fPositionY - fDimensionY;
155 //_____________________________________________________________________________
156 void AliMpArea::LeftDownCorner(Double_t& x, Double_t& y) const
158 /// Return position of the left down corner.
164 //_____________________________________________________________________________
165 void AliMpArea::LeftUpCorner(Double_t& x, Double_t& y) const
167 /// Return position of the left up corner.
173 //_____________________________________________________________________________
174 void AliMpArea::RightDownCorner(Double_t& x, Double_t& y) const
176 /// Return position of the right down corner.
183 //_____________________________________________________________________________
184 void AliMpArea::RightUpCorner(Double_t& x, Double_t& y) const
186 /// Return position of the right up corner.
192 //_____________________________________________________________________________
193 Bool_t AliMpArea::Contains(const AliMpArea& area) const
195 /// Whether area is contained within this
198 // ( area.LeftBorder() > LeftBorder() - AliMpConstants::LengthTolerance() &&
199 // area.RightBorder() < RightBorder() + AliMpConstants::LengthTolerance() &&
200 // area.DownBorder() > DownBorder() - AliMpConstants::LengthTolerance() &&
201 // area.UpBorder() < UpBorder() + AliMpConstants::LengthTolerance() );
203 if ( area.LeftBorder() < LeftBorder() ||
204 area.RightBorder() > RightBorder() ||
205 area.DownBorder() < DownBorder() ||
206 area.UpBorder() > UpBorder() )
216 //_____________________________________________________________________________
217 AliMpArea AliMpArea::Intersect(const AliMpArea& area) const
219 /// Return the common part of area and this
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());
226 return AliMpArea( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ,
227 (xmax-xmin)/2.0, (ymax-ymin)/2.0 );
230 //_____________________________________________________________________________
231 Bool_t AliMpArea::Overlap(const AliMpArea& area) const
233 /// Return true if this overlaps with given area
235 if ( LeftBorder() > area.RightBorder() - AliMpConstants::LengthTolerance() ||
236 RightBorder() < area.LeftBorder() + AliMpConstants::LengthTolerance() )
241 if ( DownBorder() > area.UpBorder() - AliMpConstants::LengthTolerance() ||
242 UpBorder() < area.DownBorder() + AliMpConstants::LengthTolerance() )
250 //_____________________________________________________________________________
252 AliMpArea::Print(Option_t* opt) const
255 /// When option is set to B (borders), the area boreders will be printed
256 /// instead of default parameters
259 if ( opt[0] == 'B' ) {
260 cout << "Area x-borders: ("
261 << LeftBorder() << ", " << RightBorder() << ") "
263 << DownBorder() << ", " << UpBorder() << ") "
269 cout << (*this) << endl;
272 //_____________________________________________________________________________
274 AliMpArea::GetParameters(Double_t& x, Double_t& y,
275 Double_t& dx, Double_t& dy) const
277 /// Fill the parameters: x, y position and dimensions
285 //_____________________________________________________________________________
286 ostream& operator<< (ostream &stream,const AliMpArea& area)
290 stream << "Area: position: ("
291 << area.GetPositionX() << ", " << area.GetPositionY() << ") "
293 << area.GetDimensionX() << ", " << area.GetDimensionY() << ") "
294 << " valid: " << (area.IsValid()==true ? "YES":"NO")