Author Topic: [XDrX-Function(39)] Use MPOLYGON to quickly find overlapping dim and entities  (Read 372 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 514
Use MPOLYGON to establish topological relationships to quickly find overlapping annotations and entities

Ordinary search implementation, algorithmically has a time complexity of n*n
Using MPOLYGON, the complexity can be reduced to n

1. Find overlapping dimension



Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.   (xdrx_begin)
  3.   (if (and
  4.         (xdrx_initssget "\nSelect overlapping dimension <Exit>:")
  5.         (setq ss (xdrx_ssget '((0 . "dim*"))))
  6.         (setq mt (xdrx_entity_getproperty ss "textbox"))
  7.         (setq mp (xdrx_curve->mpolygon mt))
  8.         (setq cp (xdrx_getpropertyvalue mp "haschildloop" t))
  9.       )
  10.     (progn
  11.       (xdrx_curve->mpolygon (xdge::entity:make cp))
  12.       (xdrx_mpolygon->hatch (entlast))
  13.       (xdrx_entity_setcolor (entlast) 1)
  14.     )
  15.   )
  16.   (xdrx_object_release cp)
  17.   (xdrx_entity_delete mp)
  18.   (xdrx_end)
  19.   (princ)
  20. )

2. Find overlapping entities



Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.   (xdrx_begin)
  3.   (if (and
  4.         (xdrx_initssget "\nSelect overlapping entities <Exit>:")
  5.         (setq ss (xdrx_ssget))
  6.         (setq mt (xdrx_entity_getproperty ss "boundingbox"))
  7.         (setq mp (xdrx_curve->mpolygon mt))
  8.         (setq cp (xdrx_getpropertyvalue mp "haschildloop" t))
  9.       )
  10.     (progn
  11.       (xdrx_curve->mpolygon (xdge::entity:make cp))
  12.       (xdrx_mpolygon->hatch (entlast))
  13.       (xdrx_entity_setcolor (entlast) 1)
  14.     )
  15.   )
  16.   (xdrx_object_release cp)
  17.   (xdrx_entity_delete mp)
  18.   (xdrx_end)
  19.   (princ)
  20. )
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net