コード例 #1
0
ファイル: area.js プロジェクト: GitJunyang/Night
        window['pixelMethod'] = function (x, y) {
            for (var j = 0; j < N_SHAPE; j++) {
                var shape = shapeList[j];

                var _rect = shape.getRect(shape.style);
                var _context = util.getPixelContext();
                var _offset = util.getPixelOffset();

                util.adjustCanvasSize(x, y);
                _context.clearRect(_rect.x, _rect.y, _rect.width, _rect.height);
                _context.beginPath();
                shape.brush(_context, { style: shape.style });
                _context.closePath();

                if (_isPainted(_context, x + _offset.x, y + _offset.y)) {
                    return true;
                }
            }
        }
コード例 #2
0
ファイル: area.js プロジェクト: ihoney/dpop-ctp
define(["require","benchmark","zrender","etpl","zrender/tool/area","zrender/tool/util","./shapes","zrender/shape/util/PathProxy"],function(require){function e(e,t){var i=[],n=d.length,a=document.createElement("div");a.className="result",document.getElementById("results").appendChild(a),d.forEach(function(r){function l(){for(var e=0;e<N_ITER;e++){var t=Math.random()*width,i=Math.random()*height;points[e][0]=t,points[e][1]=i,points[e][2]=!1}}function d(){for(var e=0;e<N_ITER;e++)ctx.fillStyle=points[e][2]?"green":"red",ctx.fillRect(points[e][0],points[e][1],2,2)}function p(e){var o=e.target;i.push({ops:(N_ITER*m/(o.stats.mean+o.stats.moe)).toFixed(0),shapeType:r}),n--,a.innerHTML=u({result:i,name:t})}function f(e){console.log(e.message.message)}h.add("ZRender "+r,{fn:"for (var i = 0; i < N_ITER; i++) {\n                    points[i][2] = "+e+"(points[i][0], points[i][1]);\n                }",setup:l,teardown:d,async:!0,onError:f,onStart:function(){zr.storage.delRoot();for(var e=0;m>e;e++){var t=o["make"+r](width,height);if(!t._pathProxy)t._pathProxy=new s,t.buildPath(t._pathProxy,t.style);c[e]=t,zr.addShape(t)}zr.refresh(),ctx.clearRect(0,0,width,height)},onComplete:p})})}var t=require("benchmark"),i=require("zrender"),n=require("etpl"),a=require("zrender/tool/area"),r=require("zrender/tool/util"),o=require("./shapes"),s=require("zrender/shape/util/PathProxy");window.zr=i.init(document.getElementById("main"));var l=document.getElementById("points");window.width=zr.getWidth(),window.height=zr.getHeight(),l.width=width,l.height=height,window.ctx=l.getContext("2d");var h=new t.Suite,d=["Circle","Line","Rectangle","Star","Sector","Heart","Cubic","Quadratic"];h.benchmarks=[],h.on("add",function(e){h.benchmarks.push(e.target)});var u=n.compile("<h3>${name}</h3>        <table>            <tr>            <th>shape类型</th>            <!-- for: ${result} as ${item} -->            <th>${item.shapeType}</th>            <!-- /for -->            </tr>            <tr>            <td>op/s</td>            <!-- for: ${result} as ${item} -->            <td>${item.ops}</td>            <!-- /for -->            </tr>        </table>"),c=[],m=20;window.N_ITER=2e3,window.points=[];for(var p=0;p<N_ITER;p++)points[p]=[0,0,!1];document.getElementById("run").addEventListener("click",function(){function t(e,t,i,n){var a;if("undefined"!=typeof n)n=(n||1)>>1,a=e.getImageData(t-n,i-n,n+n,n+n).data;else a=e.getImageData(t,i,1,1).data;for(var r=a.length;r--;)if(0!==a[r])return!0;return!1}window.mathMethod=function(e,t){for(var i=0;m>i;i++){var n=c[i];if(a.isInside(n,n.style,e,t))return!0}},window.buildPath=function(e,t){for(var i=0;m>i;i++){var n=c[i];if(ctx.beginPath(),n.buildPath(ctx,n.style),ctx.closePath(),ctx.isPointInPath(e,t))return!0}},window.jsInsidePath=function(e,t){for(var i=0;m>i;i++){var n=c[i];if(a.isInsidePath(n._pathProxy.pathCommands,n.style.lineWidth,n.style.brushType,e,t))return!0}},window.pixelMethod=function(e,i){for(var n=0;m>n;n++){var a=c[n],o=a.getRect(a.style),s=r.getPixelContext(),l=r.getPixelOffset();if(r.adjustCanvasSize(e,i),s.clearRect(o.x,o.y,o.width,o.height),s.beginPath(),a.brush(s,{style:a.style}),s.closePath(),t(s,e+l.x,i+l.y))return!0}},e("mathMethod","Math method"),e("buildPath","Native isPointInPath"),e("jsInsidePath","JS isPointInPath"),h.run()}),h.on("complete",function(){t.filter(h.benchmarks,"successful")})});