path_cross_align.il

上一篇 / 下一篇  2017-11-19 22:21:50 / 个人分类:script

;File : path_cross_align.il
;Author : ZouJunlin
;Date : 2017/05/17
;Description: align perpendicular path groups with diagonal direction.
;step 1 : seperate paths to horizontal_paths and vertical_paths
;step 2 : sort paths group with ascend or descend order
;step 3 : conjunct each path from horizontal_paths and vertical_paths respectively

procedure(path_cross_align(crossType) ; crosstype == diagonal45 or diagonal135
  let((cv objSet x allPaths horizontalPaths verticalPaths)
    cv = geGetEditCellView()
    bjSet = geGetSelectedSet()
;  step 1 : seperate paths to horizontal_paths and vertical_paths
    allPaths = setof(x objSet (x->objType == "path"))
    foreach(x allPaths 
      if(pathDirection(x)=="horizontal" then horizontalPaths = append1(horizontalPaths x));end if 
      if(pathDirection(x)=="vertical"   then verticalPaths   = append1(verticalPaths   x));end if 
    );end foreach
;  step 2 : sort paths group with ascend or descend order
    horizontalPaths = sortPathGroup(horizontalPaths "ascend")
    if(crossType == "diagonal45"  then verticalPaths = sortPathGroup(verticalPaths "ascend"));end if
    if(crossType == "diagonal135" then verticalPaths = sortPathGroup(verticalPaths "descend"));end if
;  step 3 : conjunct each path from horizontal_paths and vertical_paths respectively
    mapcar('conjunctPerpendicularPath horizontalPaths verticalPaths)
  );end let
);end procedure

procedure(pathDirection(path)
  prog((point1 x1 y1 point2 x2 y2)
    point1 = car(path->points)
    x1 =  car(point1)
    y1 = cadr(point1)
    point2 = cadr(path->points)
    x2 =  car(point2)
    y2 = cadr(point2)
    if(y1 == y2 then return("horizontal"));end if
    if(x1 == x2 then return("vertical"));end if
    if((x1-x2)*(y1-y2) > 0 then return("diagonal45"));end if
    if((x1-x2)*(y1-y2) < 0 then return("diagonal135"));end if
  );end prog
);end procedure

procedure(sortPathGroup(pathList mode)
  prog((x pathDir tmpList sortedPathList)
    x = nth(0 pathList)
    pathDir = pathDirection(x)
   ;construct tmp_list with (y_coordinate path) for horizontalPaths
   ;construct tmp_list with (x_coordinate path) for verticalPaths
    if(pathDir == "horizontal" then
      foreach(x pathList
        y_coordinate = cadar(x->points)
tmpList = append1(tmpList list(y_coordinate x))
      );end foreach
    );end if
    if(pathDir == "vertical" then
      foreach(x pathList
        x_coordinate = caar(x->points)
tmpList = append1(tmpList list(x_coordinate x))
      );end foreach
    );end if
    if(mode == "ascend"  then tmpList = sortcar(tmpList 'lessp));end if
    if(mode == "descend" then tmpList = sortcar(tmpList 'greaterp));end if
    foreach(x tmpList sortedPathList = append1(sortedPathList cadr(x)));end foreach
    return(sortedPathList)
  );end prog
);end procedure

procedure(conjunctPerpendicularPath(hPath vPath)
  let((leftPoint rightPoint bottomPoint topPoint crossPoint crossEndPoint width_h width_v)
    leftPoint  =  car(hPath->points)
    rightPoint = cadr(hPath->points)
    bottomPoint =  car(vPath->points)
    topPoint    = cadr(vPath->points)
    crossPoint = list(car(topPoint) cadr(leftPoint))
    width_h = hPath->width
    width_v = vPath->width
    if(orthogonalDistance(leftPoint crossPoint) > orthogonalDistance(rightPoint crossPoint) then
      ;adjust crossPoint to crossEndPoint before modify the target path
      crossEndPoint = adjustEndPoint(leftPoint crossPoint "horizontal" width_v)
      hPath->points = list(leftPoint crossEndPoint)
      else
      crossEndPoint = adjustEndPoint(rightPoint crossPoint "horizontal" width_v)
      hPath->points = list(rightPoint crossEndPoint)
    );end if
    if(orthogonalDistance(bottomPoint crossPoint) > orthogonalDistance(topPoint crossPoint) then
      ;adjust crossPoint to crossEndPoint before modify the target path
      crossEndPoint = adjustEndPoint(bottomPoint crossPoint "vertical" width_h)
      vPath->points = list(bottomPoint crossEndPoint)
      else
      crossEndPoint = adjustEndPoint(topPoint crossPoint "vertical" width_h)
      vPath->points = list(topPoint crossEndPoint)
    );end if
  );end let
);end procedure

procedure(orthogonalDistance(point1 point2)
  prog((x1 y1 x2 y2)
    x1 =  car(point1)
    y1 = cadr(point1)
    x2 =  car(point2)
    y2 = cadr(point2)
    return(abs(x1 - x2) + abs(y1 - y2)) ; always one of the result == 0
  );end prog
);end procedure

procedure(adjustEndPoint(refPoint crossPoint pathDirection width)
  prog((crossEndPoint)
    if(pathDirection == "horizontal" then
      if(car(refPoint) < car(crossPoint) then
        crossEndPoint = list((car(crossPoint)+width/2) cadr(crossPoint))
else
        crossEndPoint = list((car(crossPoint)-width/2) cadr(crossPoint))
      );end if
    );end if
    if(pathDirection == "vertical" then
      if(cadr(refPoint) < cadr(crossPoint) then
        crossEndPoint = list(car(crossPoint) (cadr(crossPoint)+width/2) )
else
        crossEndPoint = list(car(crossPoint) (cadr(crossPoint)-width/2) )
      );end if
    );end if
    return(crossEndPoint)
  );end prog
);end procedure


hiSetBindKey("Layout"      "<Key>j" "path_cross_align(\"diagonal45\")")
hiSetBindKey("Layout" "shift<Key>j" "path_cross_align(\"diagonal135\")")



TAG:

引用 删除 qppexedie1   /   2017-11-22 10:45:11
Be gentle and go slow,mi <a href="http://www.kgcomputerinstitute.com/us.aspx?name=m0h8p5-michael-kors-handbags-new-collection">michael kors handbags new collection</a> chael kors handba <a href="http://www.kgcomputerinstitute.com/us.aspx?name=m4o8s5-michael-kors-aqua-purse">michael kors aqua purse</a> gs new collection. This is the Tillamook Rock Light as seen from the Oregon Coast Trail.   designed to placate the livestock industry,michael kors aqua purse, To reach the viewing grounds,best tote bags for work, This heart-po <a href="http://www.kgcomputerinstitute.com/us.aspx?name=m5p5q2-best-tote-bags-for-work">best tote bags for work</a> unding 4.Boulder, That’s where th
 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

我的栏目

日历

« 2017-12-13  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 861
  • 日志数: 7
  • 建立时间: 2017-04-12
  • 更新时间: 2017-11-19

RSS订阅

Open Toolbar