!#
!#ICONAME 
!#TYPE 0
!#AUTOLOAD FS
macro DELOB \'Dělení oblouků povrchu'\ 'ff' (string jp\'Jméno povrchu'\,                 np\'Jméno nového povrchu'\;real                                             nv\'Největší zanedbávaný vrchlík'\,                                         nuh\'Největší zanedbávaný úhel'\)

 integer ii,jj
 real uhel,xs,ys,x1,y1,x2,y2,rr,duh,nn,uhel1,uhel2
 pv,'np',0;0,1;1
 for ii=1 to dep(jp)
  pv,'np','np',sb(bzp(jp,ii),1);sb(bzp(jp,ii),2)
  if ii<dep(jp) then
   if defined(sop(jp,ii)) then
    x1=sb(bzp(jp,ii),1)
    y1=sb(bzp(jp,ii),2)
    x2=sb(bzp(jp,ii+1),1)
    y2=sb(bzp(jp,ii+1),2)
    xs=sb(sop(jp,ii),1)
    ys=sb(sop(jp,ii),2)
    uhel1=angle(x1-xs,y1-ys)
    uhel2=angle(x2-xs,y2-ys)
    if pol(jp,ii)>0 then	!ccw
     if uhel1<uhel2 then
      uhel=uhel2-uhel1
     else
      uhel=360-uhel1+uhel2
     endif
    endif
    if pol(jp,ii)<0 then	!cw
     if uhel1>uhel2 then
      uhel=uhel1-uhel2
     else
      uhel=360-uhel2+uhel1
     endif
    endif
    rr=abs(pol(jp,ii))
    duh=2*acos(1-nv/rr)
    if duh>nuh then
     duh=nuh
    endif
    nn=abs(uhel)/duh
    if nn<>int(nn) then
     nn=int(nn)+1
    endif
    duh=uhel/nn
    duh=duh*sgn(pol(jp,ii))
    for jj=1 to int(nn)
     pv,'np','np',rr*cos(uhel1+jj*duh)+xs;rr*sin(uhel1+jj*duh)+ys
    next
   endif
  endif
 next
 pzp,'np',3,dep('np'),np
endmac
macro vrt(real rs\'3. souradnice rychloposuvem'\,                                         pp\'3. souradnice posuvem'\, sv\'souradnice vyjeti'\,                       ps\'posuv'\)

  ref,rs 
  ref,pp,ps
  ref,sv
endmac
macro DELD \'Dělení povrchu úsečkami'\ 'ff' (string jp\'Jméno povrchu'\,                 np\'Jméno nového povrchu'\;real                                             dd\'Největší délka úsečky'\):contour

 integer ii,jj,oblouk
 real uhel,xs,ys,x1,y1,x2,y2,rr,duh,nn,uhel1,uhel2,ll,dx,dy
 pv,'np',0;0,sb(bzp(jp,1),1);sb(bzp(jp,1),2)
 for ii=1 to dep(jp)-1
  if ii<dep(jp) then
   x1=sb(bzp(jp,ii),1)
   y1=sb(bzp(jp,ii),2)
   x2=sb(bzp(jp,ii+1),1)
   y2=sb(bzp(jp,ii+1),2)
   if defined(sop(jp,ii)) then		! oblouk
    rr=abs(pol(jp,ii))
    if rr>0 then
     oblouk=1
    else
     oblouk=0
    endif
   else		! usecka
    oblouk=0
   endif
   if oblouk=1 then		! oblouk
    xs=sb(sop(jp,ii),1)
    ys=sb(sop(jp,ii),2)
    uhel1=angle(x1-xs,y1-ys)
    uhel2=angle(x2-xs,y2-ys)
    if pol(jp,ii)>0 then	!ccw
     if uhel1<uhel2 then
      uhel=uhel2-uhel1
     else
      uhel=360-uhel1+uhel2
     endif
    endif
    if pol(jp,ii)<0 then	!cw
     if uhel1>uhel2 then
      uhel=uhel1-uhel2
     else
      uhel=360-uhel2+uhel1
     endif
    endif
    duh=2*asin(dd/2/rr)
    nn=abs(uhel)/duh
    if nn<>int(nn) then
     nn=int(nn)+1
    endif
    duh=uhel/nn
    duh=duh*sgn(pol(jp,ii))
    for jj=1 to int(nn)
     pv,'np','np',rr*cos(uhel1+jj*duh)+xs;rr*sin(uhel1+jj*duh)+ys
    next
   else		! usecka
    ll=sqrt(sqr(x2-x1)+sqr(y2-y1))
    nn=ll/dd
    if (nn<>int(nn)) or (nn=0) then
     nn=int(nn)+1
    endif
    dx=(x2-x1)/nn
    dy=(y2-y1)/nn
    for jj=1 to int(nn)
     pv,'np','np',x1+jj*dx;y1+jj*dy
    next
   endif
  endif
 next
 pzp,'np',2,dep('np'),np
endmac
