http://forum.ragezone.com/f144/total-overlapping-percent-2-rectangles-895041/
-func-
function rectCollisionPercentage(argRectA,argRectB){
/*
* argRectA = {x:0, y:0, r width:100, height:100};
* argRectB ={x:0, y:0, r width:100, height:100};
*/
var r1 = {
left:argRectA.x,
top:argRectA.y,
right:argRectA.x+argRectA.width-1,
bottom:argRectA.y+argRectA.height-1,
width:argRectA.width,
height:argRectA.height
};
var r2 = {
left:argRectB.x,
top:argRectB.y,
right:argRectB.x+argRectB.width-1,
bottom:argRectB.y+argRectB.height-1,
width:argRectB.width,
height:argRectB.height
};
// console.log(r1,r2);
var left = r1.left >= r2.left ? r1.left : r2.left;
var top = r1.top >= r2.top ? r1.top : r2.top;
var right = r1.right >= r2.right ? r2.right : r1.right;
var bottom = r1.bottom >= r2.bottom ? r2.bottom : r1.bottom
var overlapHeight = bottom - top;
var overlapWidth = right - left;
var r2Area = r2.height * r2.width;
var overlapArea = overlapHeight * overlapWidth;
var oPercent = (Math.round((overlapArea / r2Area ) * 100)) * 1.414;
console.log(oPercent);
return oPercent;
}
-use-
opatrans=rectCollisionPercentage(
{ x:boundOutBoxContainer.x,
y:boundOutBoxContainer.y,
width:mainAblumViewFlipper.getOutBoundWH().w,
height:mainAblumViewFlipper.getOutBoundWH().h } ,
{ x:( arg_newBitmapConteiner.x + ((vvAlbumList.container.getChildByName("vAlbumSubList").x)) ),
y:arg_newBitmapConteiner.y,
width:mainAblumViewFlipper.getInBoundBaseWH().w,
height:mainAblumViewFlipper.getInBoundBaseWH().h }
);
0 comments:
댓글 쓰기