@@ -73,38 +73,23 @@ static void setWorkingPyDb(PyDbDatabase& wpd)
7373
7474static std::string AcDbExtents2dToString (const AcDbExtents2d& p)
7575{
76- auto mi = p.minPoint ();
77- auto ma = p.maxPoint ();
76+ const auto & mi = p.minPoint ();
77+ const auto & ma = p.maxPoint ();
7878 return std::format (" (({:.14f},{:.14f}),({:.14f},{:.14f}))" , mi.x , mi.y , ma.x , ma.y );
7979}
8080
8181static std::string AcDbExtents2dToStringRepr (const AcDbExtents2d& p)
8282{
83- auto mi = p.minPoint ();
84- auto ma = p.maxPoint ();
83+ const auto & mi = p.minPoint ();
84+ const auto & ma = p.maxPoint ();
8585 return std::format (" {}.Extents2d(({:.14f},{:.14f}),({:.14f},{:.14f}))" , PyGeNamespace, mi.x , mi.y , ma.x , ma.y );
8686}
8787
88- // TODO: test
89- static bool AcDbExtents2dIntersects (const AcDbExtents2d& extents, const AcDbExtents2d& other)
90- {
91- auto smin = extents.minPoint ();
92- auto smax = extents.maxPoint ();
93- auto omin = other.minPoint ();
94- auto omax = other.maxPoint ();
95- if (((smin.x <= omin.x && omin.x <= smax.x ) || (omin.x <= smin.x && smin.x <= omax.x )) &&
96- ((smin.y <= omin.y && omin.y <= smax.y ) || (omin.y <= smin.y && smin.y <= omax.y )))
97- {
98- return true ;
99- }
100- return false ;
101- }
102-
10388static boost::python::tuple AcDbExtents2dCoords (const AcDbExtents2d& extents)
10489{
10590 PyAutoLockGIL lock;
106- auto min = extents.minPoint ();
107- auto max = extents.maxPoint ();
91+ const auto & min = extents.minPoint ();
92+ const auto & max = extents.maxPoint ();
10893 return boost::python::make_tuple (min.x , min.y , max.x , max.y );
10994}
11095
@@ -126,8 +111,8 @@ static AcGePoint2d AcDbExtents2dMidPoint(const AcDbExtents2d& extents)
126111
127112static bool AcDbExtents2dContains1 (const AcDbExtents2d& extents, AcGePoint2d pnt)
128113{
129- auto min = extents.minPoint ();
130- auto max = extents.maxPoint ();
114+ const auto & min = extents.minPoint ();
115+ const auto & max = extents.maxPoint ();
131116 return min.x <= pnt.x && min.y <= pnt.y &&
132117 max.x >= pnt.x && max.y >= pnt.y ;
133118}
@@ -137,6 +122,15 @@ static bool AcDbExtents2dContains2(const AcDbExtents2d& extents, const AcDbExten
137122 return AcDbExtents2dContains1 (extents, other.minPoint ()) && AcDbExtents2dContains1 (extents, other.maxPoint ());
138123}
139124
125+ static bool AcDbExtents2dIntersects (const AcDbExtents2d& extents, const AcDbExtents2d& other)
126+ {
127+ if (AcDbExtents2dContains1 (extents, other.minPoint ()) && !AcDbExtents2dContains1 (extents, other.maxPoint ()))
128+ return true ;
129+ if (!AcDbExtents2dContains1 (extents, other.minPoint ()) && AcDbExtents2dContains1 (extents, other.maxPoint ()))
130+ return true ;
131+ return false ;
132+ }
133+
140134static void makePyDbExtents2dWrapper ()
141135{
142136 constexpr const std::string_view ctords = " Overloads:\n "
@@ -167,41 +161,23 @@ static void makePyDbExtents2dWrapper()
167161
168162static std::string AcDbExtentsToString (const AcDbExtents& p)
169163{
170- auto mi = p.minPoint ();
171- auto ma = p.maxPoint ();
164+ const auto & mi = p.minPoint ();
165+ const auto & ma = p.maxPoint ();
172166 return std::format (" (({:.14f},{:.14f},{:.14f}),({:.14f},{:.14f},{:.14f}))" , mi.x , mi.y , mi.z , ma.x , ma.y , ma.z );
173167}
174168
175169static std::string AcDbExtentsToStringRepr (const AcDbExtents& p)
176170{
177- auto mi = p.minPoint ();
178- auto ma = p.maxPoint ();
171+ const auto & mi = p.minPoint ();
172+ const auto & ma = p.maxPoint ();
179173 return std::format (" {}.Extents(({:.14f},{:.14f},{:.14f}),({:.14f},{:.14f},{:.14f}))" , PyGeNamespace, mi.x , mi.y , mi.z , ma.x , ma.y , ma.z );
180174}
181175
182- // TODO: test
183- // https://gamedev.stackexchange.com/questions/23748/testing-whether-two-cubes-are-touching-in-space
184- static bool AcDbExtents3dIntersects (const AcDbExtents& extents, const AcDbExtents& other)
185- {
186- auto smin = extents.minPoint ();
187- auto smax = extents.maxPoint ();
188- auto omin = other.minPoint ();
189- auto omax = other.maxPoint ();
190-
191- if (((smin.x <= omin.x && omin.x <= smax.x ) || (omin.x <= smin.x && smin.x <= omax.x )) &&
192- ((smin.y <= omin.y && omin.y <= smax.y ) || (omin.y <= smin.y && smin.y <= omax.y )) &&
193- ((smin.z <= omin.z && omin.z <= smax.z ) || (omin.z <= smin.z && smin.z <= omax.z )))
194- {
195- return true ;
196- }
197- return false ;
198- }
199-
200176static boost::python::tuple AcDbExtents3dCoords (const AcDbExtents& extents)
201177{
202178 PyAutoLockGIL lock;
203- auto min = extents.minPoint ();
204- auto max = extents.maxPoint ();
179+ const auto & min = extents.minPoint ();
180+ const auto & max = extents.maxPoint ();
205181 return boost::python::make_tuple (min.x , min.y , min.z , max.x , max.y , max.z );
206182}
207183
@@ -222,14 +198,28 @@ static void AcDbExtentsaddBlockExt(AcDbExtents& extents, const PyDbBlockTableRec
222198 extents.addBlockExt (rec.impObj ());
223199}
224200
225- static bool AcDbExtentsContains (const AcDbExtents& extents, AcGePoint3d pnt)
201+ static bool AcDbExtentsContains1 (const AcDbExtents& extents, const AcGePoint3d& pnt)
226202{
227- auto min = extents.minPoint ();
228- auto max = extents.maxPoint ();
203+ const auto & min = extents.minPoint ();
204+ const auto & max = extents.maxPoint ();
229205 return min.x <= pnt.x && min.y <= pnt.y && min.z <= pnt.z &&
230206 max.x >= pnt.x && max.y >= pnt.y && max.z >= pnt.z ;
231207}
232208
209+ static bool AcDbExtents3dIntersects (const AcDbExtents& extents, const AcDbExtents& other)
210+ {
211+ if (AcDbExtentsContains1 (extents, other.minPoint ()) && !AcDbExtentsContains1 (extents, other.maxPoint ()))
212+ return true ;
213+ if (!AcDbExtentsContains1 (extents, other.minPoint ()) && AcDbExtentsContains1 (extents, other.maxPoint ()))
214+ return true ;
215+ return false ;
216+ }
217+
218+ static bool AcDbExtentsContains2 (const AcDbExtents& extents, const AcDbExtents& other)
219+ {
220+ return AcDbExtentsContains1 (extents, other.minPoint ()) && AcDbExtentsContains1 (extents, other.maxPoint ());
221+ }
222+
233223static void makePyDbExtentsWrapper ()
234224{
235225 constexpr const std::string_view ctords = " Overloads:\n "
@@ -252,7 +242,8 @@ static void makePyDbExtentsWrapper()
252242 .def (" intersectsWith" , &AcDbExtents3dIntersects, DS.ARGS ({ " other: PyDb.Extents" }))
253243 .def (" coords" , &AcDbExtents3dCoords, DS.ARGS ())
254244 .def (" addBlockExt" , &AcDbExtentsaddBlockExt, DS.ARGS ({ " btr: PyDb.BlockTableRecord" }, 4528 ))
255- .def (" contains" , &AcDbExtentsContains, DS.ARGS ({ " pt: PyGe.Point3d" }))
245+ .def (" contains" , &AcDbExtentsContains1)
246+ .def (" contains" , &AcDbExtentsContains2, DS.ARGS ({ " val: PyDb.Extents|PyGe.Point3d" }))
256247 .def (" __str__" , &AcDbExtentsToString, DS.ARGS ())
257248 .def (" __repr__" , &AcDbExtentsToStringRepr, DS.ARGS ())
258249 ;
0 commit comments