CFx SDK Documentation  2022 SP0
GeExtents2d.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 #ifndef _ODGEEXTENTS2D_INCLUDED_
25 #define _ODGEEXTENTS2D_INCLUDED_
27 #include "Ge/GePoint2d.h"
28 #include "Ge/GeVector2d.h"
29 #include "Ge/GeMatrix2d.h"
30 
31 #include "TD_PackPush.h"
32 
33 #define INVALIDEXTENTS 1.0e20
43 {
44 public:
45 
51  , m_max (-INVALIDEXTENTS, -INVALIDEXTENTS)
52  {}
53 
55  const OdGePoint2d& min,
56  const OdGePoint2d& max)
57  { set (min, max); }
58 
63 
67  const OdGePoint2d& minPoint () const
68  { return m_min; }
69 
73  const OdGePoint2d& maxPoint () const
74  { return m_max; }
75 
82  void set (
83  const OdGePoint2d& min,
84  const OdGePoint2d& max)
85  { m_min = min; m_max = max; }
86 
98  void comparingSet(
99  const OdGePoint2d& pt1,
100  const OdGePoint2d& pt2);
101 
107  void addPoint (
108  const OdGePoint2d& point)
109  {
110  if ( !isValidExtents() )
111  {
112  m_max = m_min = point;
113  }
114  else
115  {
116  m_max.x = odmax (point.x, m_max.x);
117  m_max.y = odmax (point.y, m_max.y);
118  m_min.x = odmin (point.x, m_min.x);
119  m_min.y = odmin (point.y, m_min.y);
120  }
121  }
122 
128  void addExt (
129  const OdGeExtents2d& extents)
130  {
131  if (extents.isValidExtents ())
132  {
133  addPoint (extents.minPoint ());
134  addPoint (extents.maxPoint ());
135  }
136  }
137 
145  bool isValidExtents () const
146  {
147  return ( (m_max.x >= m_min.x) && (m_max.y >= m_min.y) );
148  }
149 
154  void expandBy (
155  const OdGeVector2d& vect)
156  {
157  if (isValidExtents ())
158  {
159  OdGePoint2d p1 = m_min, p2 = m_max;
160  p1 += vect;
161  p2 += vect;
162  addPoint (p1);
163  addPoint (p2);
164  }
165  }
166 
172  void transformBy (
173  const OdGeMatrix2d& xfm)
174  {
175  OdGeVector2d vecX (OdGeVector2d::kXAxis * (m_max.x - m_min.x)),
176  vecY (OdGeVector2d::kYAxis * (m_max.y - m_min.y));
177 
178  if (isValidExtents ())
179  {
180  m_max = m_min = (xfm * m_min);
181  expandBy (xfm * vecX);
182  expandBy (xfm * vecY);
183  }
184  }
185 
192  bool contains (
193  const OdGePoint2d& point) const
194  {
195  return ( point.x >= m_min.x && point.y >= m_min.y &&
196  point.x <= m_max.x && point.y <= m_max.y );
197  }
198 
199  bool contains (
200  const OdGeExtents2d& extents) const
201  {
202  return (extents.m_min.x >= m_min.x && extents.m_min.y >= m_min.y &&
203  m_max.x >= extents.m_max.x && m_max.y >= extents.m_max.y );
204  }
205 
206 
213  bool isDisjoint (
214  const OdGeExtents2d& extents) const
215  {
216  return (extents.m_min.x > m_max.x || extents.m_min.y > m_max.y ||
217  m_min.x > extents.m_max.x || m_min.y > extents.m_max.y );
218  }
219 
221  {
222  kIntersectUnknown,// Either or both extents are invalid
223  kIntersectNot, // Extents are NOT intersecting
224  kIntersectOpIn, // Operand is completely within this extents
225  kIntersectOpOut, // This extents is completely within operand
226  kIntersectOk // Extents are intersecting, result is returned
227  };
228 
248  const OdGeExtents2d& extents,
249  OdGeExtents2d* pResult = 0) const;
250 
252  {
253  return m_min + (m_max - m_min) * 0.5;
254  }
255 
256  bool isEqualTo(const OdGeExtents2d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
257 
258  bool operator ==(const OdGeExtents2d& extents) const
259  {
260  return isEqualTo(extents);
261  }
262  bool operator !=(const OdGeExtents2d& extents) const
263  {
264  return !isEqualTo(extents);
265  }
266 
267 protected:
270 };
271 
272 // Inlines section
273 
274 inline void OdGeExtents2d::comparingSet(const OdGePoint2d& pt1, const OdGePoint2d& pt2)
275 {
276  if (pt1.x > pt2.x)
277  {
278  m_max.x = pt1.x;
279  m_min.x = pt2.x;
280  }
281  else
282  {
283  m_min.x = pt1.x;
284  m_max.x = pt2.x;
285  }
286  if (pt1.y > pt2.y)
287  {
288  m_max.y = pt1.y;
289  m_min.y = pt2.y;
290  }
291  else
292  {
293  m_min.y = pt1.y;
294  m_max.y = pt2.y;
295  }
296 }
297 
298 inline bool OdGeExtents2d::isEqualTo(const OdGeExtents2d& extents, const OdGeTol& tol) const
299 {
300  const OdUInt8 bValid = ((isValidExtents()) ? 1 : 0) | ((extents.isValidExtents()) ? 2 : 0);
301  switch (bValid)
302  {
303  // Both invalid
304  case 0: return true;
305  // Both valid
306  case 3: return m_min.isEqualTo(extents.m_min, tol) && m_max.isEqualTo(extents.m_max, tol);
307  }
308  return false;
309 }
310 
311 #undef INVALIDEXTENTS
312 
313 #include "TD_PackPop.h"
314 
315 #endif //_ODGEEXTENTS2D_INCLUDED_
tol
Definition: DimVarDefs.h:2287
#define GE_TOOLKIT_EXPORT
Definition: GeExport.h:49
#define GE_STATIC_EXPORT
Definition: GeExport.h:53
#define INVALIDEXTENTS
Definition: GeExtents2d.h:33
#define odmin(X, Y)
Definition: OdPlatform.h:34
#define odmax(X, Y)
Definition: OdPlatform.h:35
unsigned char OdUInt8
bool isEqualTo(const OdGeExtents2d &extents, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeExtents2d.h:298
void set(const OdGePoint2d &min, const OdGePoint2d &max)
Definition: GeExtents2d.h:82
void transformBy(const OdGeMatrix2d &xfm)
Definition: GeExtents2d.h:172
void addExt(const OdGeExtents2d &extents)
Definition: GeExtents2d.h:128
IntersectionStatus intersectWith(const OdGeExtents2d &extents, OdGeExtents2d *pResult=0) const
OdGePoint2d center() const
Definition: GeExtents2d.h:251
void comparingSet(const OdGePoint2d &pt1, const OdGePoint2d &pt2)
Definition: GeExtents2d.h:274
bool isDisjoint(const OdGeExtents2d &extents) const
Definition: GeExtents2d.h:213
OdGePoint2d m_min
Definition: GeExtents2d.h:268
bool contains(const OdGeExtents2d &extents) const
Definition: GeExtents2d.h:199
bool isValidExtents() const
Definition: GeExtents2d.h:145
const OdGePoint2d & maxPoint() const
Definition: GeExtents2d.h:73
void addPoint(const OdGePoint2d &point)
Definition: GeExtents2d.h:107
OdGeExtents2d(const OdGePoint2d &min, const OdGePoint2d &max)
Definition: GeExtents2d.h:54
void expandBy(const OdGeVector2d &vect)
Definition: GeExtents2d.h:154
static GE_STATIC_EXPORT const OdGeExtents2d kInvalid
Definition: GeExtents2d.h:62
bool contains(const OdGePoint2d &point) const
Definition: GeExtents2d.h:192
OdGePoint2d m_max
Definition: GeExtents2d.h:269
const OdGePoint2d & minPoint() const
Definition: GeExtents2d.h:67
double x
Definition: GePoint2d.h:299
double y
Definition: GePoint2d.h:300
bool isEqualTo(const OdGePoint2d &point, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeTol.h:49
static GE_STATIC_EXPORT const OdGeVector2d kYAxis
Definition: GeVector2d.h:67
static GE_STATIC_EXPORT const OdGeVector2d kXAxis
Definition: GeVector2d.h:66
const T & min(const T &x, const T &y)
const T & max(const T &x, const T &y)
bool DAI_EXPORT operator!=(const OdDAI::OdSelect &left, const OdDAI::OdSelect &right)
bool DAI_EXPORT operator==(const OdFileDescriptionAuto &left, const OdFileDescriptionAuto &right)
static GE_STATIC_EXPORT OdGeTol gTol
Definition: GeGbl.h:60