Geant4  10.00.p01
UReduciblePolygon.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * This Software is part of the AIDA Unified Solids Library package *
4 // * See: https://aidasoft.web.cern.ch/USolids *
5 // ********************************************************************
6 //
7 // $Id:$
8 //
9 // --------------------------------------------------------------------
10 //
11 // UReduciblePolygon
12 //
13 // Class description:
14 //
15 // Utility class used to specify, test, reduce, and/or otherwise
16 // manipulate a 2D polygon.
17 //
18 // For this class, a polygon consists of n > 2 points in 2D
19 // space (a,b). The polygon is always closed by connecting the
20 // last point to the first. A UReduciblePolygon is guaranteed
21 // to fulfill this definition in all instances.
22 //
23 // Illegal manipulations (such that a valid polygon would be
24 // produced) result in an error return if possible and
25 // otherwise a // UException.
26 //
27 // The Set of manipulations is limited currently to what
28 // is needed for UPolycone and UPolyhedra.
29 //
30 // 19.09.13 Marek Gayer
31 // Created from original implementation in Geant4
32 // --------------------------------------------------------------------
33 
34 #ifndef UReduciblePolygon_hh
35 #define UReduciblePolygon_hh
36 
37 #include "UTypes.hh"
38 
40 {
42 
43  public:
44  //
45  // Creator: via simple a/b arrays
46  //
47  UReduciblePolygon(const double a[], const double b[], int n);
48 
49  //
50  // Creator: a special version for UPolygon and UPolycone
51  // that takes two a points at planes of b
52  // (where a==r and b==z for the GEANT3 classic PCON and PGON)
53  //
54  UReduciblePolygon(const double rmin[], const double rmax[],
55  const double z[], int n);
56 
57  virtual ~UReduciblePolygon();
58 
59  //
60  // Queries
61  //
62  inline int NumVertices() const
63  {
64  return numVertices;
65  }
66 
67  inline double Amin() const
68  {
69  return aMin;
70  }
71  inline double Amax() const
72  {
73  return aMax;
74  }
75  inline double Bmin() const
76  {
77  return bMin;
78  }
79  inline double Bmax() const
80  {
81  return bMax;
82  }
83 
84  void CopyVertices(double a[], double b[]) const;
85 
86  //
87  // Manipulations
88  //
89  void ScaleA(double scale);
90  void ScaleB(double scale);
91 
92  bool RemoveDuplicateVertices(double tolerance);
93  bool RemoveRedundantVertices(double tolerance);
94 
95  void ReverseOrder();
96  void StartWithZMin();
97  //
98  // Tests
99  //
100  double Area();
101  bool CrossesItself(double tolerance);
102  bool BisectedBy(double a1, double b1,
103  double a2, double b2, double tolerance);
104 
105  void Print(); // Debugging only
106 
107  public: // without description
108 
109  protected:
110 
111  void Create(const double a[], const double b[], int n);
112 
113  void CalculateMaxMin();
114 
115  //
116  // Below are member values that are *always* kept up to date (please!)
117  //
118  double aMin, aMax, bMin, bMax;
120 
121  //
122  // A subclass which holds the vertices in a single-linked list
123  //
124  // Yeah, call me an old-fashioned c hacker, but I cannot make
125  // myself use the rogue tools for this trivial list.
126  //
127  struct ABVertex; // Secret recipe for allowing
128  friend struct ABVertex; // protected nested structures
129  struct ABVertex
130  {
131  ABVertex() : a(0.), b(0.), next(0) {}
132  double a, b;
134  };
135 
137 
138  private:
139 
142  // Private copy constructor and assignment operator.
143 };
144 
145 
146 //
147 // A companion class for iterating over the vertices of our polygon.
148 // It is simple enough that all routines are declared inline here.
149 //
151 {
152  public:
153 
155  {
156  subject = theSubject;
157  current = 0;
158  }
159 
160  void Begin()
161  {
163  }
164  bool Next()
165  {
166  if (current) current = current->next;
167  return Valid();
168  }
169 
170  bool Valid() const
171  {
172  return current != 0;
173  }
174 
175  double GetA() const
176  {
177  return current->a;
178  }
179  double GetB() const
180  {
181  return current->b;
182  }
183 
184  protected:
185 
186  const UReduciblePolygon* subject; // Who are we iterating over
188 };
189 
190 #endif
double Amin() const
UReduciblePolygon(const double a[], const double b[], int n)
bool RemoveRedundantVertices(double tolerance)
G4double z
Definition: TRTMaterials.hh:39
UReduciblePolygon & operator=(const UReduciblePolygon &)
static const G4double a1
void ScaleB(double scale)
UReduciblePolygonIterator(const UReduciblePolygon *theSubject)
UReduciblePolygon::ABVertex * current
void Create(const double a[], const double b[], int n)
void CopyVertices(double a[], double b[]) const
G4double a
Definition: TRTMaterials.hh:39
bool RemoveDuplicateVertices(double tolerance)
bool BisectedBy(double a1, double b1, double a2, double b2, double tolerance)
void ScaleA(double scale)
const UReduciblePolygon * subject
int NumVertices() const
static const G4double b2
double Bmin() const
const G4int n
bool CrossesItself(double tolerance)
double Amax() const
static const G4double b1
double Bmax() const
static const G4double a2