// $Id$
// $MpId: AliMpArea.cxx,v 1.8 2006/05/24 13:58:29 ivana Exp $
// Category: basic
-//
+
+//-----------------------------------------------------------------------------
// Class AliMpArea
// ----------------
// Class that defines a rectangle area positioned in plane..
// Included in AliRoot: 2003/05/02
// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
+//-----------------------------------------------------------------------------
#include "AliMpArea.h"
+#include "AliLog.h"
+#include "AliMpConstants.h"
+
#include <Riostream.h>
/// \cond CLASSIMP
/// \endcond
//_____________________________________________________________________________
-AliMpArea::AliMpArea(const TVector2& position, const TVector2& dimensions)
+AliMpArea::AliMpArea(Double_t x, Double_t y,
+ Double_t dx, Double_t dy)
: TObject(),
- fPosition(position),
- fDimensions(dimensions),
+ fPositionX(x),
+ fPositionY(y),
+ fDimensionX(dx),
+ fDimensionY(dy),
fValidity(true)
{
/// Standard constructor
// Check dimensions
- if ( fDimensions.X() < 0. || fDimensions.Y() < 0. ||
- ( fDimensions.X() == 0 && fDimensions.Y() == 0.0 ) ) {
- fDimensions = TVector2();
+ if ( fDimensionX < - AliMpConstants::LengthTolerance() ||
+ fDimensionY < - AliMpConstants::LengthTolerance() ||
+ ( fDimensionX < AliMpConstants::LengthTolerance() &&
+ fDimensionY < AliMpConstants::LengthTolerance() ) )
+ {
+ fDimensionX = 0.;
+ fDimensionY = 0.;
fValidity = false;
}
}
//_____________________________________________________________________________
AliMpArea::AliMpArea()
: TObject(),
- fPosition(TVector2()),
- fDimensions(TVector2()),
+ fPositionX(0.),
+ fPositionY(0.),
+ fDimensionX(0.),
+ fDimensionY(0.),
fValidity(false)
{
/// Default constructor
//_____________________________________________________________________________
AliMpArea::AliMpArea(const AliMpArea& rhs):
TObject(rhs),
- fPosition(rhs.fPosition),
- fDimensions(rhs.fDimensions)
+ fPositionX(rhs.fPositionX),
+ fPositionY(rhs.fPositionY),
+ fDimensionX(rhs.fDimensionX),
+ fDimensionY(rhs.fDimensionY),
+ fValidity(rhs.fValidity)
{
/// Copy constructor
}
// base class assignment
TObject::operator=(right);
- fPosition = right.fPosition;
- fDimensions = right.fDimensions;
+ fPositionX = right.fPositionX;
+ fPositionY = right.fPositionY;
+ fDimensionX = right.fDimensionX;
+ fDimensionY = right.fDimensionY;
fValidity = right.fValidity;
return *this;
{
/// Return the position of the left edge.
- return fPosition.X() - fDimensions.X();
+ return fPositionX - fDimensionX;
}
//_____________________________________________________________________________
{
/// Return the position of right edge.
- return fPosition.X() + fDimensions.X();
+ return fPositionX + fDimensionX;
}
//_____________________________________________________________________________
{
/// Return the position of the up edge.
- return fPosition.Y() + fDimensions.Y();
+ return fPositionY + fDimensionY;
}
//_____________________________________________________________________________
{
/// Return the position of the down edge.
- return fPosition.Y() - fDimensions.Y();
+ return fPositionY - fDimensionY;
}
//_____________________________________________________________________________
-TVector2 AliMpArea::LeftDownCorner() const
+void AliMpArea::LeftDownCorner(Double_t& x, Double_t& y) const
{
/// Return position of the left down corner.
- return TVector2(LeftBorder(), DownBorder());
+ x = LeftBorder();
+ y = DownBorder();
}
//_____________________________________________________________________________
-TVector2 AliMpArea::LeftUpCorner() const
+void AliMpArea::LeftUpCorner(Double_t& x, Double_t& y) const
{
/// Return position of the left up corner.
- return TVector2(LeftBorder(), UpBorder());
+ x = LeftBorder();
+ y = UpBorder();
}
//_____________________________________________________________________________
-TVector2 AliMpArea::RightDownCorner() const
+void AliMpArea::RightDownCorner(Double_t& x, Double_t& y) const
{
/// Return position of the right down corner.
- return TVector2(RightBorder(), DownBorder());
+ x = RightBorder();
+ y = DownBorder();
}
//_____________________________________________________________________________
-TVector2 AliMpArea::RightUpCorner() const
+void AliMpArea::RightUpCorner(Double_t& x, Double_t& y) const
{
/// Return position of the right up corner.
- return TVector2(RightBorder(), UpBorder());
+ x = RightBorder();
+ y = UpBorder();
+}
+
+//_____________________________________________________________________________
+Bool_t AliMpArea::Contains(const AliMpArea& area) const
+{
+/// Whether area is contained within this
+
+// return
+// ( area.LeftBorder() > LeftBorder() - AliMpConstants::LengthTolerance() &&
+// area.RightBorder() < RightBorder() + AliMpConstants::LengthTolerance() &&
+// area.DownBorder() > DownBorder() - AliMpConstants::LengthTolerance() &&
+// area.UpBorder() < UpBorder() + AliMpConstants::LengthTolerance() );
+
+ if ( area.LeftBorder() < LeftBorder() ||
+ area.RightBorder() > RightBorder() ||
+ area.DownBorder() < DownBorder() ||
+ area.UpBorder() > UpBorder() )
+ {
+ return kFALSE;
+ }
+ else
+ {
+ return kTRUE;
+ }
+}
+
+//_____________________________________________________________________________
+AliMpArea AliMpArea::Intersect(const AliMpArea& area) const
+{
+/// Return the common part of area and this
+
+ Double_t xmin = TMath::Max(area.LeftBorder(),LeftBorder());
+ Double_t xmax = TMath::Min(area.RightBorder(),RightBorder());
+ Double_t ymin = TMath::Max(area.DownBorder(),DownBorder());
+ Double_t ymax = TMath::Min(area.UpBorder(),UpBorder());
+
+ return AliMpArea( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ,
+ (xmax-xmin)/2.0, (ymax-ymin)/2.0 );
+}
+
+//_____________________________________________________________________________
+Bool_t AliMpArea::Overlap(const AliMpArea& area) const
+{
+/// Return true if this overlaps with given area
+
+ if ( LeftBorder() > area.RightBorder() - AliMpConstants::LengthTolerance() ||
+ RightBorder() < area.LeftBorder() + AliMpConstants::LengthTolerance() )
+ {
+ return kFALSE;
+ }
+
+ if ( DownBorder() > area.UpBorder() - AliMpConstants::LengthTolerance() ||
+ UpBorder() < area.DownBorder() + AliMpConstants::LengthTolerance() )
+ {
+ return kFALSE;
+ }
+ return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+void
+AliMpArea::Print(Option_t* opt) const
+{
+/// Printing
+/// When option is set to B (borders), the area boreders will be printed
+/// instead of default parameters
+
+
+ if ( opt[0] == 'B' ) {
+ cout << "Area x-borders: ("
+ << LeftBorder() << ", " << RightBorder() << ") "
+ << " y-borders: ("
+ << DownBorder() << ", " << UpBorder() << ") "
+ << endl;
+ return;
+
+ }
+
+ cout << (*this) << endl;
+}
+
+//_____________________________________________________________________________
+void
+AliMpArea::GetParameters(Double_t& x, Double_t& y,
+ Double_t& dx, Double_t& dy) const
+{
+/// Fill the parameters: x, y position and dimensions
+
+ x = fPositionX;
+ y = fPositionY;
+ dx = fDimensionX;
+ dy = fDimensionY;
}
//_____________________________________________________________________________
/// Output streaming
stream << "Area: position: ("
- << area.Position().X() << ", " << area.Position().Y() << ") "
+ << area.GetPositionX() << ", " << area.GetPositionY() << ") "
<< " dimensions: ("
- << area.Dimensions().X() << ", " << area.Dimensions().Y() << ") "
+ << area.GetDimensionX() << ", " << area.GetDimensionY() << ") "
+ << " valid: " << (area.IsValid()==true ? "YES":"NO")
<< endl;
return stream;
}