!   TITLE:  ln_seg.mac (SM_TOOL)
!
!
!   OBJECTIVE:
!
!   This sub-macro combines all colinear pairs of line segments, in a selected
!   set of lines, into single lines.
!
!
!   COMMAND SYNTAX:
!
!           LN_SEG
!
!
!   DESCRIPTION:
!
!   The lines must be colinear such that the angle between any line pair must
!   be 180 degrees. The intersetion keypoint common to both lines must not
!   be attached to any other lines other than the colinear line pair in order
!   for the algorithm to combine them into a single line.
!
!
!
*get,prkey_,active,0,prkey
/nopr

prec_=3
tol_=10**(-prec_-1)
!
ksll,s
entity_array,'k','kset1_','array'
numkps_=ecount
!
*do,jklm_,1,numkps_,1
    ksel,s,kp,,kset1_(jklm_,1)
    get_max_entity
    kcnt_=km
    !
    lslk,s,0
    *get,numcl_,line,,count
    !
    *if,numcl_,eq,2,then
        get_min_entity
        ln1_=l_min
        get_max_entity
        ln2_=lm
        !
        *get,kp11_,line,ln1_,kp,1
        *get,kp12_,line,ln1_,kp,2
        !
        *get,kp21_,line,ln2_,kp,1
        *get,kp22_,line,ln2_,kp,2
        !
        *if,kp11_,eq,kcnt_,then
            kp1_=kp12_
        *else
            kp1_=kp11_
        *endif
        !
        *if,kp21_,eq,kcnt_,then
            kp2_=kp22_
        *else
            kp2_=kp21_
        *endif
        !
        kpang_=anglek(kcnt_,kp1_,kp2_)*dconv
        dang_=180-kpang_
        !
        *if,abs(dang_),le,(10*tol_),then
            lcomb,ln1_,ln2_
        *endif
    *endif
*enddo
!
init_entity_num
!
lplot
!
*set,numkps_,
*set,numcl_,
*set,ecount,
*set,kp11_,
*set,kp12_,
*set,kp21_,
*set,kp22_,
*set,kp1_,
*set,kp2_,
*set,ln1_,
*set,ln2_,
*set,kpang_,
*set,dang_,
*set,kcnt_,
*set,kset1_(1),
*set,jklm_,
*set,tol_,
*set,prec_,

*if,prkey_,eq,1,then
    /go
*endif