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(Double_t x, Double_t y,
41 Double_t dx, Double_t dy)
49 /// Standard constructor
52 if ( fDimensionX < - AliMpConstants::LengthTolerance() ||
53 fDimensionY < - AliMpConstants::LengthTolerance() ||
54 ( fDimensionX < AliMpConstants::LengthTolerance() &&
55 fDimensionY < AliMpConstants::LengthTolerance() ) )
63 //_____________________________________________________________________________
64 AliMpArea::AliMpArea()
72 /// Default constructor
75 //_____________________________________________________________________________
76 AliMpArea::AliMpArea(const AliMpArea& rhs):
78 fPositionX(rhs.fPositionX),
79 fPositionY(rhs.fPositionY),
80 fDimensionX(rhs.fDimensionX),
81 fDimensionY(rhs.fDimensionY),
82 fValidity(rhs.fValidity)
87 //_____________________________________________________________________________
88 AliMpArea::~AliMpArea()
97 //______________________________________________________________________________
98 AliMpArea& AliMpArea::operator = (const AliMpArea& right)
100 /// Assignment operator
102 // check assignment to self
103 if (this == &right) return *this;
105 // base class assignment
106 TObject::operator=(right);
108 fPositionX = right.fPositionX;
109 fPositionY = right.fPositionY;
110 fDimensionX = right.fDimensionX;
111 fDimensionY = right.fDimensionY;
112 fValidity = right.fValidity;
121 //_____________________________________________________________________________
122 Double_t AliMpArea::LeftBorder() const
124 /// Return the position of the left edge.
126 return fPositionX - fDimensionX;
129 //_____________________________________________________________________________
130 Double_t AliMpArea::RightBorder() const
132 /// Return the position of right edge.
134 return fPositionX + fDimensionX;
137 //_____________________________________________________________________________
138 Double_t AliMpArea::UpBorder() const
140 /// Return the position of the up edge.
142 return fPositionY + fDimensionY;
145 //_____________________________________________________________________________
146 Double_t AliMpArea::DownBorder() const
148 /// Return the position of the down edge.
150 return fPositionY - fDimensionY;
153 //_____________________________________________________________________________
154 void AliMpArea::LeftDownCorner(Double_t& x, Double_t& y) const
156 /// Return position of the left down corner.
162 //_____________________________________________________________________________
163 void AliMpArea::LeftUpCorner(Double_t& x, Double_t& y) const
165 /// Return position of the left up corner.
171 //_____________________________________________________________________________
172 void AliMpArea::RightDownCorner(Double_t& x, Double_t& y) const
174 /// Return position of the right down corner.
181 //_____________________________________________________________________________
182 void AliMpArea::RightUpCorner(Double_t& x, Double_t& y) const
184 /// Return position of the right up corner.
190 //_____________________________________________________________________________
191 Bool_t AliMpArea::Contains(const AliMpArea& area) const
193 /// Whether area is contained within this
196 // ( area.LeftBorder() > LeftBorder() - AliMpConstants::LengthTolerance() &&
197 // area.RightBorder() < RightBorder() + AliMpConstants::LengthTolerance() &&
198 // area.DownBorder() > DownBorder() - AliMpConstants::LengthTolerance() &&
199 // area.UpBorder() < UpBorder() + AliMpConstants::LengthTolerance() );
201 if ( area.LeftBorder() < LeftBorder() ||
202 area.RightBorder() > RightBorder() ||
203 area.DownBorder() < DownBorder() ||
204 area.UpBorder() > UpBorder() )
214 //_____________________________________________________________________________
215 AliMpArea AliMpArea::Intersect(const AliMpArea& area) const
217 /// Return the common part of area and this
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());
224 return AliMpArea( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ,
225 (xmax-xmin)/2.0, (ymax-ymin)/2.0 );
228 //_____________________________________________________________________________
229 Bool_t AliMpArea::Overlap(const AliMpArea& area) const
231 /// Return true if this overlaps with given area
233 if ( LeftBorder() > area.RightBorder() - AliMpConstants::LengthTolerance() ||
234 RightBorder() < area.LeftBorder() + AliMpConstants::LengthTolerance() )
239 if ( DownBorder() > area.UpBorder() - AliMpConstants::LengthTolerance() ||
240 UpBorder() < area.DownBorder() + AliMpConstants::LengthTolerance() )
248 //_____________________________________________________________________________
250 AliMpArea::Print(Option_t* opt) const
253 /// When option is set to B (borders), the area boreders will be printed
254 /// instead of default parameters
257 if ( opt[0] == 'B' ) {
258 cout << "Area x-borders: ("
259 << LeftBorder() << ", " << RightBorder() << ") "
261 << DownBorder() << ", " << UpBorder() << ") "
267 cout << (*this) << endl;
270 //_____________________________________________________________________________
272 AliMpArea::GetParameters(Double_t& x, Double_t& y,
273 Double_t& dx, Double_t& dy) const
281 //_____________________________________________________________________________
282 ostream& operator<< (ostream &stream,const AliMpArea& area)
286 stream << "Area: position: ("
287 << area.GetPositionX() << ", " << area.GetPositionY() << ") "
289 << area.GetDimensionX() << ", " << area.GetDimensionY() << ") "
290 << " valid: " << (area.IsValid()==true ? "YES":"NO")