BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSExtent.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef BDSEXTENT_H
20#define BDSEXTENT_H
21
22#include <ostream>
23#include <utility> // for pair and pair relational operators
24#include <vector>
25
26#include "globals.hh" // geant4 types / globals
27#include "G4ThreeVector.hh"
28
30class BDSTiltOffset;
31
39{
40public:
42 BDSExtent();
44 BDSExtent(const std::pair<G4double, G4double>& extXIn,
45 const std::pair<G4double, G4double>& extYIn,
46 const std::pair<G4double, G4double>& extZIn);
48 BDSExtent(G4double extXNegIn, G4double extXPosIn,
49 G4double extYNegIn, G4double extYPosIn,
50 G4double extZNegIn, G4double extZPosIn);
52 BDSExtent(G4double extXIn, G4double extYIn, G4double extZIn);
54 BDSExtent(G4ThreeVector extInNeg, G4ThreeVector extInPos);
56 explicit BDSExtent(G4ThreeVector extIn);
57
58 virtual ~BDSExtent();
59
61 inline std::pair<G4double, G4double> ExtentX() const {return std::make_pair(extXNeg, extXPos);}
62 inline std::pair<G4double, G4double> ExtentY() const {return std::make_pair(extYNeg, extYPos);}
63 inline std::pair<G4double, G4double> ExtentZ() const {return std::make_pair(extZNeg, extZPos);}
64
65 inline G4double XNeg() const {return extXNeg;}
66 inline G4double XPos() const {return extXPos;}
67 inline G4double YNeg() const {return extYNeg;}
68 inline G4double YPos() const {return extYPos;}
69 inline G4double ZNeg() const {return extZNeg;}
70 inline G4double ZPos() const {return extZPos;}
71
72 inline G4ThreeVector ExtentPositive() const
73 {return G4ThreeVector(extXPos, extYPos, extZPos);}
74
75 inline G4ThreeVector ExtentNegative() const
76 {return G4ThreeVector(extXNeg, extYNeg, extZNeg);}
77
79 std::vector<G4ThreeVector> AllBoundaryPoints() const;
81
83 inline G4double DX() const {return extXPos - extXNeg;}
84 inline G4double DY() const {return extYPos - extYNeg;}
85 inline G4double DZ() const {return extZPos - extZNeg;}
87
89 inline G4bool operator< (const BDSExtent& r) const;
90 inline G4bool operator> (const BDSExtent& r) const {return r < (*this);}
91 inline G4bool operator<=(const BDSExtent& r) const {return !((*this) > r);}
92 inline G4bool operator>=(const BDSExtent& r) const {return !((*this) < r);}
94
96 inline G4bool operator==(const BDSExtent& r) const;
97 inline G4bool operator!=(const BDSExtent& r) const {return !((*this) == r);}
99
101 inline G4bool TransverselyLessThan(const BDSExtent& r) const;
102 inline G4bool TransverselyGreaterThan(const BDSExtent& r) const {return !(this->TransverselyLessThan(r));}
103 inline G4bool TransverselyLessEquals(const BDSExtent& r) const {return !(this->TransverselyGreaterThan(r));}
104 inline G4bool TransverselyGreaterEquals(const BDSExtent& r) const {return !(this->TransverselyLessThan(r));}
106
108 G4bool Encompasses(const G4ThreeVector& point) const;
109
112 G4bool Encompasses(const BDSExtent& other) const;
113
115 G4bool Encompasses(G4double x,
116 G4double y,
117 G4double z) const {return Encompasses(G4ThreeVector(x,y,z));}
118
119 G4bool Encompasses(const BDSParticleCoords& coords) const;
120
122 BDSExtent Tilted(G4double angle) const;
123
125 BDSExtent Translate(const G4ThreeVector& offset) const {return Translate(offset.x(), offset.y(), offset.z());}
126 BDSExtent Translate(G4double dx, G4double dy, G4double dz) const;
128
130 BDSExtent TiltOffset(const BDSTiltOffset* tiltOffset) const;
131
133 friend std::ostream& operator<< (std::ostream &out, BDSExtent const &ext);
134
136 G4double MaximumAbs() const;
137
139 G4double MinimumAbs() const;
140
141 G4double MaximumX() const {return std::max(std::abs(extXNeg), std::abs(extXPos));}
142 G4double MaximumY() const {return std::max(std::abs(extYNeg), std::abs(extYPos));}
143 G4double MaximumZ() const {return std::max(std::abs(extZNeg), std::abs(extZPos));}
144
146 G4double MaximumAbsTransverse() const;
147
149 G4double MinimumAbsTransverse() const;
150
152 G4double TransverseBoundingRadius() const;
153
155 BDSExtent ExpandBy(G4double margin) const;
156
158 BDSExtent ExpandTransverselyBy(G4double margin) const;
159
162 void ExpandToEncompass(const BDSExtent& other);
163
164private:
166 G4double extXNeg;
167 G4double extXPos;
168 G4double extYNeg;
169 G4double extYPos;
170 G4double extZNeg;
171 G4double extZPos;
173};
174
175inline G4bool BDSExtent::operator<(const BDSExtent& r) const
176{
177 G4bool xOK = (extXNeg > r.extXNeg) && (extXPos < r.extXPos);
178 G4bool yOK = (extYNeg > r.extYNeg) && (extYPos < r.extYPos);
179 G4bool zOK = (extZNeg > r.extZNeg) && (extZPos < r.extZPos);
180 return xOK && yOK && zOK;
181}
182
183inline G4bool BDSExtent::operator==(const BDSExtent& r) const
184{
185 G4bool xOK = (extXNeg == r.extXNeg) && (extXPos == r.extXPos);
186 G4bool yOK = (extYNeg == r.extYNeg) && (extYPos == r.extYPos);
187 G4bool zOK = (extZNeg == r.extZNeg) && (extZPos == r.extZPos);
188 return xOK && yOK && zOK;
189}
190
191inline G4bool BDSExtent::TransverselyLessThan(const BDSExtent& r) const
192{
193 G4bool xOK = (extXNeg > r.extXNeg) && (extXPos < r.extXPos);
194 G4bool yOK = (extYNeg > r.extYNeg) && (extYPos < r.extYPos);
195 return xOK && yOK;
196}
197
198namespace BDS
199{
201 BDSExtent MaximumCombinedExtent(const BDSExtent& first, const BDSExtent& second);
202}
203
204#endif
Holder for +- extents in 3 dimensions.
Definition: BDSExtent.hh:39
std::pair< G4double, G4double > ExtentX() const
Accessor.
Definition: BDSExtent.hh:61
G4double XPos() const
Accessor.
Definition: BDSExtent.hh:66
BDSExtent Tilted(G4double angle) const
Provide a new copy of this extent but rotated along Z by a given tilt angle.
Definition: BDSExtent.cc:121
BDSExtent Translate(const G4ThreeVector &offset) const
Provide a new copy of this extent with an offset applied.
Definition: BDSExtent.hh:125
G4bool operator==(const BDSExtent &r) const
Equality operator.
Definition: BDSExtent.hh:183
G4ThreeVector ExtentNegative() const
Accessor.
Definition: BDSExtent.hh:75
std::vector< G4ThreeVector > AllBoundaryPoints() const
All 8 boundary points of the bounding box.
Definition: BDSExtent.cc:91
G4double extZNeg
Extent.
Definition: BDSExtent.hh:170
G4bool operator<=(const BDSExtent &r) const
Comparison operator.
Definition: BDSExtent.hh:91
G4bool TransverselyGreaterEquals(const BDSExtent &r) const
Comparison operator for x,y only. Ignores z (length).
Definition: BDSExtent.hh:104
BDSExtent()
Default constructor gives 0 in all extents - typically unphysical.
Definition: BDSExtent.cc:34
G4bool TransverselyGreaterThan(const BDSExtent &r) const
Comparison operator for x,y only. Ignores z (length).
Definition: BDSExtent.hh:102
G4bool Encompasses(G4double x, G4double y, G4double z) const
Return whether the extent encompasses the point. Similar, but with separate x,y,z coordinates.
Definition: BDSExtent.hh:115
G4bool operator>=(const BDSExtent &r) const
Comparison operator.
Definition: BDSExtent.hh:92
G4bool operator>(const BDSExtent &r) const
Comparison operator.
Definition: BDSExtent.hh:90
friend std::ostream & operator<<(std::ostream &out, BDSExtent const &ext)
Output stream.
Definition: BDSExtent.cc:149
G4double extZPos
Extent.
Definition: BDSExtent.hh:171
G4double ZPos() const
Accessor.
Definition: BDSExtent.hh:70
G4ThreeVector ExtentPositive() const
Accessor.
Definition: BDSExtent.hh:72
G4double MaximumAbsTransverse() const
Return the maximum absolute value considering only x,y.
Definition: BDSExtent.cc:171
BDSExtent ExpandBy(G4double margin) const
Return a copy expanded in all dimensions by the given margin.
Definition: BDSExtent.cc:213
G4bool Encompasses(const G4ThreeVector &point) const
Return whether the extent encompasses the point. True if point lies inside the extent.
Definition: BDSExtent.cc:190
G4double MaximumAbs() const
Return the maximum absolute value considering all dimensions.
Definition: BDSExtent.cc:157
void ExpandToEncompass(const BDSExtent &other)
Definition: BDSExtent.cc:236
G4double XNeg() const
Accessor.
Definition: BDSExtent.hh:65
G4bool operator!=(const BDSExtent &r) const
Equality operator.
Definition: BDSExtent.hh:97
G4double extYNeg
Extent.
Definition: BDSExtent.hh:168
G4double extYPos
Extent.
Definition: BDSExtent.hh:169
G4double DZ() const
The difference in a dimension.
Definition: BDSExtent.hh:85
G4double YNeg() const
Accessor.
Definition: BDSExtent.hh:67
G4bool operator<(const BDSExtent &r) const
Comparison operator.
Definition: BDSExtent.hh:175
BDSExtent TiltOffset(const BDSTiltOffset *tiltOffset) const
Provide a new copy of this extent with both a tilt and an offset applied.
Definition: BDSExtent.cc:105
G4double extXPos
Extent.
Definition: BDSExtent.hh:167
std::pair< G4double, G4double > ExtentZ() const
Accessor.
Definition: BDSExtent.hh:63
G4double MinimumAbsTransverse() const
Return the minimum absolute value considering only x,y.
Definition: BDSExtent.cc:177
G4double DX() const
The difference in a dimension.
Definition: BDSExtent.hh:83
std::pair< G4double, G4double > ExtentY() const
Accessor.
Definition: BDSExtent.hh:62
G4double MinimumAbs() const
Return the minimum absolute value considering all dimensions.
Definition: BDSExtent.cc:164
G4bool TransverselyLessEquals(const BDSExtent &r) const
Comparison operator for x,y only. Ignores z (length).
Definition: BDSExtent.hh:103
G4double DY() const
The difference in a dimension.
Definition: BDSExtent.hh:84
G4bool TransverselyLessThan(const BDSExtent &r) const
Comparison operator for x,y only. Ignores z (length).
Definition: BDSExtent.hh:191
BDSExtent ExpandTransverselyBy(G4double margin) const
Return a copy expanded in x and y by the given margin.
Definition: BDSExtent.cc:226
G4double YPos() const
Accessor.
Definition: BDSExtent.hh:68
G4double extXNeg
Extent.
Definition: BDSExtent.hh:166
G4double ZNeg() const
Accessor.
Definition: BDSExtent.hh:69
G4double TransverseBoundingRadius() const
Return a radius that would encompass the maximum x,y extent.
Definition: BDSExtent.cc:183
A set of particle coordinates.
A holder for any placement offsets and rotations for a BDSAcceleratorComponent.
Return either G4Tubs or G4CutTubs depending on flat face.
BDSExtent MaximumCombinedExtent(const BDSExtent &first, const BDSExtent &second)
Returns the extent which is the greatest extent in all six directions.
Definition: BDSExtent.cc:248