Warning, /include/opencascade/Intrv_Interval.lxx is written in an unsupported language. File is not indexed.
0001 // Created on: 1991-12-13
0002 // Created by: Christophe MARION
0003 // Copyright (c) 1991-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016
0017 // **-----------**** Other
0018 // ***-----* IsBefore
0019 // ***------------* IsJustBefore
0020 // ***-----------------* IsOverlappingAtStart
0021 // ***--------------------------* IsJustEnclosingAtEnd
0022 // ***-------------------------------------* IsEnclosing
0023 // ***----* IsJustOverlappingAtStart
0024 // ***-------------* IsSimilar
0025 // ***------------------------* IsJustEnclosingAtStart
0026 // ***-* IsInside
0027 // ***------* IsJustOverlappingAtEnd
0028 // ***-----------------* IsOverlappingAtEnd
0029 // ***--------* IsJustAfter
0030 // ***---* IsAfter
0031
0032 //=================================================================================================
0033
0034 inline double Intrv_Interval::Start() const
0035 {
0036 return myStart;
0037 }
0038
0039 //=================================================================================================
0040
0041 inline double Intrv_Interval::End() const
0042 {
0043 return myEnd;
0044 }
0045
0046 //=================================================================================================
0047
0048 inline float Intrv_Interval::TolStart() const
0049 {
0050 return myTolStart;
0051 }
0052
0053 //=================================================================================================
0054
0055 inline float Intrv_Interval::TolEnd() const
0056 {
0057 return myTolEnd;
0058 }
0059
0060 //=================================================================================================
0061
0062 inline void Intrv_Interval::Bounds(double& Start, float& TolStart, double& End, float& TolEnd) const
0063 {
0064 Start = myStart;
0065 TolStart = myTolStart;
0066 End = myEnd;
0067 TolEnd = myTolEnd;
0068 }
0069
0070 //=================================================================================================
0071
0072 inline void Intrv_Interval::SetStart(const double Start, const float TolStart)
0073 {
0074 myStart = Start;
0075 myTolStart = TolStart;
0076 }
0077
0078 //=======================================================================
0079 // function : FuseAtStart
0080 //
0081 // ****+****--------------------> Old one
0082 // ****+****------------------------> New one to fuse
0083 // <<< <<<
0084 // ****+****------------------------> result
0085 //
0086 //=======================================================================
0087
0088 inline void Intrv_Interval::FuseAtStart(const double Start, const float TolStart)
0089 {
0090 if (myStart != RealFirst())
0091 {
0092 double a = std::min(myStart - myTolStart, Start - TolStart);
0093 double b = std::min(myStart + myTolStart, Start + TolStart);
0094 myStart = (a + b) / 2;
0095 myTolStart = (float)(b - a) / 2;
0096 }
0097 }
0098
0099 //=======================================================================
0100 // function : CutAtStart
0101 //
0102 // ****+****-----------> Old one
0103 // <----------**+** Tool for cutting
0104 // >>> >>>
0105 // ****+****-----------> result
0106 //
0107 //=======================================================================
0108
0109 inline void Intrv_Interval::CutAtStart(const double Start, const float TolStart)
0110 {
0111 if (myStart != RealFirst())
0112 {
0113 double a = std::max(myStart - myTolStart, Start - TolStart);
0114 double b = std::max(myStart + myTolStart, Start + TolStart);
0115 myStart = (a + b) / 2;
0116 myTolStart = (float)(b - a) / 2;
0117 }
0118 }
0119
0120 //=================================================================================================
0121
0122 inline void Intrv_Interval::SetEnd(const double End, const float TolEnd)
0123 {
0124 myEnd = End;
0125 myTolEnd = TolEnd;
0126 }
0127
0128 //=======================================================================
0129 // function : FuseAtEnd
0130 //
0131 // <---------------------****+**** Old one
0132 // <-----------------**+** New one to fuse
0133 // >>> >>>
0134 // <---------------------****+**** result
0135 //
0136 //=======================================================================
0137
0138 inline void Intrv_Interval::FuseAtEnd(const double End, const float TolEnd)
0139 {
0140 if (myEnd != RealLast())
0141 {
0142 double a = std::max(myEnd - myTolEnd, End - TolEnd);
0143 double b = std::max(myEnd + myTolEnd, End + TolEnd);
0144 myEnd = (a + b) / 2;
0145 myTolEnd = (float)(b - a) / 2;
0146 }
0147 }
0148
0149 //=======================================================================
0150 // function : CutAtEnd
0151 //
0152 // <-----****+**** Old one
0153 // **+**------> Tool for cutting
0154 // <<< <<<
0155 // <-----****+**** result
0156 //
0157 //=======================================================================
0158
0159 inline void Intrv_Interval::CutAtEnd(const double End, const float TolEnd)
0160 {
0161 if (myEnd != RealLast())
0162 {
0163 double a = std::min(myEnd - myTolEnd, End - TolEnd);
0164 double b = std::min(myEnd + myTolEnd, End + TolEnd);
0165 myEnd = (a + b) / 2;
0166 myTolEnd = (float)(b - a) / 2;
0167 }
0168 }
0169
0170 //=================================================================================================
0171
0172 inline bool AreFused(const double c1, const float t1, const double c2, const float t2)
0173 {
0174 return t1 + t2 >= std::abs(c1 - c2);
0175 }
0176
0177 //=================================================================================================
0178
0179 inline bool Intrv_Interval::IsProbablyEmpty() const
0180 {
0181 return AreFused(myStart, myTolStart, myEnd, myTolEnd);
0182 }
0183
0184 //=======================================================================
0185 // **-----------**** Other
0186 // ***-----* IsBefore
0187 //=======================================================================
0188
0189 inline bool Intrv_Interval::IsBefore(const Intrv_Interval& Other) const
0190 {
0191 return myTolEnd + Other.myTolStart < Other.myStart - myEnd;
0192 }
0193
0194 //=======================================================================
0195 // **-----------**** Other
0196 // ***---* IsAfter
0197 //=======================================================================
0198
0199 inline bool Intrv_Interval::IsAfter(const Intrv_Interval& Other) const
0200 {
0201 return myTolStart + Other.myTolEnd < myStart - Other.myEnd;
0202 }
0203
0204 //=======================================================================
0205 // **-----------**** Other
0206 // ***-* IsInside
0207 //=======================================================================
0208
0209 inline bool Intrv_Interval::IsInside(const Intrv_Interval& Other) const
0210 {
0211 return myTolStart + Other.myTolStart < myStart - Other.myStart
0212 && myTolEnd + Other.myTolEnd < Other.myEnd - myEnd;
0213 }
0214
0215 //=======================================================================
0216 // **-----------**** Other
0217 // ***-------------------------------------* IsEnclosing
0218 //=======================================================================
0219
0220 inline bool Intrv_Interval::IsEnclosing(const Intrv_Interval& Other) const
0221 {
0222 return myTolStart + Other.myTolStart < Other.myStart - myStart
0223 && myTolEnd + Other.myTolEnd < myEnd - Other.myEnd;
0224 }
0225
0226 //=======================================================================
0227 // **-----------**** Other
0228 // ***------------------------* IsJustEnclosingAtStart
0229 //=======================================================================
0230
0231 inline bool Intrv_Interval::IsJustEnclosingAtStart(const Intrv_Interval& Other) const
0232 {
0233 return AreFused(myStart, myTolStart, Other.myStart, Other.myTolStart)
0234 && myTolEnd + Other.myTolEnd < myEnd - Other.myEnd;
0235 }
0236
0237 //=======================================================================
0238 // **-----------**** Other
0239 // ***--------------------------* IsJustEnclosingAtEnd
0240 //=======================================================================
0241
0242 inline bool Intrv_Interval::IsJustEnclosingAtEnd(const Intrv_Interval& Other) const
0243 {
0244 return myTolStart + Other.myTolStart < Other.myStart - myStart
0245 && AreFused(Other.myEnd, Other.myTolEnd, myEnd, myTolEnd);
0246 }
0247
0248 //=======================================================================
0249 // **-----------**** Other
0250 // ***------------* IsJustBefore
0251 //=======================================================================
0252
0253 inline bool Intrv_Interval::IsJustBefore(const Intrv_Interval& Other) const
0254 {
0255 return AreFused(myEnd, myTolEnd, Other.myStart, Other.myTolStart);
0256 }
0257
0258 //=======================================================================
0259 // **-----------**** Other
0260 // ***--------* IsJustAfter
0261 //=======================================================================
0262
0263 inline bool Intrv_Interval::IsJustAfter(const Intrv_Interval& Other) const
0264 {
0265 return AreFused(Other.myEnd, Other.myTolEnd, myStart, myTolStart);
0266 }
0267
0268 //=======================================================================
0269 // **-----------**** Other
0270 // ***-----------------* IsOverlappingAtStart
0271 //=======================================================================
0272
0273 inline bool Intrv_Interval::IsOverlappingAtStart(const Intrv_Interval& Other) const
0274 {
0275 return myTolStart + Other.myTolStart < Other.myStart - myStart
0276 && myTolEnd + Other.myTolStart < myEnd - Other.myStart
0277 && myTolEnd + Other.myTolEnd < Other.myEnd - myEnd;
0278 }
0279
0280 //=======================================================================
0281 // **-----------**** Other
0282 // ***-----------------* IsOverlappingAtEnd
0283 //=======================================================================
0284
0285 inline bool Intrv_Interval::IsOverlappingAtEnd(const Intrv_Interval& Other) const
0286 {
0287 return myTolStart + Other.myTolStart < myStart - Other.myStart
0288 && myTolStart + Other.myTolEnd < Other.myEnd - myStart
0289 && myTolEnd + Other.myTolEnd < myEnd - Other.myEnd;
0290 }
0291
0292 //=======================================================================
0293 // **-----------**** Other
0294 // ***----* IsJustOverlappingAtStart
0295 //=======================================================================
0296
0297 inline bool Intrv_Interval::IsJustOverlappingAtStart(const Intrv_Interval& Other) const
0298 {
0299 return AreFused(myStart, myTolStart, Other.myStart, Other.myTolStart)
0300 && myTolEnd + Other.myTolEnd < Other.myEnd - myEnd;
0301 }
0302
0303 //=======================================================================
0304 // **-----------**** Other
0305 // ***------* IsJustOverlappingAtEnd
0306 //=======================================================================
0307
0308 inline bool Intrv_Interval::IsJustOverlappingAtEnd(const Intrv_Interval& Other) const
0309 {
0310 return myTolStart + Other.myTolStart < myStart - Other.myStart
0311 && AreFused(Other.myEnd, Other.myTolEnd, myEnd, myTolEnd);
0312 }
0313
0314 //=======================================================================
0315 // **-----------**** Other
0316 // ***-------------* IsSimilar
0317 //=======================================================================
0318
0319 inline bool Intrv_Interval::IsSimilar(const Intrv_Interval& Other) const
0320 {
0321 bool b1, b2;
0322 b1 = AreFused(myStart, myTolStart, Other.myStart, Other.myTolStart);
0323 b2 = AreFused(myEnd, myTolEnd, Other.myEnd, Other.myTolEnd);
0324 return b1 && b2;
0325 }