0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / Bnd / Bnd_Range.hxx
CommitLineData
d30895f5 1// Created on: 2016-06-07
2// Created by: Nikolai BUKHALOV
3// Copyright (c) 2016 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _Bnd_Range_HeaderFile
17#define _Bnd_Range_HeaderFile
18
19#include <Standard_Real.hxx>
20#include <Standard_ConstructionError.hxx>
21
22//! This class describes a range in 1D space restricted
23//! by two real values.
24//! A range can be void indicating there is no point included in the range.
25
26class Bnd_Range
27{
28public:
29
30 //! Default constructor. Creates VOID range.
31 Bnd_Range() : myFirst(0.0), myLast(-1.0)
32 {
33 };
34
35 //! Constructor. Never creates VOID range.
36 Bnd_Range(const Standard_Real theMin, const Standard_Real theMax) :
37 myFirst(theMin), myLast(theMax)
38 {
39 if(myLast < myFirst)
9775fa61 40 throw Standard_ConstructionError("Last < First");
d30895f5 41 };
42
43 //! Replaces <this> with common-part of <this> and theOther
44 Standard_EXPORT void Common(const Bnd_Range& theOther);
45
46 //! Extends <this> to include theParameter
47 void Add(const Standard_Real theParameter)
48 {
49 if(IsVoid())
50 {
51 myFirst = myLast = theParameter;
52 return;
53 }
54
55 myFirst = Min(myFirst, theParameter);
56 myLast = Max(myLast, theParameter);
57 }
58
59 //! Obtain MIN boundary of <this>.
60 //! If <this> is VOID the method returns false.
61 Standard_Boolean GetMin(Standard_Real& thePar) const
62 {
63 if(IsVoid())
64 {
65 return Standard_False;
66 }
67
68 thePar = myFirst;
69 return Standard_True;
70 }
71
72 //! Obtain MAX boundary of <this>.
73 //! If <this> is VOID the method returns false.
74 Standard_Boolean GetMAX(Standard_Real& thePar) const
75 {
76 if(IsVoid())
77 {
78 return Standard_False;
79 }
80
81 thePar = myLast;
82 return Standard_True;
83 }
84
85 //! Returns range value (MAX-MIN). Returns negative value for VOID range.
86 Standard_Real Delta() const
87 {
88 return (myLast - myFirst);
89 }
90
91 //! Is <this> initialized.
92 Standard_Boolean IsVoid() const
93 {
94 return (myLast < myFirst);
95 }
96
97 //! Initializes <this> by default parameters. Makes <this> VOID.
98 void SetVoid()
99 {
100 myLast = -1.0;
101 myFirst = 0.0;
102 }
103
104 //! Extends this to the given value (in both side)
105 void Enlarge(const Standard_Real theDelta)
106 {
107 if (IsVoid())
108 {
109 return;
110 }
111
112 myFirst -= theDelta;
113 myLast += theDelta;
114 }
115
116private:
117 //! Start of range
118 Standard_Real myFirst;
119
120 //! End of range
121 Standard_Real myLast;
122};
123
124#endif