CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
GeExtents2d.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 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/GePoint2dArray.h"
29#include "Ge/GeVector2d.h"
30#include "Ge/GeMatrix2d.h"
31
32#include "TD_PackPush.h"
33
34#define INVALIDEXTENTS 1.0e20
35
44{
45public:
46
56 {}
57
64 const OdGePoint2d& min,
65 const OdGePoint2d& max)
66 { set(min, max); }
67
72
79 const OdGePoint2d& minPoint() const
80 { return m_min; }
81
88 const OdGePoint2d& maxPoint() const
89 { return m_max; }
90
98 { return m_max - m_min; }
99
106 void set(const OdGePoint2d& min, const OdGePoint2d& max)
107 {
108 //ODA_ASSERT_ONCE(min.x <= max.x);
109 //ODA_ASSERT_ONCE(min.y <= max.y);
110 m_min = min; m_max = max;
111 }
112
125 void comparingSet(
126 const OdGePoint2d& pt1,
127 const OdGePoint2d& pt2);
128
138 const OdGePoint2d& point)
139 {
140 if (!isValidExtents())
141 {
142 m_max = m_min = point;
143 }
144 else
145 {
146 m_max.x = odmax (point.x, m_max.x);
147 m_max.y = odmax (point.y, m_max.y);
148 m_min.x = odmin (point.x, m_min.x);
149 m_min.y = odmin (point.y, m_min.y);
150 }
151 return *this;
152 }
153
163
173 const OdGeExtents2d& extents)
174 {
175 if (extents.isValidExtents())
176 {
177 addPoint (extents.minPoint());
178 addPoint (extents.maxPoint());
179 }
180 return *this;
181 }
182
193 bool isValidExtents() const
194 {
195 return ((m_max.x >= m_min.x) && (m_max.y >= m_min.y));
196 }
197
204 const OdGeVector2d& vect);
205
212 const OdGeMatrix2d& xfm);
213
220 const OdGeVector2d &iShift)
221 {
222 m_min += iShift;
223 m_max += iShift;
224 }
225
236 bool contains(
237 const OdGePoint2d& point, const OdGeTol& tol = OdGeContext::gTol) const;
238
249 bool contains(
250 const OdGeExtents2d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
251
262 bool isDisjoint(
263 const OdGeExtents2d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
264
269 {
279 kIntersectOk
280 };
281
304 const OdGeExtents2d& extents,
305 OdGeExtents2d* pResult = 0) const;
306
314 {
315 return OdGePoint2d(0.5 * (m_min.x + m_max.x), 0.5 * (m_min.y + m_max.y));
316 }
317
330 bool isEqualTo(const OdGeExtents2d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
331
340 bool operator ==(const OdGeExtents2d& extents) const
341 {
342 return isEqualTo(extents);
343 }
344
353 bool operator !=(const OdGeExtents2d& extents) const
354 {
355 return !isEqualTo(extents);
356 }
357//DOM-IGNORE-BEGIN
358protected:
361//DOM-IGNORE-END
362};
363
364// Inlines section
365
366inline void OdGeExtents2d::comparingSet(const OdGePoint2d& pt1, const OdGePoint2d& pt2)
367{
368 m_min.x = odmin(pt1.x, pt2.x);
369 m_max.x = odmax(pt1.x, pt2.x);
370 m_min.y = odmin(pt1.y, pt2.y);
371 m_max.y = odmax(pt1.y, pt2.y);
372}
373
374inline bool OdGeExtents2d::contains(const OdGePoint2d& point, const OdGeTol& tol) const
375{
376 //ODA_ASSERT(isValidExtents()); //note: empty/invalid box does NOT contain any point
377
378 return ( (point.x + tol.equalPoint()) >= m_min.x
379 && (point.y + tol.equalPoint()) >= m_min.y
380 && (point.x - tol.equalPoint()) <= m_max.x
381 && (point.y - tol.equalPoint()) <= m_max.y );
382}
383
384inline bool OdGeExtents2d::contains(const OdGeExtents2d& extents, const OdGeTol& tol) const
385{
387
388 return ((extents.m_min.x + tol.equalPoint()) >= m_min.x
389 && (extents.m_min.y + tol.equalPoint()) >= m_min.y
390 && m_max.x >= (extents.m_max.x - tol.equalPoint())
391 && m_max.y >= (extents.m_max.y - tol.equalPoint()));
392}
393
394inline bool OdGeExtents2d::isDisjoint(const OdGeExtents2d& extents, const OdGeTol& tol) const
395{
396 //ODA_ASSERT(isValidExtents()); //note: empty/invalid box is disjoint with everything
397
398 return ((extents.m_min.x - tol.equalPoint()) > m_max.x
399 || (extents.m_min.y - tol.equalPoint()) > m_max.y
400 || m_min.x > (extents.m_max.x + tol.equalPoint())
401 || m_min.y > (extents.m_max.y + tol.equalPoint()));
402}
403
412inline void pointsExtents(OdGePoint2d& minPt, OdGePoint2d& maxPt
413 , const OdGePoint2d& pt1, const OdGePoint2d& pt2)
414{
415 if (pt1.x <= pt2.x)
416 {
417 minPt.x = pt1.x;
418 maxPt.x = pt2.x;
419 }
420 else
421 {
422 minPt.x = pt2.x;
423 maxPt.x = pt1.x;
424 }
425
426 if (pt1.y <= pt2.y)
427 {
428 minPt.y = pt1.y;
429 maxPt.y = pt2.y;
430 }
431 else
432 {
433 minPt.y = pt2.y;
434 maxPt.y = pt1.y;
435 }
436}
437
451inline bool extendExtents(double& minValue, double& maxValue, const double& value)
452{
453 ODA_ASSERT(minValue <= maxValue);
454
455 if (value < minValue)
456 {
457 minValue = value;
458
459 return true;
460 }
461
462 if (value > maxValue)
463 {
464 maxValue = value;
465
466 return true;
467 }
468
469 return false;
470}
471
487inline bool extendExtents(OdGePoint2d& minPt, OdGePoint2d& maxPt, const OdGePoint2d& pt)
488{
489 bool extended = extendExtents(minPt.x, maxPt.x, pt.x);
490
491 extended |= extendExtents(minPt.y, maxPt.y, pt.y);
492
493 return extended;
494}
495
507inline bool isBoxContainsPoint(const OdGePoint2d& minPt, const OdGePoint2d& maxPt
508 , const OdGePoint2d& pt, const OdGeTol& tol = OdGeContext::gTol)
509{
510 ODA_ASSERT(minPt.x <= maxPt.x);
511 ODA_ASSERT(minPt.y <= maxPt.y);
512
513 return (OdGreaterOrEqual(pt.x, minPt.x, tol.equalPoint())
514 && OdGreaterOrEqual(pt.y, minPt.y, tol.equalPoint())
515 && OdLessOrEqual(pt.x, maxPt.x, tol.equalPoint())
516 && OdLessOrEqual(pt.y, maxPt.y, tol.equalPoint()));
517}
518
519#undef INVALIDEXTENTS
520
521#include "TD_PackPop.h"
522
523#endif //_ODGEEXTENTS2D_INCLUDED_
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:57
tol
Definition: DimVarDefs.h:2287
#define GE_TOOLKIT_EXPORT
Definition: GeExport.h:49
#define GE_STATIC_EXPORT
Definition: GeExport.h:52
bool isBoxContainsPoint(const OdGePoint2d &minPt, const OdGePoint2d &maxPt, const OdGePoint2d &pt, const OdGeTol &tol=OdGeContext::gTol)
Definition: GeExtents2d.h:507
bool extendExtents(double &minValue, double &maxValue, const double &value)
Definition: GeExtents2d.h:451
void pointsExtents(OdGePoint2d &minPt, OdGePoint2d &maxPt, const OdGePoint2d &pt1, const OdGePoint2d &pt2)
Definition: GeExtents2d.h:412
#define INVALIDEXTENTS
Definition: GeExtents2d.h:34
bool operator!=(T left, const OdGiVariant::EnumType right)
Definition: GiVariant.h:403
bool operator==(T left, const OdGiVariant::EnumType right)
Definition: GiVariant.h:397
#define odmin(X, Y)
Definition: OdPlatform.h:34
#define odmax(X, Y)
Definition: OdPlatform.h:35
bool OdLessOrEqual(double x, double y, double tol=1.e-10)
Definition: OdaDefs.h:552
bool OdGreaterOrEqual(double x, double y, double tol=1.e-10)
Definition: OdaDefs.h:562
OdGeExtents2d & addPoint(const OdGePoint2d &point)
Definition: GeExtents2d.h:137
bool isEqualTo(const OdGeExtents2d &extents, const OdGeTol &tol=OdGeContext::gTol) const
void set(const OdGePoint2d &min, const OdGePoint2d &max)
Definition: GeExtents2d.h:106
void transformBy(const OdGeMatrix2d &xfm)
IntersectionStatus intersectWith(const OdGeExtents2d &extents, OdGeExtents2d *pResult=0) const
OdGePoint2d center() const
Definition: GeExtents2d.h:313
OdGeExtents2d & addExt(const OdGeExtents2d &extents)
Definition: GeExtents2d.h:172
void comparingSet(const OdGePoint2d &pt1, const OdGePoint2d &pt2)
Definition: GeExtents2d.h:366
OdGePoint2d m_min
Definition: GeExtents2d.h:359
bool contains(const OdGePoint2d &point, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeExtents2d.h:374
void translate(const OdGeVector2d &iShift)
Definition: GeExtents2d.h:219
bool isValidExtents() const
Definition: GeExtents2d.h:193
bool isDisjoint(const OdGeExtents2d &extents, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeExtents2d.h:394
const OdGePoint2d & maxPoint() const
Definition: GeExtents2d.h:88
const OdGePoint2d & minPoint() const
Definition: GeExtents2d.h:79
OdGeExtents2d(const OdGePoint2d &min, const OdGePoint2d &max)
Definition: GeExtents2d.h:63
void expandBy(const OdGeVector2d &vect)
static GE_STATIC_EXPORT const OdGeExtents2d kInvalid
Definition: GeExtents2d.h:71
OdGeVector2d diagonal() const
Definition: GeExtents2d.h:97
OdGePoint2d m_max
Definition: GeExtents2d.h:360
OdGeExtents2d & addPoints(const OdGePoint2dArray &points)
double x
Definition: GePoint2d.h:409
double y
Definition: GePoint2d.h:410
Definition: GeTol.h:49
GLsizei const GLfloat * value
Definition: gles2_ext.h:302
static GE_STATIC_EXPORT OdGeTol gTol
Definition: GeGbl.h:65