Fixing a warning
[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
117 AliMUONPolygon& rhs = static_cast<AliMUONPolygon&>(obj);
118
119 Double_t* x = new Double_t[fN];
120 Double_t* y = new Double_t[fN];
121
122 for ( Int_t i = 0; i < fN; ++i )
123 {
124 x[i] = fX[i];
125 y[i] = fY[i];
126 }
127
128 delete rhs.fX;
129 delete rhs.fY;
130
131 rhs.fX = x;
132 rhs.fY = y;
133 rhs.fN = fN;
134}
135
136//_____________________________________________________________________________
137void
138AliMUONPolygon::Close()
139{
140 /// Make that last point = first point
141
142 SetVertex(fN-1,X(0),Y(0));
143}
144
145//_____________________________________________________________________________
146void AliMUONPolygon::Print(Option_t*) const
147{
148 /// Printout
149 cout << Form("AliMUONPolygon : %3d vertices. Signed Area=%e",NumberOfVertices(),SignedArea()) << endl;
150 for ( Int_t i = 0; i < NumberOfVertices(); ++i )
151 {
152 cout << Form("%10.5f,%10.5f",X(i),Y(i)) << endl;
153 }
154}
155
156//_____________________________________________________________________________
157Double_t
158AliMUONPolygon::SignedArea() const
159{
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
163
164 Double_t area(0.0);
165
166 for ( Int_t i = 0; i < NumberOfVertices()-1; ++i )
167 {
168 area += X(i)*Y(i+1) - X(i+1)*Y(i);
169 }
170
171 return area;
172}
173
174//_____________________________________________________________________________
175void
176AliMUONPolygon::ReverseOrientation()
177{
178 /// Reverse the orientation of this polygon
179 Double_t* x = new Double_t[fN];
180 Double_t* y = new Double_t[fN];
181
182 for ( Int_t i = fN-1; i >= 0; --i )
183 {
184 x[i] = X(fN-i-1);
185 y[i] = Y(fN-i-1);
186 }
187
188 delete[] fX;
189 delete[] fY;
190
191 fX = x;
192 fY = y;
193}
194
195//_____________________________________________________________________________
196void
197AliMUONPolygon::SetVertex(Int_t i, Double_t x, Double_t y)
198{
199 /// Set one vertex
200 if ( i >= fN )
201 {
202 TObject* o(0x0);
203 o->Print(); // to crash
204 }
205 fX[i] = x;
206 fY[i] = y;
207}
208