QML中map的用法

            var keys = [];
            for(var p in dect){
                if(dect.hasOwnProperty(p))
                    keys.push(p);
            }
            //            console.log(keys);

            for(var i = 0; i < keys.length; i++){
                f_setLayerPropertyUI(layerId, dect, keys[i]);
            }

两个Rectangle的自动吸附功能

        function autoTile(arr, obj) {
            var sx = 0; // space x
            var sy = 0; // space y
            var sstd = 0;
            var end = arr.length - 1;

            for (var i = 0; i <= end; ++i) {
                if (arr[i] == obj) {
                    continue;
                }

                sx = arr[i].x - obj.x;
                sy = arr[i].y - obj.y;
                //                console.log("sx=" + sx + ",sy=" + sy + ",obj.x=" + obj.x + ",obj.y=" + obj.y);TEST

                if (sx > 0) {
                    sstd = arr[i].x - obj.width;

                    if (Math.abs(Math.abs(sstd) - Math.abs(obj.x)) <= activeAutoTile) {
                        if (Math.abs(sy) <= activeAutoTile) {
                            obj.x = sstd;
                            obj.y = arr[i].y;
                            break;
                        }
                    }
                }
                else {
                    sstd = arr[i].x + arr[i].width;

                    if (Math.abs(Math.abs(sstd) - Math.abs(obj.x)) <= activeAutoTile) {
                        if (Math.abs(sy) <= activeAutoTile) {
                            obj.x = sstd;
                            obj.y = arr[i].y;
                            break;
                        }
                    }
                }

                if (sy > 0) {
                    sstd = arr[i].y - obj.height;

                    if (Math.abs(Math.abs(sstd) - Math.abs(obj.y)) <= activeAutoTile) {
                        if (Math.abs(sx) <= activeAutoTile) {
                            obj.x = arr[i].x;
                            obj.y = sstd;
                            break;
                        }
                    }
                }
                else {
                    sstd = arr[i].y + arr[i].height;

                    if (Math.abs(Math.abs(sstd) - Math.abs(obj.y)) <= activeAutoTile) {
                        if (Math.abs(sx) <= activeAutoTile) {
                            obj.x = arr[i].x;
                            obj.y = sstd;
                            break;
                        }
                    }
                }
            }
        }

旋转后获取最大矩形

        function f_getRotationMaxRect(point1,point2,point3,point4){ //旋转后获取最大的矩形
            var rect = {"x":0,"y":0,"width":0,"height":0};
            var minX = Math.min(point1.x,point2.x,point3.x,point4.x);
            var minY = Math.min(point1.y,point2.y,point3.y,point4.y);
            var maxX = Math.max(point1.x,point2.x,point3.x,point4.x);
            var maxY = Math.max(point1.y,point2.y,point3.y,point4.y);

            var w = maxX - minX;
            var h = maxY - minY;

            rect.x = minX;
            rect.y = minY;
            rect.width = w;
            rect.height = h;

            return rect;
        }

获取旋转后的点

        function f_getRotationLaterPoint(point, centerPoint, angle){ //获取旋转后的点
            var tmQ = angle/180*Math.PI;
            var tmX = (point.x - centerPoint.x)*Math.cos(tmQ) -(point.y - centerPoint.y)*Math.sin(tmQ) + centerPoint.x;
            var tmY = (point.x - centerPoint.x)*Math.sin(tmQ) -(point.y - centerPoint.y)*Math.cos(tmQ) + centerPoint.y;

            var tempPoint = Qt.point(tmX, tmY);
            return  tempPoint;
        }
点是否在矩形内
    function f_IsOnRectangle(rect, point){ //点是否在矩形内
        var rectX = rect.x;
        var rectY = rect.y;
        var rectW = rect.width;
        var rectH = rect.height;

        var pointX = point.x;
        var pointY = point.y;

        if(pointX>=rectX && pointX <=(rectX+rectW) && pointY >= rectY && pointY<=(rectY+rectH))
            return true;
        else
            return false;

    }

rgb值转换成unsigned int一个数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值