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
/////////////////////////////////////////////////////////////////////////////// 
// 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 _SpExtents_h_Included_
#define _SpExtents_h_Included_
 
#if _MSC_VER >= 1000
#pragma once
#endif
 
#include "Si/SiSpatialIndex.h"
 
/** \details
 
    <group TD_Namespaces>
*/
namespace OdSi
{
 
  /** \details
      This class implements 3D Spatial Index Extents objects.
 
      Library: SpatialIndex
  */
  class ODSI_API Extent3d : public OdGeExtents3d, public OdSiShape
  {
  public:
    virtual bool contains( const OdGeExtents3d& extents, bool planar = false, const OdGeTol& tol = OdGeContext::gTol) const
    {
      if ( planar ) 
      {
        ODA_ASSERT ( extents.minPoint().z == 0 && extents.maxPoint().z == 0 );
      }
      return OdGeExtents3d::contains( extents, tol );
    }
 
    virtual bool intersects( const OdGeExtents3d& extents, bool planar = false, const OdGeTol& tol = OdGeContext::gTol) const
    {
      if ( planar == false )
        return !isDisjoint( extents, tol );
      else
      {
        return !( extents.minPoint().x > (maxPoint().x + tol.equalPoint())
          || extents.minPoint().y > (maxPoint().y + tol.equalPoint())
          || minPoint().x > (extents.maxPoint().x + tol.equalPoint()) 
          || minPoint().y > (extents.maxPoint().y + tol.equalPoint()));
      }
    }
 
    enum IntersectResult 
    { 
      left    = 0,     // Coordinate is to the *left* of the *extents*.
      upon    = 1,     // Coordinate is *upon* the *extents*.
      right   = 2      // Coordinate is to the *right* of the *extents*.
    };
    
    /** \details
      Returns the intersection with this Extents object.
 
      \param dimension [in]  X, Y, or Z.
      \param coordinate [in]  Coordinate to test.
      \param extents [in]  Any 3D extents box.
      \param planar [in]  If and only if true, a planar computation is made. 
      
      \remarks
      intersects() returns one of the following.
      
      <table>
      Name    Value    Description
      true    ..       The specified extents intersect this Extents object.
      false   ..       The specified extents do not intersect this Extents object.
      left    0        coordinate is to the left of this Extents object.
      upon    1        coordinate is upon this Extents object.
      right   2        coordinate is to the right of this Extents object.
      </table>
    */
#ifndef SWIG
    IntersectResult intersects( double coordinate, int dimension, double tol = OdGeContext::gTol.equalPoint() ) const
    {
      if ( m_min[dimension] > (coordinate + tol) ) return right;
      if ( m_max[dimension] < (coordinate - tol) ) return left;
      return upon;
    }
#endif
    /** \details
      Halves the specified dimension of this Extents object.
      \param dimension [in]  X, Y, or Z.
      \param moveRight [in]  True to move the right -hand edge, false for the left -hand.
    */
    void makeHalf( int dimension, bool moveRight )
    {
      if ( moveRight )
        m_max[dimension] = ( m_min[dimension] + m_max[dimension]) / 2;
      else 
        m_min[dimension] = ( m_min[dimension] + m_max[dimension]) / 2;
    }
 
    /** \details
      Doubles the specified dimension of this Extents object.
      \param dimension [in]  X, Y, or Z.
      \param moveRight [in]  True to move the right -hand edge, false for the left -hand.
    */
    void makeDouble( int dimension, bool moveRight )
    {
      if ( moveRight )
        m_max[dimension] += ( m_max[dimension] - m_min[dimension] );
      else 
        m_min[dimension] -= ( m_max[dimension] - m_min[dimension] );
    }
    /** \details
      Expands this Extents object to a square or cube of its largest dimension.
      \param planar [in]  True for 2D extents, false for 3D.
    */
    void makeCube( bool planar )
    {
      if ( m_min.isEqualTo( m_max ) ) return;
      double ext = odmax( m_max.x - m_min.x, m_max.y - m_min.y );
      if ( !planar ) ext = odmax( m_max.z - m_min.z, ext );
      m_max.x = m_min.x + ext;
      m_max.y = m_min.y + ext;
      if ( !planar ) m_max.z = m_min.z + ext;
    }
    
    Extent3d() {}
    /** \param min [in]  Minimum point.
      \param max [in]  Maximum point.
    */
    Extent3d( const OdGePoint3d& min, const OdGePoint3d& max )
      : OdGeExtents3d( min, max ) {}
    Extent3d( const OdGeExtents3d& source ) : OdGeExtents3d( source ) {}
    Extent3d( const OdGeExtents2d& source ) 
      : OdGeExtents3d( OdGePoint3d( source.minPoint().x, source.minPoint().y, 0 ), 
      OdGePoint3d( source.maxPoint().x, source.maxPoint().y, 0 )) {}
  };
}
#endif