CFx SDK Documentation  2023 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 #include "Ge/GePoint2dArray.h"
31 
32 #include "TD_PackPush.h"
33 
34 #define INVALIDEXTENTS 1.0e20
44 {
45 public:
46 
52  , m_max (-INVALIDEXTENTS, -INVALIDEXTENTS)
53  {}
54 
56  const OdGePoint2d& min,
57  const OdGePoint2d& max)
58  { set (min, max); }
59 
64 
68  const OdGePoint2d& minPoint () const
69  { return m_min; }
70 
74  const OdGePoint2d& maxPoint () const
75  { return m_max; }
76 
83  void set (
84  const OdGePoint2d& min,
85  const OdGePoint2d& max)
86  { m_min = min; m_max = max; }
87 
99  void comparingSet(
100  const OdGePoint2d& pt1,
101  const OdGePoint2d& pt2);
102 
108  void addPoint (
109  const OdGePoint2d& point)
110  {
111  if ( !isValidExtents() )
112  {
113  m_max = m_min = point;
114  }
115  else
116  {
117  m_max.x = odmax (point.x, m_max.x);
118  m_max.y = odmax (point.y, m_max.y);
119  m_min.x = odmin (point.x, m_min.x);
120  m_min.y = odmin (point.y, m_min.y);
121  }
122  }
123 
129  void addExt (
130  const OdGeExtents2d& extents)
131  {
132  if (extents.isValidExtents ())
133  {
134  addPoint (extents.minPoint ());
135  addPoint (extents.maxPoint ());
136  }
137  }
138 
146  bool isValidExtents () const
147  {
148  return ( (m_max.x >= m_min.x) && (m_max.y >= m_min.y) );
149  }
150 
155  void expandBy (
156  const OdGeVector2d& vect)
157  {
158  if (isValidExtents ())
159  {
160  OdGePoint2d p1 = m_min, p2 = m_max;
161  p1 += vect;
162  p2 += vect;
163  addPoint (p1);
164  addPoint (p2);
165  }
166  }
167 
173  void transformBy (
174  const OdGeMatrix2d& xfm)
175  {
176  OdGeVector2d vecX (OdGeVector2d::kXAxis * (m_max.x - m_min.x)),
177  vecY (OdGeVector2d::kYAxis * (m_max.y - m_min.y));
178 
179  if (isValidExtents ())
180  {
181  m_max = m_min = (xfm * m_min);
182  expandBy (xfm * vecX);
183  expandBy (xfm * vecY);
184  }
185  }
186 
193  bool contains (
194  const OdGePoint2d& point) const
195  {
196  return ( point.x >= m_min.x && point.y >= m_min.y &&
197  point.x <= m_max.x && point.y <= m_max.y );
198  }
199 
200  bool contains (
201  const OdGeExtents2d& extents) const
202  {
203  return (extents.m_min.x >= m_min.x && extents.m_min.y >= m_min.y &&
204  m_max.x >= extents.m_max.x && m_max.y >= extents.m_max.y );
205  }
206 
207 
214  bool isDisjoint (
215  const OdGeExtents2d& extents) const
216  {
217  return (extents.m_min.x > m_max.x || extents.m_min.y > m_max.y ||
218  m_min.x > extents.m_max.x || m_min.y > extents.m_max.y );
219  }
220 
222  {
223  kIntersectUnknown,// Either or both extents are invalid
224  kIntersectNot, // Extents are NOT intersecting
225  kIntersectOpIn, // Operand is completely within this extents
226  kIntersectOpOut, // This extents is completely within operand
227  kIntersectOk // Extents are intersecting, result is returned
228  };
229 
249  const OdGeExtents2d& extents,
250  OdGeExtents2d* pResult = 0) const;
251 
253  {
254  return m_min + (m_max - m_min) * 0.5;
255  }
256 
257  bool isEqualTo(const OdGeExtents2d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
258 
259  bool operator ==(const OdGeExtents2d& extents) const
260  {
261  return isEqualTo(extents);
262  }
263  bool operator !=(const OdGeExtents2d& extents) const
264  {
265  return !isEqualTo(extents);
266  }
267 
268 //FELIX_CHANGE_BEGIN
270 //FELIX_CHANGE_END
271 
272 protected:
275 };
276 
277 // Inlines section
278 
279 inline void OdGeExtents2d::comparingSet(const OdGePoint2d& pt1, const OdGePoint2d& pt2)
280 {
281  if (pt1.x > pt2.x)
282  {
283  m_max.x = pt1.x;
284  m_min.x = pt2.x;
285  }
286  else
287  {
288  m_min.x = pt1.x;
289  m_max.x = pt2.x;
290  }
291  if (pt1.y > pt2.y)
292  {
293  m_max.y = pt1.y;
294  m_min.y = pt2.y;
295  }
296  else
297  {
298  m_min.y = pt1.y;
299  m_max.y = pt2.y;
300  }
301 }
302 
303 inline bool OdGeExtents2d::isEqualTo(const OdGeExtents2d& extents, const OdGeTol& tol) const
304 {
305  const OdUInt8 bValid = ((isValidExtents()) ? 1 : 0) | ((extents.isValidExtents()) ? 2 : 0);
306  switch (bValid)
307  {
308  // Both invalid
309  case 0: return true;
310  // Both valid
311  case 3: return m_min.isEqualTo(extents.m_min, tol) && m_max.isEqualTo(extents.m_max, tol);
312  }
313  return false;
314 }
315 
316 #undef INVALIDEXTENTS
317 
318 #include "TD_PackPop.h"
319 
320 #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:34
#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:303
void set(const OdGePoint2d &min, const OdGePoint2d &max)
Definition: GeExtents2d.h:83
void transformBy(const OdGeMatrix2d &xfm)
Definition: GeExtents2d.h:173
void addExt(const OdGeExtents2d &extents)
Definition: GeExtents2d.h:129
IntersectionStatus intersectWith(const OdGeExtents2d &extents, OdGeExtents2d *pResult=0) const
OdGePoint2d center() const
Definition: GeExtents2d.h:252
void comparingSet(const OdGePoint2d &pt1, const OdGePoint2d &pt2)
Definition: GeExtents2d.h:279
bool isDisjoint(const OdGeExtents2d &extents) const
Definition: GeExtents2d.h:214
OdGePoint2d m_min
Definition: GeExtents2d.h:273
bool contains(const OdGeExtents2d &extents) const
Definition: GeExtents2d.h:200
OdGeExtents2d & addPoints(const OdGePoint2dArray &points)
bool isValidExtents() const
Definition: GeExtents2d.h:146
const OdGePoint2d & maxPoint() const
Definition: GeExtents2d.h:74
void addPoint(const OdGePoint2d &point)
Definition: GeExtents2d.h:108
OdGeExtents2d(const OdGePoint2d &min, const OdGePoint2d &max)
Definition: GeExtents2d.h:55
void expandBy(const OdGeVector2d &vect)
Definition: GeExtents2d.h:155
static GE_STATIC_EXPORT const OdGeExtents2d kInvalid
Definition: GeExtents2d.h:63
bool contains(const OdGePoint2d &point) const
Definition: GeExtents2d.h:193
OdGePoint2d m_max
Definition: GeExtents2d.h:274
const OdGePoint2d & minPoint() const
Definition: GeExtents2d.h:68
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
bool operator==(const BlockRefPath &rA, const BlockRefPath &rB)
DOM.
bool operator!=(const BlockRefPath &rA, const BlockRefPath &rB)
DOM.
const T & min(const T &x, const T &y)
const T & max(const T &x, const T &y)
static GE_STATIC_EXPORT OdGeTol gTol
Definition: GeGbl.h:60