QML中map的用法
阿新 • • 發佈:2019-01-23
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;
}