BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSExtent.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef BDSEXTENT_H
19#define BDSEXTENT_H
20
21#include <ostream>
22#include <utility> // for pair and pair relational operators
23#include <vector>
24
25#include "globals.hh" // geant4 types / globals
26#include "G4ThreeVector.hh"
27
29class BDSTiltOffset;
30
38{
39public:
41 BDSExtent();
43 BDSExtent(const std::pair<G4double, G4double>& extXIn,
44 const std::pair<G4double, G4double>& extYIn,
45 const std::pair<G4double, G4double>& extZIn);
47 BDSExtent(G4double extXNegIn, G4double extXPosIn,
48 G4double extYNegIn, G4double extYPosIn,
49 G4double extZNegIn, G4double extZPosIn);
51 BDSExtent(G4double extXIn, G4double extYIn, G4double extZIn);
53 BDSExtent(G4ThreeVector extInNeg, G4ThreeVector extInPos);
55 explicit BDSExtent(G4ThreeVector extIn);
56
57 virtual ~BDSExtent();
58
60 inline std::pair<G4double, G4double> ExtentX() const {return std::make_pair(extXNeg, extXPos);}
61 inline std::pair<G4double, G4double> ExtentY() const {return std::make_pair(extYNeg, extYPos);}
62 inline std::pair<G4double, G4double> ExtentZ() const {return std::make_pair(extZNeg, extZPos);}
63
64 inline G4double XNeg() const {return extXNeg;}
65 inline G4double XPos() const {return extXPos;}
66 inline G4double YNeg() const {return extYNeg;}
67 inline G4double YPos() const {return extYPos;}
68 inline G4double ZNeg() const {return extZNeg;}
69 inline G4double ZPos() const {return extZPos;}
70
71 inline G4ThreeVector ExtentPositive() const
72 {return G4ThreeVector(extXPos, extYPos, extZPos);}
73
74 inline G4ThreeVector ExtentNegative() const
75 {return G4ThreeVector(extXNeg, extYNeg, extZNeg);}
76
78 std::vector<G4ThreeVector> AllBoundaryPoints() const;
80
82 inline G4double DX() const {return extXPos - extXNeg;}
83 inline G4double DY() const {return extYPos - extYNeg;}
84 inline G4double DZ() const {return extZPos - extZNeg;}
86
88 inline G4bool operator< (const BDSExtent& r) const;
89 inline G4bool operator> (const BDSExtent& r) const {return r < (*this);}
90 inline G4bool operator<=(const BDSExtent& r) const {return !((*this) > r);}
91 inline G4bool operator>=(const BDSExtent& r) const {return !((*this) < r);}
93
95 inline G4bool operator==(const BDSExtent& r) const;
96 inline G4bool operator!=(const BDSExtent& r) const {return !((*this) == r);}
98
100 inline G4bool TransverselyLessThan(const BDSExtent& r) const;
101 inline G4bool TransverselyGreaterThan(const BDSExtent& r) const {return !(this->TransverselyLessThan(r));}
102 inline G4bool TransverselyLessEquals(const BDSExtent& r) const {return !(this->TransverselyGreaterThan(r));}
103 inline G4bool TransverselyGreaterEquals(const BDSExtent& r) const {return !(this->TransverselyLessThan(r));}
105
107 G4bool Encompasses(const G4ThreeVector& point) const;
108
111 G4bool Encompasses(const BDSExtent& other) const;
112
114 G4bool Encompasses(G4double x,
115 G4double y,
116 G4double z) const {return Encompasses(G4ThreeVector(x,y,z));}
117
118 G4bool Encompasses(const BDSParticleCoords& coords) const;
119
121 BDSExtent Tilted(G4double angle) const;
122
124 BDSExtent Translate(const G4ThreeVector& offset) const {return Translate(offset.x(), offset.y(), offset.z());}
125 BDSExtent Translate(G4double dx, G4double dy, G4double dz) const;
127
129 BDSExtent TiltOffset(const BDSTiltOffset* tiltOffset) const;
130
132 friend std::ostream& operator<< (std::ostream &out, BDSExtent const &ext);
133
135 G4double MaximumAbs() const;
136
138 G4double MinimumAbs() const;
139
140 G4double MaximumX() const {return std::max(std::abs(extXNeg), std::abs(extXPos));}
141 G4double MaximumY() const {return std::max(std::abs(extYNeg), std::abs(extYPos));}
142 G4double MaximumZ() const {return std::max(std::abs(extZNeg), std::abs(extZPos));}
143
145 G4double MaximumAbsTransverse() const;
146
148 G4double MinimumAbsTransverse() const;
149
151 G4double TransverseBoundingRadius() const;
152
154 BDSExtent ExpandBy(G4double margin) const;
155
157 BDSExtent ExpandTransverselyBy(G4double margin) const;
158
161 void ExpandToEncompass(const BDSExtent& other);
162
163private:
165 G4double extXNeg;
166 G4double extXPos;
167 G4double extYNeg;
168 G4double extYPos;
169 G4double extZNeg;
170 G4double extZPos;
172};
173
174inline G4bool BDSExtent::operator<(const BDSExtent& r) const
175{
176 G4bool xOK = (extXNeg > r.extXNeg) && (extXPos < r.extXPos);
177 G4bool yOK = (extYNeg > r.extYNeg) && (extYPos < r.extYPos);
178 G4bool zOK = (extZNeg > r.extZNeg) && (extZPos < r.extZPos);
179 return xOK && yOK && zOK;
180}
181
182inline G4bool BDSExtent::operator==(const BDSExtent& r) const
183{
184 G4bool xOK = (extXNeg == r.extXNeg) && (extXPos == r.extXPos);
185 G4bool yOK = (extYNeg == r.extYNeg) && (extYPos == r.extYPos);
186 G4bool zOK = (extZNeg == r.extZNeg) && (extZPos == r.extZPos);
187 return xOK && yOK && zOK;
188}
189
190inline G4bool BDSExtent::TransverselyLessThan(const BDSExtent& r) const
191{
192 G4bool xOK = (extXNeg > r.extXNeg) && (extXPos < r.extXPos);
193 G4bool yOK = (extYNeg > r.extYNeg) && (extYPos < r.extYPos);
194 return xOK && yOK;
195}
196
197namespace BDS
198{
200 BDSExtent MaximumCombinedExtent(const BDSExtent& first, const BDSExtent& second);
201}
202
203#endif
Holder for +- extents in 3 dimensions.
Definition BDSExtent.hh:38
std::pair< G4double, G4double > ExtentX() const
Accessor.
Definition BDSExtent.hh:60
G4double XPos() const
Accessor.
Definition BDSExtent.hh:65
BDSExtent Tilted(G4double angle) const
Provide a new copy of this extent but rotated along Z by a given tilt angle.
Definition BDSExtent.cc:120
BDSExtent Translate(const G4ThreeVector &offset) const
Provide a new copy of this extent with an offset applied.
Definition BDSExtent.hh:124
G4bool operator==(const BDSExtent &r) const
Equality operator.
Definition BDSExtent.hh:182
G4ThreeVector ExtentNegative() const
Accessor.
Definition BDSExtent.hh:74
std::vector< G4ThreeVector > AllBoundaryPoints() const
All 8 boundary points of the bounding box.
Definition BDSExtent.cc:90
G4double extZNeg
Extent.
Definition BDSExtent.hh:169
G4bool operator<=(const BDSExtent &r) const
Comparison operator.
Definition BDSExtent.hh:90
G4bool TransverselyGreaterEquals(const BDSExtent &r) const
Comparison operator for x,y only. Ignores z (length).
Definition BDSExtent.hh:103
BDSExtent()
Default constructor gives 0 in all extents - typically unphysical.
Definition BDSExtent.cc:33
G4bool TransverselyGreaterThan(const BDSExtent &r) const
Comparison operator for x,y only. Ignores z (length).
Definition BDSExtent.hh:101
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:114
G4bool operator>=(const BDSExtent &r) const
Comparison operator.
Definition BDSExtent.hh:91
G4bool operator>(const BDSExtent &r) const
Comparison operator.
Definition BDSExtent.hh:89
friend std::ostream & operator<<(std::ostream &out, BDSExtent const &ext)
Output stream.
Definition BDSExtent.cc:148
G4double extZPos
Extent.
Definition BDSExtent.hh:170
G4double ZPos() const
Accessor.
Definition BDSExtent.hh:69
G4ThreeVector ExtentPositive() const
Accessor.
Definition BDSExtent.hh:71
G4double MaximumAbsTransverse() const
Return the maximum absolute value considering only x,y.
Definition BDSExtent.cc:170
BDSExtent ExpandBy(G4double margin) const
Return a copy expanded in all dimensions by the given margin.
Definition BDSExtent.cc:212
G4bool Encompasses(const G4ThreeVector &point) const
Return whether the extent encompasses the point. True if point lies inside the extent.
Definition BDSExtent.cc:189
G4double MaximumAbs() const
Return the maximum absolute value considering all dimensions.
Definition BDSExtent.cc:156
void ExpandToEncompass(const BDSExtent &other)
Definition BDSExtent.cc:235
G4double XNeg() const
Accessor.
Definition BDSExtent.hh:64
G4bool operator!=(const BDSExtent &r) const
Equality operator.
Definition BDSExtent.hh:96
G4double extYNeg
Extent.
Definition BDSExtent.hh:167
G4double extYPos
Extent.
Definition BDSExtent.hh:168
G4double DZ() const
The difference in a dimension.
Definition BDSExtent.hh:84
G4double YNeg() const
Accessor.
Definition BDSExtent.hh:66
G4bool operator<(const BDSExtent &r) const
Comparison operator.
Definition BDSExtent.hh:174
BDSExtent TiltOffset(const BDSTiltOffset *tiltOffset) const
Provide a new copy of this extent with both a tilt and an offset applied.
Definition BDSExtent.cc:104
G4double extXPos
Extent.
Definition BDSExtent.hh:166
std::pair< G4double, G4double > ExtentZ() const
Accessor.
Definition BDSExtent.hh:62
G4double MinimumAbsTransverse() const
Return the minimum absolute value considering only x,y.
Definition BDSExtent.cc:176
G4double DX() const
The difference in a dimension.
Definition BDSExtent.hh:82
std::pair< G4double, G4double > ExtentY() const
Accessor.
Definition BDSExtent.hh:61
G4double MinimumAbs() const
Return the minimum absolute value considering all dimensions.
Definition BDSExtent.cc:163
G4bool TransverselyLessEquals(const BDSExtent &r) const
Comparison operator for x,y only. Ignores z (length).
Definition BDSExtent.hh:102
G4double DY() const
The difference in a dimension.
Definition BDSExtent.hh:83
G4bool TransverselyLessThan(const BDSExtent &r) const
Comparison operator for x,y only. Ignores z (length).
Definition BDSExtent.hh:190
BDSExtent ExpandTransverselyBy(G4double margin) const
Return a copy expanded in x and y by the given margin.
Definition BDSExtent.cc:225
G4double YPos() const
Accessor.
Definition BDSExtent.hh:67
G4double extXNeg
Extent.
Definition BDSExtent.hh:165
G4double ZNeg() const
Accessor.
Definition BDSExtent.hh:68
G4double TransverseBoundingRadius() const
Return a radius that would encompass the maximum x,y extent.
Definition BDSExtent.cc:182
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:247