]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPolygon.cxx
Test for Coverity
[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
59e8caf1 85 ((AliMUONPolygon&)rhs).AliMUONPolygon::Copy(*this);
0b936dc0 86}
87
88//______________________________________________________________________________
89AliMUONPolygon&
90AliMUONPolygon::operator=(const AliMUONPolygon& rhs)
91{
92 /// Assignment operator
93 if ( this != &rhs )
94 {
59e8caf1 95 rhs.AliMUONPolygon::Copy(*this);
0b936dc0 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);
beeb1573 120
121 delete [] rhs.fX;
122 delete [] rhs.fY;
0b936dc0 123
beeb1573 124 rhs.fX = 0;
125 rhs.fY = 0;
126 rhs.fN = 0;
0b936dc0 127
62b6f26d 128 if ( fN > 0 )
0b936dc0 129 {
beeb1573 130 rhs.fN = fN;
131
132 rhs.fX = new Double_t[rhs.fN];
133 rhs.fY = new Double_t[rhs.fN];
62b6f26d 134
beeb1573 135 for ( Int_t i = 0; i < rhs.fN; ++i )
62b6f26d 136 {
beeb1573 137 rhs.fX[i] = fX[i];
138 rhs.fY[i] = fY[i];
62b6f26d 139 }
beeb1573 140 }
0b936dc0 141}
142
143//_____________________________________________________________________________
144void
145AliMUONPolygon::Close()
146{
147 /// Make that last point = first point
148
149 SetVertex(fN-1,X(0),Y(0));
150}
151
152//_____________________________________________________________________________
153void AliMUONPolygon::Print(Option_t*) const
154{
155 /// Printout
156 cout << Form("AliMUONPolygon : %3d vertices. Signed Area=%e",NumberOfVertices(),SignedArea()) << endl;
157 for ( Int_t i = 0; i < NumberOfVertices(); ++i )
158 {
159 cout << Form("%10.5f,%10.5f",X(i),Y(i)) << endl;
160 }
161}
162
163//_____________________________________________________________________________
164Double_t
165AliMUONPolygon::SignedArea() const
166{
167 /// Compute the signed area of this polygon
168 /// Algorithm from F. Feito, J.C. Torres and A. Urena,
169 /// Comput. & Graphics, Vol. 19, pp. 595-600, 1995
170
171 Double_t area(0.0);
172
173 for ( Int_t i = 0; i < NumberOfVertices()-1; ++i )
174 {
175 area += X(i)*Y(i+1) - X(i+1)*Y(i);
176 }
177
178 return area;
179}
180
181//_____________________________________________________________________________
182void
183AliMUONPolygon::ReverseOrientation()
184{
185 /// Reverse the orientation of this polygon
186 Double_t* x = new Double_t[fN];
187 Double_t* y = new Double_t[fN];
188
189 for ( Int_t i = fN-1; i >= 0; --i )
190 {
191 x[i] = X(fN-i-1);
192 y[i] = Y(fN-i-1);
193 }
194
195 delete[] fX;
196 delete[] fY;
197
198 fX = x;
199 fY = y;
200}
201
202//_____________________________________________________________________________
203void
204AliMUONPolygon::SetVertex(Int_t i, Double_t x, Double_t y)
205{
206 /// Set one vertex
207 if ( i >= fN )
208 {
fc2293be 209 AliFatal("Wrong index");
0b936dc0 210 }
211 fX[i] = x;
212 fY[i] = y;
213}
214