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 **************************************************************************/
18 /// \class AliMUONPolygon
20 /// A simple planar polygon, with a given orientation
22 /// \author Laurent Aphecetche, Subatech
24 #include "AliMUONPolygon.h"
27 #include "Riostream.h"
31 ClassImp(AliMUONPolygon)
34 //_____________________________________________________________________________
35 AliMUONPolygon::AliMUONPolygon(Int_t nvertices)
41 /// Ctor with a predefined number of vertices.
44 //_____________________________________________________________________________
45 AliMUONPolygon::AliMUONPolygon(Double_t xpos, Double_t ypos, Double_t halfsizex, Double_t halfsizey)
51 /// Ctor. Polygon will be a rectangle.
54 double xmin(xpos-halfsizex);
55 double xmax(xpos+halfsizex);
56 double ymin(ypos-halfsizey);
57 double ymax(ypos+halfsizey);
59 SetVertex(0,xmin,ymin);
60 SetVertex(1,xmax,ymin);
61 SetVertex(2,xmax,ymax);
62 SetVertex(3,xmin,ymax);
68 //_____________________________________________________________________________
69 AliMUONPolygon::~AliMUONPolygon()
76 //______________________________________________________________________________
77 AliMUONPolygon::AliMUONPolygon(const AliMUONPolygon& rhs)
85 ((AliMUONPolygon&)rhs).Copy(*this);
88 //______________________________________________________________________________
90 AliMUONPolygon::operator=(const AliMUONPolygon& rhs)
92 /// Assignment operator
100 //______________________________________________________________________________
102 AliMUONPolygon::Contains(Double_t x, Double_t y) const
104 /// Whether the polygon contains point (x,y)
106 // Note that the polygon must be a closed polygon (1st and last point
107 // must be identical), which should be the case here.
109 return TMath::IsInside(x,y,fN,fX,fY);
112 //______________________________________________________________________________
113 void AliMUONPolygon::Copy(TObject& obj) const
117 AliMUONPolygon& rhs = static_cast<AliMUONPolygon&>(obj);
119 Double_t* x = new Double_t[fN];
120 Double_t* y = new Double_t[fN];
122 for ( Int_t i = 0; i < fN; ++i )
136 //_____________________________________________________________________________
138 AliMUONPolygon::Close()
140 /// Make that last point = first point
142 SetVertex(fN-1,X(0),Y(0));
145 //_____________________________________________________________________________
146 void AliMUONPolygon::Print(Option_t*) const
149 cout << Form("AliMUONPolygon : %3d vertices. Signed Area=%e",NumberOfVertices(),SignedArea()) << endl;
150 for ( Int_t i = 0; i < NumberOfVertices(); ++i )
152 cout << Form("%10.5f,%10.5f",X(i),Y(i)) << endl;
156 //_____________________________________________________________________________
158 AliMUONPolygon::SignedArea() const
160 /// Compute the signed area of this polygon
161 /// Algorithm from F. Feito, J.C. Torres and A. Urena,
162 /// Comput. & Graphics, Vol. 19, pp. 595-600, 1995
166 for ( Int_t i = 0; i < NumberOfVertices()-1; ++i )
168 area += X(i)*Y(i+1) - X(i+1)*Y(i);
174 //_____________________________________________________________________________
176 AliMUONPolygon::ReverseOrientation()
178 /// Reverse the orientation of this polygon
179 Double_t* x = new Double_t[fN];
180 Double_t* y = new Double_t[fN];
182 for ( Int_t i = fN-1; i >= 0; --i )
195 //_____________________________________________________________________________
197 AliMUONPolygon::SetVertex(Int_t i, Double_t x, Double_t y)
203 o->Print(); // to crash