zoukankan      html  css  js  c++  java
  • 图形-回行扫描函数

    //回行扫描函数 left、top、right、bottom
    function scanRound(x,y,w,h,isOpenFunc,callfunc) {
        const map={}
        function isOpen(x,y) {
    
            if(map[x+','+y]){
                return 0
            }
            if(x<0||x>=w||y<0||y>=h){
                return 0;
            }
            return isOpenFunc(x,y)
        }
        function callback(x,y) {
            map[x+','+y]=true;
            return callfunc(x,y)
        }
        if(isOpen(x,y)){
            callback(x,y)
        }else{
            return;
        }
        const dreMap={
            left:{x:-1,y:0},
            right:{x:1,y:0},
            bottom:{x:0,y:1},
            top:{x:0,y:-1},
        }
        const pos={
            x,y
        }
        let dre='init';
        while (dre!=='end'){
            if(dre==='init'){
                if(isOpen(pos.x+dreMap.left.x,pos.y+dreMap.left.y)){
                    dre='left';
                }else if(isOpen(pos.x+dreMap.top.x,pos.y+dreMap.top.y)){
                    dre='top';
                }else if(isOpen(pos.x+dreMap.right.x,pos.y+dreMap.right.y)){
                    dre='right';
                }else if(isOpen(pos.x+dreMap.bottom.x,pos.y+dreMap.bottom.y)){
                    dre='bottom';
                }else{
                    dre='end';
                }
            }
            if(dre!=='end'){
                const npos={
                   x:pos.x+dreMap[dre].x,y:pos.y+dreMap[dre].y
                }
                if(isOpen(npos.x,npos.y)){
                    pos.x=npos.x;
                    pos.y=npos.y;
                    callback(pos.x,pos.y)
                }else{
                    dre='init';
                }
            }
    
        }
    }
    
    
    scanRound(0,0,100,100,function (x,y) {
        return 1;
    },function (x,y) {
        console.log(x,y);
    })
  • 相关阅读:
    ***EF中的问题(复习的同学可略过)
    课堂练习
    MVC-07 案例2
    MVC-06 安装部署
    MVC-05 Model(2)
    MVC-05 Model(1)
    MVC-04 视图(3)
    Learning Web
    MVC-04 视图(2)
    hdu 1272 并查集
  • 原文地址:https://www.cnblogs.com/caoke/p/11088808.html
Copyright © 2011-2022 走看看