Import Geant4 11.4.0 source tree
This commit is contained in:
@@ -27,98 +27,169 @@
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// Utility class used to specify, test, reduce, and/or otherwise
|
||||
// manipulate a 2D polygon.
|
||||
// Utility class used to specify, test, reduce, and/or otherwise
|
||||
// manipulate a 2D polygon.
|
||||
//
|
||||
// For this class, a polygon consists of n > 2 points in 2D
|
||||
// space (a,b). The polygon is always closed by connecting the
|
||||
// last point to the first. A G4ReduciblePolygon is guaranteed
|
||||
// to fulfill this definition in all instances.
|
||||
// For this class, a polygon consists of n > 2 points in 2D
|
||||
// space (a,b). The polygon is always closed by connecting the
|
||||
// last point to the first. A G4ReduciblePolygon is guaranteed
|
||||
// to fulfill this definition in all instances.
|
||||
//
|
||||
// Illegal manipulations (such that a valid polygon would be
|
||||
// produced) result in an error return if possible and
|
||||
// otherwise a G4Exception.
|
||||
// Illegal manipulations (such that a valid polygon would be
|
||||
// produced) result in an error return if possible and
|
||||
// otherwise a G4Exception.
|
||||
//
|
||||
// The set of manipulations is limited currently to what
|
||||
// is needed for G4Polycone and G4Polyhedra.
|
||||
// The set of manipulations is limited currently to what
|
||||
// is needed for G4Polycone and G4Polyhedra.
|
||||
|
||||
// Author: David C. Williams (davidw@scipp.ucsc.edu)
|
||||
// Author: David C. Williams (UCSC), 1998
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4REDUCIBLEPOLYGON_HH
|
||||
#define G4REDUCIBLEPOLYGON_HH 1
|
||||
#define G4REDUCIBLEPOLYGON_HH
|
||||
|
||||
#include "G4Types.hh"
|
||||
|
||||
/**
|
||||
* @brief G4ReduciblePolygon is a utility class used to specify, test, reduce,
|
||||
* and/or otherwise manipulate a 2D polygon.
|
||||
*/
|
||||
|
||||
class G4ReduciblePolygon
|
||||
{
|
||||
friend class G4ReduciblePolygonIterator;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor of G4ReduciblePolygon via simple a/b arrays.
|
||||
* @param[in] a First array of points.
|
||||
* @param[in] b Second array of points.
|
||||
* @param[in] n The number of vertices of the polygon (has to be >=3).
|
||||
*/
|
||||
G4ReduciblePolygon( const G4double a[], const G4double b[], G4int n );
|
||||
// Creator: via simple a/b arrays
|
||||
|
||||
/**
|
||||
* Special constructor version for G4Polyhedra and G4Polycone, that takes
|
||||
* two a points at planes of b (where a==r and b==z).
|
||||
* @param[in] rmin Array of r-min coordinates of corners.
|
||||
* @param[in] rmax Array of r-max coordinates of corners.
|
||||
* @param[in] z Array of Z coordinates of corners.
|
||||
* @param[in] n The number of vertices of the polygon.
|
||||
*/
|
||||
G4ReduciblePolygon( const G4double rmin[], const G4double rmax[],
|
||||
const G4double z[], G4int n );
|
||||
// Creator: a special version for G4Polygon and G4Polycone
|
||||
// that takes two a points at planes of b
|
||||
// (where a==r and b==z for the GEANT3 classic PCON and PGON)
|
||||
|
||||
/**
|
||||
* Copy constructor and assignment operator not allowed.
|
||||
*/
|
||||
G4ReduciblePolygon(const G4ReduciblePolygon&) = delete;
|
||||
G4ReduciblePolygon& operator=(const G4ReduciblePolygon&) = delete;
|
||||
// Deleted copy constructor and assignment operator.
|
||||
|
||||
virtual ~G4ReduciblePolygon();
|
||||
/**
|
||||
* Destructor, taking care to clear allocated lists.
|
||||
*/
|
||||
~G4ReduciblePolygon();
|
||||
|
||||
// Queries
|
||||
|
||||
/**
|
||||
* Accessors.
|
||||
*/
|
||||
inline G4int NumVertices() const { return numVertices; }
|
||||
|
||||
inline G4double Amin() const { return aMin; }
|
||||
inline G4double Amax() const { return aMax; }
|
||||
inline G4double Bmin() const { return bMin; }
|
||||
inline G4double Bmax() const { return bMax; }
|
||||
|
||||
/**
|
||||
* Copies contents of provided arrays into simple linear arrays.
|
||||
*/
|
||||
void CopyVertices( G4double a[], G4double b[] ) const;
|
||||
|
||||
// Manipulations
|
||||
|
||||
/**
|
||||
* Methods to multiply all a or b values by a common scale.
|
||||
*/
|
||||
void ScaleA( G4double scale );
|
||||
void ScaleB( G4double scale );
|
||||
|
||||
/**
|
||||
* Removes adjacent vertices that are equal.
|
||||
* @param[in] tolerance Provided tolerance for adjacent vertices.
|
||||
* @returns false, if there is a problem (too few vertices remaining).
|
||||
*/
|
||||
G4bool RemoveDuplicateVertices( G4double tolerance );
|
||||
|
||||
/**
|
||||
* Removes any unneeded vertices, i.e. those vertices which are on the
|
||||
* line connecting the previous and next vertices.
|
||||
* @param[in] tolerance Provided tolerance for parallel line segments.
|
||||
* @returns false, if there is a problem (too few vertices remaining).
|
||||
*/
|
||||
G4bool RemoveRedundantVertices( G4double tolerance );
|
||||
|
||||
/**
|
||||
* Reverses the order of the vertices.
|
||||
*/
|
||||
void ReverseOrder();
|
||||
|
||||
/**
|
||||
* Method is used for G4GenericPolycone; starting always with Zmin=bMin.
|
||||
*/
|
||||
void StartWithZMin();
|
||||
|
||||
// Tests
|
||||
//
|
||||
G4double Area();
|
||||
G4bool CrossesItself( G4double tolerance );
|
||||
G4bool BisectedBy( G4double a1, G4double b1,
|
||||
G4double a2, G4double b2, G4double tolerance );
|
||||
|
||||
void Print(); // Debugging only
|
||||
|
||||
G4ReduciblePolygon(__void__&);
|
||||
// Fake default constructor for usage restricted to direct object
|
||||
// persistency for clients requiring preallocation of memory for
|
||||
// persistifiable objects.
|
||||
// Methods for tests
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Calculates signed polygon area, where polygons specified in a
|
||||
* clockwise manner have negative area.
|
||||
*/
|
||||
G4double Area();
|
||||
|
||||
/**
|
||||
* Returns "true" if the polygon crosses itself.
|
||||
*/
|
||||
G4bool CrossesItself( G4double tolerance );
|
||||
|
||||
/**
|
||||
* Decides if a line through two points crosses the polygon,
|
||||
* within tolerance.
|
||||
*/
|
||||
G4bool BisectedBy( G4double a1, G4double b1,
|
||||
G4double a2, G4double b2, G4double tolerance );
|
||||
|
||||
/**
|
||||
* Print function for debugging.
|
||||
*/
|
||||
void Print();
|
||||
|
||||
/**
|
||||
* Fake default constructor for usage restricted to direct object
|
||||
* persistency for clients requiring preallocation of memory for
|
||||
* persistifiable objects.
|
||||
*/
|
||||
G4ReduciblePolygon(__void__&);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Create the polygon; used in constructors.
|
||||
*/
|
||||
void Create( const G4double a[], const G4double b[], G4int n );
|
||||
|
||||
/**
|
||||
* Re-calculates global values. To be called when the vertices are changed.
|
||||
*/
|
||||
void CalculateMaxMin();
|
||||
|
||||
// Below are member values that are *always* kept up to date (please!)
|
||||
private:
|
||||
|
||||
// Below are member values that are *always* kept up to date
|
||||
//
|
||||
G4double aMin, aMax, bMin, bMax;
|
||||
G4int numVertices = 0;
|
||||
|
||||
// A subclass which holds the vertices in a single-linked list
|
||||
//
|
||||
|
||||
/**
|
||||
* A subclass which holds the vertices in a single-linked list.
|
||||
*/
|
||||
struct ABVertex; // Secret recipe for allowing
|
||||
friend struct ABVertex; // protected nested structures
|
||||
struct ABVertex
|
||||
@@ -134,29 +205,35 @@ class G4ReduciblePolygon
|
||||
// A companion class for iterating over the vertices of our polygon.
|
||||
// It is simple enough that all routines are declared inline here.
|
||||
//
|
||||
|
||||
/**
|
||||
* @brief G4ReduciblePolygonIterator is companion class for iterating over
|
||||
* the vertices of a polygon.
|
||||
*/
|
||||
|
||||
class G4ReduciblePolygonIterator
|
||||
{
|
||||
public:
|
||||
|
||||
G4ReduciblePolygonIterator( const G4ReduciblePolygon* theSubject )
|
||||
inline G4ReduciblePolygonIterator( const G4ReduciblePolygon* theSubject )
|
||||
{
|
||||
subject = theSubject; current = nullptr;
|
||||
}
|
||||
|
||||
void Begin() { current = subject->vertexHead; }
|
||||
inline void Begin() { current = subject->vertexHead; }
|
||||
|
||||
G4bool Next()
|
||||
inline G4bool Next()
|
||||
{
|
||||
if (current != nullptr) current=current->next;
|
||||
if (current != nullptr) { current=current->next; }
|
||||
return Valid();
|
||||
}
|
||||
|
||||
G4bool Valid() const { return current != nullptr; }
|
||||
inline G4bool Valid() const { return current != nullptr; }
|
||||
|
||||
G4double GetA() const { return current->a; }
|
||||
G4double GetB() const { return current->b; }
|
||||
inline G4double GetA() const { return current->a; }
|
||||
inline G4double GetB() const { return current->b; }
|
||||
|
||||
protected:
|
||||
private:
|
||||
|
||||
const G4ReduciblePolygon* subject = nullptr; // Who are we iterating over
|
||||
G4ReduciblePolygon::ABVertex* current = nullptr; // Current vertex
|
||||
|
||||
Reference in New Issue
Block a user