zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2002-2016, Open Design Alliance (the "Alliance"). 
// All rights reserved. 
// 
// This software and its documentation and related materials are owned by 
// the Alliance. The software may only be incorporated into application 
// programs owned by members of the Alliance, subject to a signed 
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable  
// trade secrets of the Alliance and its suppliers. The software is also 
// protected by copyright law and international treaty provisions. Application  
// programs incorporating this software must include the following statement 
// with their copyright notices:
//   
//   This application incorporates Teigha(R) software pursuant to a license 
//   agreement with Open Design Alliance.
//   Teigha(R) Copyright (C) 2002-2016 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
 
#ifndef _ODGEEXTENTS2D_INCLUDED_
#define _ODGEEXTENTS2D_INCLUDED_ /*!DOM*/
 
#include "Ge/GePoint2d.h"
#include "Ge/GeVector2d.h"
#include "Ge/GeMatrix2d.h"
 
#include "TD_PackPush.h"
 
#define INVALIDEXTENTS 1.0e20 /*!DOM*/
 
/** \details
    This class represents 2D bounding boxes as minimum and maximum 2d points.
 
    Library: TD_Ge
 
    <group OdGe_Classes> 
*/
class GE_TOOLKIT_EXPORT OdGeExtents2d
{
public:
 
  /** \param min [in]  Minimum point.
    \param max [in]  Maximum point.
  */
  OdGeExtents2d ()
    : m_min (INVALIDEXTENTS,  INVALIDEXTENTS)
    , m_max (-INVALIDEXTENTS, -INVALIDEXTENTS)
  {}
 
  OdGeExtents2d (
    const OdGePoint2d& min, 
    const OdGePoint2d& max) 
  { set (min, max); }
 
  /** \details
    The invalid extents.
  */
  GE_STATIC_EXPORT static const OdGeExtents2d kInvalid;
 
  /** \details
    Returns the minimum point of this Extents object.
  */
  const OdGePoint2d& minPoint () const 
  { return m_min; }
 
  /** \details
    Returns the maximum point of this Extents object.
  */
  const OdGePoint2d& maxPoint () const 
  { return m_max; }
 
  /** \details
    Sets the minimum and maximum points for this Extents object.
    
    \param min [in]  Minimum point.
    \param max [in]  Maximum point.
  */
  void set (
    const OdGePoint2d& min, 
    const OdGePoint2d& max) 
  { m_min = min; m_max = max; }
 
  /** \details
    Sets the minimum and maximum points for this Extents object to
    that of the box defined by pt1 and pt2.
 
    \param pt1 [in]  First point.
    \param pt2 [in]  Second point.
 
    \remarks
    pt1 and pt2 need only define a box. They need not be the minimum
    and maximum points of the box.
  */
  void comparingSet(
    const OdGePoint2d& pt1,
    const OdGePoint2d& pt2);
 
  /** \details
    Updates the extents of this Extents object with the specified point.
 
    \param point [in]  Any 2D point.
  */
  void addPoint (
    const OdGePoint2d& point)
  {
    if ( !isValidExtents() )
    {
      m_max = m_min = point;
    }
    else
    {
      m_max.x = odmax (point.x, m_max.x);
      m_max.y = odmax (point.y, m_max.y);
      m_min.x = odmin (point.x, m_min.x);
      m_min.y = odmin (point.y, m_min.y);
    }
  }
    
  /** \details
    Updates the extents of this Extents object with the specified Extents object.
    
    \param extents [in]  Any 2D Extents object.
  */
  void addExt (
    const OdGeExtents2d& extents)
  {
    if (extents.isValidExtents ())
    {
      addPoint (extents.minPoint ());
      addPoint (extents.maxPoint ());
    }
  }
 
  /** \details
    Returns true if and only if this Extents object contains valid extents.
    
    \remarks
    Extents are valid if and only if each member of the minimum extents 
    is less than or equal to the corresponding member of maximum extents.
  */
  bool isValidExtents () const
  {
    return ( (m_max.x >= m_min.x) && (m_max.y >= m_min.y) );
  }
 
  /** \details
    Updates the extents of this Extents object by the specified vector.
    \param vect [in]  Any 2D vector.
  */
    void expandBy (
    const OdGeVector2d& vect)
  {
    if (isValidExtents ())
    {
      OdGePoint2d p1 = m_min, p2 = m_max;
      p1 += vect;
      p2 += vect;
      addPoint (p1);
      addPoint (p2);
    }
  }
 
  /** \details
    Applies the 2D transformation matrix to the extents.
 
    \param xfm [in]  2D transformation matrix.
  */
  void transformBy (
    const OdGeMatrix2d& xfm)
  {
    OdGeVector2d vecX (OdGeVector2d::kXAxis * (m_max.x - m_min.x)),
      vecY (OdGeVector2d::kYAxis * (m_max.y - m_min.y));
 
    if (isValidExtents ())
    {
      m_max = m_min = (xfm * m_min);
      expandBy (xfm * vecX);
      expandBy (xfm * vecY);
    }
  }
    
  /** \details
    Returns true if and only if this Extents object contains the specified object.
    
    \param point [in]  Any 2D point.
    \param extents [in]  Any 2D Extents object.
  */
  bool contains (
    const OdGePoint2d& point) const
  {
    return ( point.x >= m_min.x  &&  point.y >= m_min.y  &&
              point.x <= m_max.x  &&  point.y <= m_max.y );
  }
 
  bool contains (
    const OdGeExtents2d& extents) const
  {
    return (extents.m_min.x >=         m_min.x && extents.m_min.y >=     m_min.y      &&
                    m_max.x >= extents.m_max.x &&          m_max.y >= extents.m_max.y );
  }
 
 
  /** \details
    Returns true if and only if specified Extents object
    does not intersect this one.
 
    \param extents [in]  Any 2D Extents object.
  */
  bool isDisjoint (
    const OdGeExtents2d& extents) const
  {
    return (extents.m_min.x >         m_max.x || extents.m_min.y >         m_max.y ||
                    m_min.x > extents.m_max.x ||         m_min.y > extents.m_max.y );
  }    
 
  enum IntersectionStatus
  {
    kIntersectUnknown,// Either or both extents are invalid
    kIntersectNot,    // Extents are NOT intersecting
    kIntersectOpIn,   // Operand is completely within this extents
    kIntersectOpOut,  // This extents is completely within operand
    kIntersectOk      // Extents are intersecting, result is returned
  };
 
  /** \details
    Determines the intersection of the specified Extents object with this one,
    and returns the resulting intersection box.
    
    \param extents [in]  Any 2D Extents object.
    \param pResult [out]  Receives extents of the intersection.
    
    \remarks
    pResult object should be created by the caller. Possible return values are as follows.
    
    @untitled table
    kIntersectUnknown   Either or both Extents objects are invalid
    kIntersectNot       The Extents objects are NOT intersecting
    kIntersectOpIn      The specified Extents object is completely within this one
    kIntersectOpOut     This Extents object is completely within the specified one
    kIntersectOk        The Extents objectes are intersecting, and a result is returned
    
  */
  IntersectionStatus intersectWith (
    const OdGeExtents2d& extents, 
    OdGeExtents2d* pResult = 0) const;
 
  OdGePoint2d center() const
  {
    return m_min + (m_max - m_min) * 0.5;
  }
 
  bool isEqualTo(const OdGeExtents2d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
 
  bool operator ==(const OdGeExtents2d& extents) const
  {
    return isEqualTo(extents);
  }
  bool operator !=(const OdGeExtents2d& extents) const
  {
    return !isEqualTo(extents);
  }
 
protected:
  OdGePoint2d m_min;
  OdGePoint2d m_max;
};
 
// Inlines section
 
inline void OdGeExtents2d::comparingSet(const OdGePoint2d& pt1, const OdGePoint2d& pt2)
{
  if (pt1.x > pt2.x)
  {
    m_max.x = pt1.x;
    m_min.x = pt2.x;
  }
  else
  {
    m_min.x = pt1.x;
    m_max.x = pt2.x;
  }
  if (pt1.y > pt2.y)
  {
    m_max.y = pt1.y;
    m_min.y = pt2.y;
  }
  else
  {
    m_min.y = pt1.y;
    m_max.y = pt2.y;
  }
}
 
inline bool OdGeExtents2d::isEqualTo(const OdGeExtents2d& extents, const OdGeTol& tol) const
{
  const OdUInt8 bValid = ((isValidExtents()) ? 1 : 0) | ((extents.isValidExtents()) ? 2 : 0);
  switch (bValid)
  {
    // Both invalid
    case 0: return true;
    // Both valid
    case 3: return m_min.isEqualTo(extents.m_min, tol) && m_max.isEqualTo(extents.m_max, tol);
  }
  return false;
}
 
#undef INVALIDEXTENTS
 
#include "TD_PackPop.h"
 
#endif //_ODGEEXTENTS2D_INCLUDED_