LCOV - code coverage report
Current view: top level - MUON/MUONgraphics - AliMUONPolygon.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 80 1.2 %
Date: 2016-06-14 17:26:59 Functions: 1 17 5.9 %

          Line data    Source code
       1             : /**************************************************************************
       2             : * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             : *                                                                        *
       4             : * Author: The ALICE Off-line Project.                                    *
       5             : * Contributors are mentioned in the code where appropriate.              *
       6             : *                                                                        *
       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             : **************************************************************************/
      15             : 
      16             : // $Id$
      17             : 
      18             : /// \class AliMUONPolygon
      19             : ///
      20             : /// A simple planar polygon, with a given orientation
      21             : ///
      22             : /// \author Laurent Aphecetche, Subatech
      23             : 
      24             : #include "AliMUONPolygon.h"
      25             : 
      26             : #include "AliLog.h"
      27             : #include "Riostream.h"
      28             : #include "TMath.h"
      29             : 
      30             : using std::cout;
      31             : using std::endl;
      32             : ///\cond CLASSIMP
      33          12 : ClassImp(AliMUONPolygon)
      34             : ///\endcond
      35             : 
      36             : //_____________________________________________________________________________
      37             : AliMUONPolygon::AliMUONPolygon(Int_t nvertices) 
      38           0 : : TObject(),
      39           0 : fN(nvertices),
      40           0 : fX(new Double_t[fN]),
      41           0 : fY(new Double_t[fN])
      42           0 : {
      43             :   /// Ctor with a predefined number of vertices.
      44           0 : }
      45             : 
      46             : //_____________________________________________________________________________
      47             : AliMUONPolygon::AliMUONPolygon(Double_t xpos, Double_t ypos, Double_t halfsizex, Double_t halfsizey)
      48           0 : : TObject(),
      49           0 : fN(5),
      50           0 : fX(new Double_t[fN]),
      51           0 : fY(new Double_t[fN])
      52           0 : {
      53             :   /// Ctor. Polygon will be a rectangle.
      54             :   
      55             :   
      56           0 :   double xmin(xpos-halfsizex);
      57           0 :   double xmax(xpos+halfsizex);
      58           0 :   double ymin(ypos-halfsizey);
      59           0 :   double ymax(ypos+halfsizey);
      60             : 
      61           0 :   SetVertex(0,xmin,ymin);
      62           0 :   SetVertex(1,xmax,ymin);
      63           0 :   SetVertex(2,xmax,ymax);
      64           0 :   SetVertex(3,xmin,ymax);
      65             :   
      66           0 :   Close();
      67           0 : }
      68             : 
      69             : 
      70             : //_____________________________________________________________________________
      71             : AliMUONPolygon::~AliMUONPolygon()
      72           0 : {
      73             :   /// dtor
      74           0 :   delete[] fX;
      75           0 :   delete[] fY;
      76           0 : }
      77             : 
      78             : //______________________________________________________________________________
      79             : AliMUONPolygon::AliMUONPolygon(const AliMUONPolygon& rhs) 
      80           0 : : TObject(rhs), 
      81           0 : fN(rhs.fN),
      82           0 : fX(0x0),
      83           0 : fY(0x0)
      84           0 : {
      85             :   /// Copy constructor.
      86             :   
      87           0 :   if ( fN > 0 ) 
      88             :   {
      89           0 :     fX = new Double_t[fN];
      90           0 :     fY = new Double_t[fN];
      91             :     
      92           0 :     for ( Int_t i = 0; i < fN; ++i )
      93             :     {
      94           0 :       fX[i] = rhs.fX[i];
      95           0 :       fY[i] = rhs.fY[i];
      96             :     }
      97             :     
      98           0 :   }
      99             :   
     100           0 : }
     101             : 
     102             : //______________________________________________________________________________
     103             : AliMUONPolygon&
     104             : AliMUONPolygon::operator=(const AliMUONPolygon& rhs)
     105             : {
     106             :   /// Assignment operator
     107           0 :   if ( this != &rhs ) 
     108             :   {
     109           0 :     static_cast<TObject&>(*this)=rhs;
     110             : 
     111           0 :     delete[] fX;
     112           0 :     delete[] fY;
     113             :     
     114           0 :     fX = 0;
     115           0 :     fY = 0;
     116             :     
     117           0 :     fN = rhs.fN;
     118             :     
     119           0 :     if ( fN > 0 ) 
     120             :     {
     121           0 :       fX = new Double_t[fN];
     122           0 :       fY = new Double_t[fN];
     123             :       
     124           0 :       for ( Int_t i = 0; i < fN; ++i )
     125             :       {
     126           0 :         fX[i] = rhs.fX[i];
     127           0 :         fY[i] = rhs.fY[i];
     128             :       }
     129             :       
     130           0 :     }
     131             :   }
     132           0 :   return *this;
     133             : }
     134             : 
     135             : //______________________________________________________________________________
     136             : Bool_t
     137             : AliMUONPolygon::Contains(Double_t x, Double_t y) const
     138             : {
     139             :   /// Whether the polygon contains point (x,y)
     140             :   
     141             :   // Note that the polygon must be a closed polygon (1st and last point
     142             :   // must be identical), which should be the case here.
     143             : 
     144           0 :   return TMath::IsInside(x,y,fN,fX,fY);
     145             : }
     146             : 
     147             : //_____________________________________________________________________________
     148             : void
     149             : AliMUONPolygon::Close()
     150             : {
     151             :   /// Make that last point = first point
     152             :   
     153           0 :   SetVertex(fN-1,X(0),Y(0));
     154           0 : }
     155             : 
     156             : //_____________________________________________________________________________
     157             : void AliMUONPolygon::Print(Option_t*) const
     158             : {
     159             :   /// Printout
     160           0 :   cout << Form("AliMUONPolygon : %3d vertices. Signed Area=%e",NumberOfVertices(),SignedArea()) << endl;
     161           0 :   for ( Int_t i = 0; i < NumberOfVertices(); ++i )
     162             :   {
     163           0 :     cout << Form("%10.5f,%10.5f",X(i),Y(i)) << endl;
     164             :   }
     165           0 : }
     166             : 
     167             : //_____________________________________________________________________________
     168             : Double_t 
     169             : AliMUONPolygon::SignedArea() const
     170             : {
     171             :   /// Compute the signed area of this polygon
     172             :   /// Algorithm from F. Feito, J.C. Torres and A. Urena,
     173             :   /// Comput. & Graphics, Vol. 19, pp. 595-600, 1995
     174             :   
     175             :   Double_t area(0.0);
     176             :   
     177           0 :   for ( Int_t i = 0; i < NumberOfVertices()-1; ++i ) 
     178             :   {
     179           0 :     area += X(i)*Y(i+1) - X(i+1)*Y(i);
     180             :   }
     181             :  
     182           0 :   return area;
     183             : }
     184             : 
     185             : //_____________________________________________________________________________
     186             : void 
     187             : AliMUONPolygon::ReverseOrientation()
     188             : {
     189             :   /// Reverse the orientation of this polygon
     190           0 :   Double_t* x = new Double_t[fN];
     191           0 :   Double_t* y = new Double_t[fN];
     192             :   
     193           0 :   for ( Int_t i = fN-1; i >= 0; --i )
     194             :   {
     195           0 :     x[i] = X(fN-i-1);
     196           0 :     y[i] = Y(fN-i-1);
     197             :   }
     198             : 
     199           0 :   delete[] fX;
     200           0 :   delete[] fY;
     201             :   
     202           0 :   fX = x;
     203           0 :   fY = y;
     204           0 : }
     205             : 
     206             : //_____________________________________________________________________________
     207             : void 
     208             : AliMUONPolygon::SetVertex(Int_t i, Double_t x, Double_t y)
     209             : {
     210             :   /// Set one vertex
     211           0 :   if ( i >= fN ) 
     212             :   {
     213           0 :     AliFatal("Wrong index");
     214           0 :   }
     215           0 :   fX[i] = x;
     216           0 :   fY[i] = y;
     217           0 : }
     218             : 

Generated by: LCOV version 1.11