File indexing completed on 2026-09-08 09:15:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _Bnd_Range_HeaderFile
0017 #define _Bnd_Range_HeaderFile
0018
0019 #include <Standard_ConstructionError.hxx>
0020
0021 #include <NCollection_List.hxx>
0022
0023
0024
0025
0026 class Bnd_Range
0027 {
0028 public:
0029
0030 Bnd_Range()
0031 : myFirst(0.0),
0032 myLast(-1.0)
0033 {
0034 }
0035
0036
0037 Bnd_Range(const Standard_Real theMin, const Standard_Real theMax)
0038 : myFirst(theMin),
0039 myLast(theMax)
0040 {
0041 if (myLast < myFirst)
0042 throw Standard_ConstructionError("Last < First");
0043 }
0044
0045
0046 Standard_EXPORT void Common(const Bnd_Range& theOther);
0047
0048
0049
0050
0051
0052
0053 Standard_EXPORT Standard_Boolean Union(const Bnd_Range& theOther);
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 Standard_EXPORT void Split(const Standard_Real theVal,
0066 NCollection_List<Bnd_Range>& theList,
0067 const Standard_Real thePeriod = 0.0) const;
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 Standard_EXPORT Standard_Integer IsIntersected(const Standard_Real theVal,
0079 const Standard_Real thePeriod = 0.0) const;
0080
0081
0082 void Add(const Standard_Real theParameter)
0083 {
0084 if (IsVoid())
0085 {
0086 myFirst = myLast = theParameter;
0087 return;
0088 }
0089
0090 myFirst = Min(myFirst, theParameter);
0091 myLast = Max(myLast, theParameter);
0092 }
0093
0094
0095
0096 void Add(const Bnd_Range& theRange)
0097 {
0098 if (theRange.IsVoid())
0099 {
0100 return;
0101 }
0102 else if (IsVoid())
0103 {
0104 *this = theRange;
0105 }
0106 myFirst = Min(myFirst, theRange.myFirst);
0107 myLast = Max(myLast, theRange.myLast);
0108 }
0109
0110
0111
0112 Standard_Boolean GetMin(Standard_Real& thePar) const
0113 {
0114 if (IsVoid())
0115 {
0116 return Standard_False;
0117 }
0118
0119 thePar = myFirst;
0120 return Standard_True;
0121 }
0122
0123
0124
0125 Standard_Boolean GetMax(Standard_Real& thePar) const
0126 {
0127 if (IsVoid())
0128 {
0129 return Standard_False;
0130 }
0131
0132 thePar = myLast;
0133 return Standard_True;
0134 }
0135
0136
0137
0138 Standard_Boolean GetBounds(Standard_Real& theFirstPar, Standard_Real& theLastPar) const
0139 {
0140 if (IsVoid())
0141 {
0142 return Standard_False;
0143 }
0144
0145 theFirstPar = myFirst;
0146 theLastPar = myLast;
0147 return Standard_True;
0148 }
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158 Standard_Boolean GetIntermediatePoint(const Standard_Real theLambda,
0159 Standard_Real& theParameter) const
0160 {
0161 if (IsVoid())
0162 {
0163 return Standard_False;
0164 }
0165
0166 theParameter = myFirst + theLambda * (myLast - myFirst);
0167 return Standard_True;
0168 }
0169
0170
0171 Standard_Real Delta() const { return (myLast - myFirst); }
0172
0173
0174 Standard_Boolean IsVoid() const { return (myLast < myFirst); }
0175
0176
0177 void SetVoid()
0178 {
0179 myLast = -1.0;
0180 myFirst = 0.0;
0181 }
0182
0183
0184 void Enlarge(const Standard_Real theDelta)
0185 {
0186 if (IsVoid())
0187 {
0188 return;
0189 }
0190
0191 myFirst -= theDelta;
0192 myLast += theDelta;
0193 }
0194
0195
0196 Bnd_Range Shifted(const Standard_Real theVal) const
0197 {
0198 return !IsVoid() ? Bnd_Range(myFirst + theVal, myLast + theVal) : Bnd_Range();
0199 }
0200
0201
0202 void Shift(const Standard_Real theVal)
0203 {
0204 if (!IsVoid())
0205 {
0206 myFirst += theVal;
0207 myLast += theVal;
0208 }
0209 }
0210
0211
0212
0213 void TrimFrom(const Standard_Real theValLower)
0214 {
0215 if (!IsVoid())
0216 {
0217 myFirst = Max(myFirst, theValLower);
0218 }
0219 }
0220
0221
0222
0223 void TrimTo(const Standard_Real theValUpper)
0224 {
0225 if (!IsVoid())
0226 {
0227 myLast = Min(myLast, theValUpper);
0228 }
0229 }
0230
0231
0232 Standard_Boolean IsOut(Standard_Real theValue) const
0233 {
0234 return IsVoid() || theValue < myFirst || theValue > myLast;
0235 }
0236
0237
0238 Standard_Boolean IsOut(const Bnd_Range& theRange) const
0239 {
0240 return IsVoid() || theRange.IsVoid() || theRange.myLast < myFirst || theRange.myFirst > myLast;
0241 }
0242
0243
0244 Standard_Boolean operator==(const Bnd_Range& theOther) const
0245 {
0246 return ((myFirst == theOther.myFirst) && (myLast == theOther.myLast));
0247 }
0248
0249
0250 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
0251
0252 private:
0253 Standard_Real myFirst;
0254 Standard_Real myLast;
0255 };
0256
0257 #endif