ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

// $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>

using std::cout;
using std::endl;
/// \cond CLASSIMP
ClassImp(AliMpArea)
/// \endcond

//_____________________________________________________________________________
AliMpArea::AliMpArea(Double_t x, Double_t y, 
                     Double_t dx, Double_t dy)
  : TObject(),
    fPositionX(x),
    fPositionY(y),
    fDimensionX(dx),
    fDimensionY(dy),
    fValidity(true) 
{
/// Standard constructor

  // Check dimensions
  if (  fDimensionX < - AliMpConstants::LengthTolerance() || 
        fDimensionY < - AliMpConstants::LengthTolerance() || 
      ( fDimensionX < AliMpConstants::LengthTolerance() && 
        fDimensionY < AliMpConstants::LengthTolerance() ) )
  {
    fDimensionX = 0.;
    fDimensionY = 0.;
    fValidity = false;
  }  
}

//_____________________________________________________________________________
AliMpArea::AliMpArea()
  : TObject(),
    fPositionX(0.),
    fPositionY(0.),
    fDimensionX(0.),
    fDimensionY(0.),
    fValidity(false) 
{
/// Default constructor
}

//_____________________________________________________________________________
AliMpArea::AliMpArea(const AliMpArea& rhs):
  TObject(rhs),
  fPositionX(rhs.fPositionX),
  fPositionY(rhs.fPositionY),
  fDimensionX(rhs.fDimensionX), 
  fDimensionY(rhs.fDimensionY), 
  fValidity(rhs.fValidity) 
{
/// Copy constructor
}

//_____________________________________________________________________________
AliMpArea::~AliMpArea() 
{
/// Destructor
}

//
// operators
//

//______________________________________________________________________________
AliMpArea& AliMpArea::operator = (const AliMpArea& right)
{
/// Assignment operator

  // check assignment to self
  if (this == &right) return *this;

  // base class assignment
  TObject::operator=(right);

  fPositionX = right.fPositionX;
  fPositionY = right.fPositionY;
  fDimensionX = right.fDimensionX;
  fDimensionY = right.fDimensionY;
  fValidity = right.fValidity;

  return *this;
} 

//
// public methods
//

//_____________________________________________________________________________
Double_t AliMpArea::LeftBorder() const
{
/// Return the position of the left edge.

  return fPositionX - fDimensionX;
}

//_____________________________________________________________________________
Double_t AliMpArea::RightBorder() const
{
/// Return the position of right edge.

  return fPositionX + fDimensionX;
}

//_____________________________________________________________________________
Double_t AliMpArea::UpBorder() const
{
/// Return the position of the up edge.

  return fPositionY + fDimensionY;
}

//_____________________________________________________________________________
Double_t AliMpArea::DownBorder() const
{
/// Return the position of the down edge.

  return fPositionY - fDimensionY;
}

//_____________________________________________________________________________
void AliMpArea::LeftDownCorner(Double_t& x, Double_t& y) const
{
/// Return position of the left down corner.

  x = LeftBorder();
  y = DownBorder();
}  

//_____________________________________________________________________________
void AliMpArea::LeftUpCorner(Double_t& x, Double_t& y) const
{
/// Return position of the left up corner.

  x = LeftBorder();
  y = UpBorder();
}  

//_____________________________________________________________________________
void AliMpArea::RightDownCorner(Double_t& x, Double_t& y) const
{
/// Return position of the right down corner.

  x = RightBorder();
  y = DownBorder();
}  


//_____________________________________________________________________________
void AliMpArea::RightUpCorner(Double_t& x, Double_t& y) const
{
/// Return position of the right up corner.

  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;
}  

//_____________________________________________________________________________
ostream& operator<< (ostream &stream,const AliMpArea& area)
{
/// Output streaming

  stream << "Area: position: (" 
         << area.GetPositionX() << ", " << area.GetPositionY() << ") " 
	 << " dimensions: (" 
         << area.GetDimensionX() << ", " << area.GetDimensionY() << ") " 
  << " valid: " << (area.IsValid()==true ? "YES":"NO")
	 << endl;
  return stream;
}

 AliMpArea.cxx:1
 AliMpArea.cxx:2
 AliMpArea.cxx:3
 AliMpArea.cxx:4
 AliMpArea.cxx:5
 AliMpArea.cxx:6
 AliMpArea.cxx:7
 AliMpArea.cxx:8
 AliMpArea.cxx:9
 AliMpArea.cxx:10
 AliMpArea.cxx:11
 AliMpArea.cxx:12
 AliMpArea.cxx:13
 AliMpArea.cxx:14
 AliMpArea.cxx:15
 AliMpArea.cxx:16
 AliMpArea.cxx:17
 AliMpArea.cxx:18
 AliMpArea.cxx:19
 AliMpArea.cxx:20
 AliMpArea.cxx:21
 AliMpArea.cxx:22
 AliMpArea.cxx:23
 AliMpArea.cxx:24
 AliMpArea.cxx:25
 AliMpArea.cxx:26
 AliMpArea.cxx:27
 AliMpArea.cxx:28
 AliMpArea.cxx:29
 AliMpArea.cxx:30
 AliMpArea.cxx:31
 AliMpArea.cxx:32
 AliMpArea.cxx:33
 AliMpArea.cxx:34
 AliMpArea.cxx:35
 AliMpArea.cxx:36
 AliMpArea.cxx:37
 AliMpArea.cxx:38
 AliMpArea.cxx:39
 AliMpArea.cxx:40
 AliMpArea.cxx:41
 AliMpArea.cxx:42
 AliMpArea.cxx:43
 AliMpArea.cxx:44
 AliMpArea.cxx:45
 AliMpArea.cxx:46
 AliMpArea.cxx:47
 AliMpArea.cxx:48
 AliMpArea.cxx:49
 AliMpArea.cxx:50
 AliMpArea.cxx:51
 AliMpArea.cxx:52
 AliMpArea.cxx:53
 AliMpArea.cxx:54
 AliMpArea.cxx:55
 AliMpArea.cxx:56
 AliMpArea.cxx:57
 AliMpArea.cxx:58
 AliMpArea.cxx:59
 AliMpArea.cxx:60
 AliMpArea.cxx:61
 AliMpArea.cxx:62
 AliMpArea.cxx:63
 AliMpArea.cxx:64
 AliMpArea.cxx:65
 AliMpArea.cxx:66
 AliMpArea.cxx:67
 AliMpArea.cxx:68
 AliMpArea.cxx:69
 AliMpArea.cxx:70
 AliMpArea.cxx:71
 AliMpArea.cxx:72
 AliMpArea.cxx:73
 AliMpArea.cxx:74
 AliMpArea.cxx:75
 AliMpArea.cxx:76
 AliMpArea.cxx:77
 AliMpArea.cxx:78
 AliMpArea.cxx:79
 AliMpArea.cxx:80
 AliMpArea.cxx:81
 AliMpArea.cxx:82
 AliMpArea.cxx:83
 AliMpArea.cxx:84
 AliMpArea.cxx:85
 AliMpArea.cxx:86
 AliMpArea.cxx:87
 AliMpArea.cxx:88
 AliMpArea.cxx:89
 AliMpArea.cxx:90
 AliMpArea.cxx:91
 AliMpArea.cxx:92
 AliMpArea.cxx:93
 AliMpArea.cxx:94
 AliMpArea.cxx:95
 AliMpArea.cxx:96
 AliMpArea.cxx:97
 AliMpArea.cxx:98
 AliMpArea.cxx:99
 AliMpArea.cxx:100
 AliMpArea.cxx:101
 AliMpArea.cxx:102
 AliMpArea.cxx:103
 AliMpArea.cxx:104
 AliMpArea.cxx:105
 AliMpArea.cxx:106
 AliMpArea.cxx:107
 AliMpArea.cxx:108
 AliMpArea.cxx:109
 AliMpArea.cxx:110
 AliMpArea.cxx:111
 AliMpArea.cxx:112
 AliMpArea.cxx:113
 AliMpArea.cxx:114
 AliMpArea.cxx:115
 AliMpArea.cxx:116
 AliMpArea.cxx:117
 AliMpArea.cxx:118
 AliMpArea.cxx:119
 AliMpArea.cxx:120
 AliMpArea.cxx:121
 AliMpArea.cxx:122
 AliMpArea.cxx:123
 AliMpArea.cxx:124
 AliMpArea.cxx:125
 AliMpArea.cxx:126
 AliMpArea.cxx:127
 AliMpArea.cxx:128
 AliMpArea.cxx:129
 AliMpArea.cxx:130
 AliMpArea.cxx:131
 AliMpArea.cxx:132
 AliMpArea.cxx:133
 AliMpArea.cxx:134
 AliMpArea.cxx:135
 AliMpArea.cxx:136
 AliMpArea.cxx:137
 AliMpArea.cxx:138
 AliMpArea.cxx:139
 AliMpArea.cxx:140
 AliMpArea.cxx:141
 AliMpArea.cxx:142
 AliMpArea.cxx:143
 AliMpArea.cxx:144
 AliMpArea.cxx:145
 AliMpArea.cxx:146
 AliMpArea.cxx:147
 AliMpArea.cxx:148
 AliMpArea.cxx:149
 AliMpArea.cxx:150
 AliMpArea.cxx:151
 AliMpArea.cxx:152
 AliMpArea.cxx:153
 AliMpArea.cxx:154
 AliMpArea.cxx:155
 AliMpArea.cxx:156
 AliMpArea.cxx:157
 AliMpArea.cxx:158
 AliMpArea.cxx:159
 AliMpArea.cxx:160
 AliMpArea.cxx:161
 AliMpArea.cxx:162
 AliMpArea.cxx:163
 AliMpArea.cxx:164
 AliMpArea.cxx:165
 AliMpArea.cxx:166
 AliMpArea.cxx:167
 AliMpArea.cxx:168
 AliMpArea.cxx:169
 AliMpArea.cxx:170
 AliMpArea.cxx:171
 AliMpArea.cxx:172
 AliMpArea.cxx:173
 AliMpArea.cxx:174
 AliMpArea.cxx:175
 AliMpArea.cxx:176
 AliMpArea.cxx:177
 AliMpArea.cxx:178
 AliMpArea.cxx:179
 AliMpArea.cxx:180
 AliMpArea.cxx:181
 AliMpArea.cxx:182
 AliMpArea.cxx:183
 AliMpArea.cxx:184
 AliMpArea.cxx:185
 AliMpArea.cxx:186
 AliMpArea.cxx:187
 AliMpArea.cxx:188
 AliMpArea.cxx:189
 AliMpArea.cxx:190
 AliMpArea.cxx:191
 AliMpArea.cxx:192
 AliMpArea.cxx:193
 AliMpArea.cxx:194
 AliMpArea.cxx:195
 AliMpArea.cxx:196
 AliMpArea.cxx:197
 AliMpArea.cxx:198
 AliMpArea.cxx:199
 AliMpArea.cxx:200
 AliMpArea.cxx:201
 AliMpArea.cxx:202
 AliMpArea.cxx:203
 AliMpArea.cxx:204
 AliMpArea.cxx:205
 AliMpArea.cxx:206
 AliMpArea.cxx:207
 AliMpArea.cxx:208
 AliMpArea.cxx:209
 AliMpArea.cxx:210
 AliMpArea.cxx:211
 AliMpArea.cxx:212
 AliMpArea.cxx:213
 AliMpArea.cxx:214
 AliMpArea.cxx:215
 AliMpArea.cxx:216
 AliMpArea.cxx:217
 AliMpArea.cxx:218
 AliMpArea.cxx:219
 AliMpArea.cxx:220
 AliMpArea.cxx:221
 AliMpArea.cxx:222
 AliMpArea.cxx:223
 AliMpArea.cxx:224
 AliMpArea.cxx:225
 AliMpArea.cxx:226
 AliMpArea.cxx:227
 AliMpArea.cxx:228
 AliMpArea.cxx:229
 AliMpArea.cxx:230
 AliMpArea.cxx:231
 AliMpArea.cxx:232
 AliMpArea.cxx:233
 AliMpArea.cxx:234
 AliMpArea.cxx:235
 AliMpArea.cxx:236
 AliMpArea.cxx:237
 AliMpArea.cxx:238
 AliMpArea.cxx:239
 AliMpArea.cxx:240
 AliMpArea.cxx:241
 AliMpArea.cxx:242
 AliMpArea.cxx:243
 AliMpArea.cxx:244
 AliMpArea.cxx:245
 AliMpArea.cxx:246
 AliMpArea.cxx:247
 AliMpArea.cxx:248
 AliMpArea.cxx:249
 AliMpArea.cxx:250
 AliMpArea.cxx:251
 AliMpArea.cxx:252
 AliMpArea.cxx:253
 AliMpArea.cxx:254
 AliMpArea.cxx:255
 AliMpArea.cxx:256
 AliMpArea.cxx:257
 AliMpArea.cxx:258
 AliMpArea.cxx:259
 AliMpArea.cxx:260
 AliMpArea.cxx:261
 AliMpArea.cxx:262
 AliMpArea.cxx:263
 AliMpArea.cxx:264
 AliMpArea.cxx:265
 AliMpArea.cxx:266
 AliMpArea.cxx:267
 AliMpArea.cxx:268
 AliMpArea.cxx:269
 AliMpArea.cxx:270
 AliMpArea.cxx:271
 AliMpArea.cxx:272
 AliMpArea.cxx:273
 AliMpArea.cxx:274
 AliMpArea.cxx:275
 AliMpArea.cxx:276
 AliMpArea.cxx:277
 AliMpArea.cxx:278
 AliMpArea.cxx:279
 AliMpArea.cxx:280
 AliMpArea.cxx:281
 AliMpArea.cxx:282
 AliMpArea.cxx:283
 AliMpArea.cxx:284
 AliMpArea.cxx:285
 AliMpArea.cxx:286
 AliMpArea.cxx:287
 AliMpArea.cxx:288
 AliMpArea.cxx:289
 AliMpArea.cxx:290
 AliMpArea.cxx:291
 AliMpArea.cxx:292
 AliMpArea.cxx:293
 AliMpArea.cxx:294
 AliMpArea.cxx:295
 AliMpArea.cxx:296
 AliMpArea.cxx:297
 AliMpArea.cxx:298