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