|
||||
File indexing completed on 2025-01-18 09:59:02
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // G4ReduciblePolygon 0027 // 0028 // Class description: 0029 // 0030 // Utility class used to specify, test, reduce, and/or otherwise 0031 // manipulate a 2D polygon. 0032 // 0033 // For this class, a polygon consists of n > 2 points in 2D 0034 // space (a,b). The polygon is always closed by connecting the 0035 // last point to the first. A G4ReduciblePolygon is guaranteed 0036 // to fulfill this definition in all instances. 0037 // 0038 // Illegal manipulations (such that a valid polygon would be 0039 // produced) result in an error return if possible and 0040 // otherwise a G4Exception. 0041 // 0042 // The set of manipulations is limited currently to what 0043 // is needed for G4Polycone and G4Polyhedra. 0044 0045 // Author: David C. Williams (davidw@scipp.ucsc.edu) 0046 // -------------------------------------------------------------------- 0047 #ifndef G4REDUCIBLEPOLYGON_HH 0048 #define G4REDUCIBLEPOLYGON_HH 0049 0050 #include "G4Types.hh" 0051 0052 class G4ReduciblePolygon 0053 { 0054 friend class G4ReduciblePolygonIterator; 0055 0056 public: 0057 0058 G4ReduciblePolygon( const G4double a[], const G4double b[], G4int n ); 0059 // Creator: via simple a/b arrays 0060 0061 G4ReduciblePolygon( const G4double rmin[], const G4double rmax[], 0062 const G4double z[], G4int n ); 0063 // Creator: a special version for G4Polygon and G4Polycone 0064 // that takes two a points at planes of b 0065 // (where a==r and b==z for the GEANT3 classic PCON and PGON) 0066 0067 G4ReduciblePolygon(const G4ReduciblePolygon&) = delete; 0068 G4ReduciblePolygon& operator=(const G4ReduciblePolygon&) = delete; 0069 // Deleted copy constructor and assignment operator. 0070 0071 virtual ~G4ReduciblePolygon(); 0072 0073 // Queries 0074 0075 inline G4int NumVertices() const { return numVertices; } 0076 0077 inline G4double Amin() const { return aMin; } 0078 inline G4double Amax() const { return aMax; } 0079 inline G4double Bmin() const { return bMin; } 0080 inline G4double Bmax() const { return bMax; } 0081 0082 void CopyVertices( G4double a[], G4double b[] ) const; 0083 0084 // Manipulations 0085 0086 void ScaleA( G4double scale ); 0087 void ScaleB( G4double scale ); 0088 0089 G4bool RemoveDuplicateVertices( G4double tolerance ); 0090 G4bool RemoveRedundantVertices( G4double tolerance ); 0091 0092 void ReverseOrder(); 0093 void StartWithZMin(); 0094 0095 // Tests 0096 // 0097 G4double Area(); 0098 G4bool CrossesItself( G4double tolerance ); 0099 G4bool BisectedBy( G4double a1, G4double b1, 0100 G4double a2, G4double b2, G4double tolerance ); 0101 0102 void Print(); // Debugging only 0103 0104 G4ReduciblePolygon(__void__&); 0105 // Fake default constructor for usage restricted to direct object 0106 // persistency for clients requiring preallocation of memory for 0107 // persistifiable objects. 0108 0109 protected: 0110 0111 void Create( const G4double a[], const G4double b[], G4int n ); 0112 0113 void CalculateMaxMin(); 0114 0115 // Below are member values that are *always* kept up to date (please!) 0116 // 0117 G4double aMin, aMax, bMin, bMax; 0118 G4int numVertices = 0; 0119 0120 // A subclass which holds the vertices in a single-linked list 0121 // 0122 struct ABVertex; // Secret recipe for allowing 0123 friend struct ABVertex; // protected nested structures 0124 struct ABVertex 0125 { 0126 ABVertex() {} 0127 G4double a{0.}, b{0.}; 0128 ABVertex *next{nullptr}; 0129 }; 0130 0131 ABVertex* vertexHead = nullptr; 0132 }; 0133 0134 // A companion class for iterating over the vertices of our polygon. 0135 // It is simple enough that all routines are declared inline here. 0136 // 0137 class G4ReduciblePolygonIterator 0138 { 0139 public: 0140 0141 G4ReduciblePolygonIterator( const G4ReduciblePolygon* theSubject ) 0142 { 0143 subject = theSubject; current = nullptr; 0144 } 0145 0146 void Begin() { current = subject->vertexHead; } 0147 0148 G4bool Next() 0149 { 0150 if (current != nullptr) current=current->next; 0151 return Valid(); 0152 } 0153 0154 G4bool Valid() const { return current != nullptr; } 0155 0156 G4double GetA() const { return current->a; } 0157 G4double GetB() const { return current->b; } 0158 0159 protected: 0160 0161 const G4ReduciblePolygon* subject = nullptr; // Who are we iterating over 0162 G4ReduciblePolygon::ABVertex* current = nullptr; // Current vertex 0163 }; 0164 0165 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |