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