0027057: Wrong license statements in some files
[occt.git] / src / Bnd / Bnd_B2x.lxx
CommitLineData
b311480e 1// Created on: 2005-09-08
2// Created by: Alexander GRIGORIEV
973c2be1 3// Copyright (c) 2005-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <gp_Pnt2d.hxx>
17
18#ifndef Bnd_B2x_RealLast
19#define Bnd_B2x_RealLast RealType(1e30);
20#endif
21
22/**
23 * Empty constructor
24 */
25inline Bnd_B2x::Bnd_B2x ()
26{
27 Clear();
28}
29
30/**
31 * Constructor.
32 * @param theCenter
33 * Center of the created box
34 * @param theHSize
35 * Half-diagonal of the box, both X and Y should be non-negative
36 */
37inline Bnd_B2x::Bnd_B2x (const gp_XY& theCenter,
38 const gp_XY& theHSize)
39{
40 myCenter[0] = RealType(theCenter.X());
41 myCenter[1] = RealType(theCenter.Y());
42 myHSize[0] = RealType(theHSize.X());
43 myHSize[1] = RealType(theHSize.Y());
44}
45
46/**
47 * Reset the box data.
48 */
49inline void Bnd_B2x::Clear ()
50{
51 myCenter[0] = Bnd_B2x_RealLast;
52 myCenter[1] = Bnd_B2x_RealLast;
53 myHSize[0] = -Bnd_B2x_RealLast;
54 myHSize[1] = -Bnd_B2x_RealLast;
55}
56
57/**
58 * Check if the box is empty.
59 */
60inline Standard_Boolean Bnd_B2x::IsVoid () const
61{
62 return (myHSize[0] < -1e-5);
63}
64
65/**
66 * Update the box by point.
67 */
68inline void Bnd_B2x::Add (const gp_Pnt2d& thePnt)
69{
70 Add (thePnt.XY());
71}
72
73/**
74 * Update the box by another box.
75 */
76inline void Bnd_B2x::Add (const Bnd_B2x& theBox)
77{
78 if (theBox.IsVoid() == Standard_False) {
79 Add (theBox.CornerMin());
80 Add (theBox.CornerMax());
81 }
82}
83
84/**
85 * Query a box corner.
86 */
87inline gp_XY Bnd_B2x::CornerMin () const
88{
89 return gp_XY (myCenter[0] - myHSize[0], myCenter[1] - myHSize[1]);
90}
91
92/**
93 * Query a box corner.
94 */
95inline gp_XY Bnd_B2x::CornerMax () const
96{
97 return gp_XY (myCenter[0] + myHSize[0], myCenter[1] + myHSize[1]);
98}
99
100/**
101 * Query the square diagonal.
102 */
103inline Standard_Real Bnd_B2x::SquareExtent () const
104{
105 return 4 * (myHSize[0] * myHSize[0] + myHSize[1] * myHSize[1]);
106}
107
108/**
109 * Set the Center coordinates.
110 */
111inline void Bnd_B2x::SetCenter (const gp_XY& theCenter)
112{
113 myCenter[0] = RealType(theCenter.X());
114 myCenter[1] = RealType(theCenter.Y());
115}
116
117/**
118 * Set the HSize coordinates.
119 */
120inline void Bnd_B2x::SetHSize (const gp_XY& theHSize)
121{
122 myHSize[0] = RealType(theHSize.X());
123 myHSize[1] = RealType(theHSize.Y());
124}
125
126/**
127 * Increase the box.
128 * @param aDiff
129 * absolute value of this parameter is added to the box size in all dimensions.
130 */
131inline void Bnd_B2x::Enlarge (const Standard_Real aDiff)
132{
133 const RealType aD = RealType(Abs(aDiff));
134 myHSize[0] += aD;
135 myHSize[1] += aD;
136}
137
138/**
139 * Intersection Box - Point
140 */
141inline Standard_Boolean Bnd_B2x::IsOut (const gp_XY& thePnt) const
142{
143 return (Abs(RealType(thePnt.X()) - myCenter[0]) > myHSize[0] ||
144 Abs(RealType(thePnt.Y()) - myCenter[1]) > myHSize[1]);
145}
146
147/**
148 * Intersection Box-Box.
149 */
150inline Standard_Boolean Bnd_B2x::IsOut (const Bnd_B2x& theBox) const
151{
152 return (Abs(theBox.myCenter[0]-myCenter[0]) > theBox.myHSize[0]+myHSize[0] ||
153 Abs(theBox.myCenter[1]-myCenter[1]) > theBox.myHSize[1]+myHSize[1]);
154}
155
156/**
157 * Test the complete inclusion of this box in theBox.
158 */
159inline Standard_Boolean Bnd_B2x::IsIn (const Bnd_B2x& theBox) const
160{
161 return (Abs(theBox.myCenter[0]-myCenter[0]) < theBox.myHSize[0]-myHSize[0] &&
162 Abs(theBox.myCenter[1]-myCenter[1]) < theBox.myHSize[1]-myHSize[1]);
163}
164