C语言 两个矩形的合并

function:仿opencv中 rect01 & rect02
不重叠矩形的合并及面积.
#include <stdio.h>

#define max(x,y)  ( x>y?x:y )
#define min(x,y)  ( x<y?x:y )

typedef struct  ss
{
	int a;
	int b;
}ss;
ss h;

typedef struct tag_rect_s
{
	int left;
	int right;
	int top;
	int bottom;
}Rect_s;


/************************************************************************************************************************************************************
* function : rect_or()
* return to a big_rect;
************************************************************************************************************************************************************/
Rect_s RectOr(Rect_s &a, Rect_s &b)
{
	int left = min(a.left, b.left);
	int right = max(a.right, b.right);
	int top = min(a.top, b.top);
	int bottom = max(a.bottom, b.bottom);

	Rect_s rect_or = Rect_s{ left ,right ,top ,bottom };
	return rect_or;
}


/************************************************************************************************************************************************************
* function : RectAarea()

************************************************************************************************************************************************************/

int RectAarea(Rect_s &a)
{
	return ((a.right - a.left)*(a.bottom - a.top));
}


int main()
{
	//ss h;
	h = ss{5,7};
	printf("\n %d %d\n", h.a,h.b);


	//Rect_s rect01 = Rect_s{ 10,100,10,100 };
	//Rect_s rect01 = { 10,100,10,100 };
	Rect_s rect01{ 10,100,10,100 };
	
	Rect_s rect02 = Rect_s{ 150,300,120,200 };
	Rect_s rect03 = rect01;

	Rect_s rect_or = RectOr(rect03, rect02);
	printf("\n L=%d R=%d T=%d B=%d\n", rect_or.left, rect_or.right, rect_or.top, rect_or.bottom);

	int area=RectAarea(rect_or);
	printf("\n area_or = %d\n", area);


	getchar();
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值