矩形重叠检测。
// 矩形重疊類型注釋
// CORNER_OVERLAP
// --------------------
// | |
// | |
// | **********|**********
// | * | *
// | * | *
// ---------*---------| *
// * *
// * *
// *********************
//
// ANCHOR_OVERLAP
// ----
// | |
// | |
// *******|**|*******
// * | | *
// * | | *
// * ---- *
// * *
// ******************
// SAME_WIDTH_OVERLAP
// |-----------------|
// | |
// ******************|
// |-----------------*
// * *
// *******************
//
// INSIDE_OVERLAP
// **********************
// * *
// * --------- *
// * | | *
// * | | *
// * --------- *
// * *
// **********************
//
// CROSS_OVERLAP
// -----
// | |
// | |
// *****|***|******
// * | | *
// * | | *
// *****|***|******
// | |
// -----
typedef enum EM_RectOverlapType
{NO_OVERLAP,CORNER_OVERLAP,ANCHOR_OVERLAP,SAME_WIDTH_OVERLAP,INSIDE_OVERLAP,CROSS_OVERLAP,ERROR_OVERLAP,
}EM_RectOverlapType;//判斷Rect重疊的類型,判定方法
//NO_OVERLAP: 重疊矩形面積為0
//CORNER_OVERLAP: 重疊矩形的一個(gè)角的兩條邊,與被判定矩形的一個(gè)角的兩條邊坐標(biāo)一致(角的2條邊)
//SAME_WIDTH_OVERLAP: 兩個(gè)矩形的橫向坐標(biāo)或者縱向坐標(biāo)一致,并且重疊。
//ANCHOR_OVERLAP: 重疊矩形的三條邊與被判定矩形的三條邊重疊(3個(gè)邊)
//INSIDE_OVERLAP: 重疊矩形與被判定矩形的其中之一完全重合(4個(gè)邊)
//CROSS_OVERLAP : 重疊矩形的平行的兩條邊與被判定矩形之一的對(duì)應(yīng)兩條邊重疊,另兩條邊與另一個(gè)被判定矩形的對(duì)應(yīng)的另兩條邊重疊(2對(duì)對(duì)應(yīng)的兩條邊)
//后三種的相同部分是都有平行的兩條邊重合,所以判定先重后三行開始
EM_RectOverlapType JudgeOverlapTypeByTwoRect(const EM_RECT& firstRect,const EM_RECT& overlapRect)
{if ( (overlapRect.left == firstRect.left) && (overlapRect.right==firstRect.right))//平行2條邊{if ( (overlapRect.top == firstRect.top) )//3條邊{if (overlapRect.bottom == firstRect.bottom)//4條邊{return INSIDE_OVERLAP;}else{return ANCHOR_OVERLAP;}}else if (overlapRect.bottom == firstRect.bottom){if (overlapRect.top == firstRect.top){return INSIDE_OVERLAP;}else{return ANCHOR_OVERLAP;}}else{return SAME_WIDTH_OVERLAP;}}else if ((overlapRect.top == firstRect.top) && (overlapRect.bottom == firstRect.bottom) ){return SAME_WIDTH_OVERLAP;}else {return CORNER_OVERLAP;}
}EM_RectOverlapType JudgeOverlapType(const EM_RECT& firstRect,const EM_RECT& secondRect,const EM_RECT& overlapRect)
{EM_RectOverlapType firstType = JudgeOverlapTypeByTwoRect(firstRect,overlapRect);if (ERROR_OVERLAP != firstType){ return firstType;}else{EM_RectOverlapType secondType = JudgeOverlapTypeByTwoRect(secondRect,overlapRect); if (ERROR_OVERLAP != secondType){return secondType;}else{return ERROR_OVERLAP;}}
}EM_RectOverlapType GetRectOverlapType(const EM_RECT& firstRect,const EM_RECT& secondRect)
{EM_RECT overlapRect = GetOverlapRect(firstRect,secondRect);long overlapRectSize = GetEM_RECTSize(overlapRect);if (overlapRectSize){return JudgeOverlapType(firstRect,secondRect,overlapRect);}else{return NO_OVERLAP;}
}
轉(zhuǎn)載于:https://www.cnblogs.com/Dennis-mi/p/3812072.html
總結(jié)
- 上一篇: Android 监听 Android中监
- 下一篇: windows下python安装Nump