// @(#)root/geom:$Id$
// Author: Mihaela Gheata   05/01/04

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TGeoPolygon
#define ROOT_TGeoPolygon

#ifndef ROOT_TObject
#include "TObject.h"
#endif

#ifndef ROOT_TObjArray
#include "TObjArray.h"
#endif

////////////////////////////////////////////////////////////////////////////
//                                                                        //
// TGeoPolygon - An arbitrary polygon defined by vertices. The vertices   //
//   have to be defined CLOCKWISE in the XY plane, making either a convex //
//   or concave polygon. No test for malformed polygons is performed.     //
//                                                                        //
////////////////////////////////////////////////////////////////////////////

class TGeoPolygon : public TObject
{
public:
  enum {
      kGeoConvex        = BIT(9),
      kGeoFinishPolygon = BIT(10),
      kGeoACW           = BIT(11)
   };
protected :
// data members
   Int_t               fNvert;            // number of vertices (must be defined clockwise in XY plane)
   Int_t               fNconvex;          // number of points of the outscribed convex polygon
   Int_t              *fInd;              //[fNvert] list of vertex indices
   Int_t              *fIndc;             //[fNconvex] indices of vertices of the outscribed convex polygon
   Double_t           *fX;                //! pointer to list of current X coordinates of vertices
   Double_t           *fY;                //! pointer to list of current Y coordinates of vertices
   TObjArray          *fDaughters;        // list of concave daughters
private:
   void                ConvexCheck(); // force convexity checking
   Bool_t              IsSegConvex(Int_t i1, Int_t i2=-1) const;
   Bool_t              IsRightSided(const Double_t *point, Int_t ind1, Int_t ind2) const;
   void                OutscribedConvex();
public:
   // constructors
   TGeoPolygon();
   TGeoPolygon(Int_t nvert);
   // destructor
   virtual ~TGeoPolygon();
   // methods
   Double_t            Area() const;
   Bool_t              Contains(const Double_t *point) const;
   virtual void        Draw(Option_t *option="");
   void                FinishPolygon();
   Int_t               GetNvert() const {return fNvert;}
   Int_t               GetNconvex() const {return fNconvex;}
   Double_t           *GetX() {return fX;}
   Double_t           *GetY() {return fY;}
   void                GetVertices(Double_t *x, Double_t *y) const;
   void                GetConvexVertices(Double_t *x, Double_t *y) const;
   Bool_t              IsClockwise() const {return !TObject::TestBit(kGeoACW);}
   Bool_t              IsConvex() const {return TObject::TestBit(kGeoConvex);}
   Bool_t              IsFinished() const {return TObject::TestBit(kGeoFinishPolygon);}
   Bool_t              IsIllegalCheck() const;
   Double_t            Safety(const Double_t *point, Int_t &isegment) const;
   void                SetConvex(Bool_t flag=kTRUE) {TObject::SetBit(kGeoConvex,flag);}
   void                SetXY(Double_t *x, Double_t *y);
   void                SetNextIndex(Int_t index=-1);

   ClassDef(TGeoPolygon, 2)         // class for handling arbitrary polygons
};

#endif

 TGeoPolygon.h:1
 TGeoPolygon.h:2
 TGeoPolygon.h:3
 TGeoPolygon.h:4
 TGeoPolygon.h:5
 TGeoPolygon.h:6
 TGeoPolygon.h:7
 TGeoPolygon.h:8
 TGeoPolygon.h:9
 TGeoPolygon.h:10
 TGeoPolygon.h:11
 TGeoPolygon.h:12
 TGeoPolygon.h:13
 TGeoPolygon.h:14
 TGeoPolygon.h:15
 TGeoPolygon.h:16
 TGeoPolygon.h:17
 TGeoPolygon.h:18
 TGeoPolygon.h:19
 TGeoPolygon.h:20
 TGeoPolygon.h:21
 TGeoPolygon.h:22
 TGeoPolygon.h:23
 TGeoPolygon.h:24
 TGeoPolygon.h:25
 TGeoPolygon.h:26
 TGeoPolygon.h:27
 TGeoPolygon.h:28
 TGeoPolygon.h:29
 TGeoPolygon.h:30
 TGeoPolygon.h:31
 TGeoPolygon.h:32
 TGeoPolygon.h:33
 TGeoPolygon.h:34
 TGeoPolygon.h:35
 TGeoPolygon.h:36
 TGeoPolygon.h:37
 TGeoPolygon.h:38
 TGeoPolygon.h:39
 TGeoPolygon.h:40
 TGeoPolygon.h:41
 TGeoPolygon.h:42
 TGeoPolygon.h:43
 TGeoPolygon.h:44
 TGeoPolygon.h:45
 TGeoPolygon.h:46
 TGeoPolygon.h:47
 TGeoPolygon.h:48
 TGeoPolygon.h:49
 TGeoPolygon.h:50
 TGeoPolygon.h:51
 TGeoPolygon.h:52
 TGeoPolygon.h:53
 TGeoPolygon.h:54
 TGeoPolygon.h:55
 TGeoPolygon.h:56
 TGeoPolygon.h:57
 TGeoPolygon.h:58
 TGeoPolygon.h:59
 TGeoPolygon.h:60
 TGeoPolygon.h:61
 TGeoPolygon.h:62
 TGeoPolygon.h:63
 TGeoPolygon.h:64
 TGeoPolygon.h:65
 TGeoPolygon.h:66
 TGeoPolygon.h:67
 TGeoPolygon.h:68
 TGeoPolygon.h:69
 TGeoPolygon.h:70
 TGeoPolygon.h:71
 TGeoPolygon.h:72
 TGeoPolygon.h:73
 TGeoPolygon.h:74
 TGeoPolygon.h:75
 TGeoPolygon.h:76
 TGeoPolygon.h:77
 TGeoPolygon.h:78
 TGeoPolygon.h:79
 TGeoPolygon.h:80
 TGeoPolygon.h:81
 TGeoPolygon.h:82
 TGeoPolygon.h:83