Rectangle Aread
C Code
#include <stdio.h>
int computeArea(int A,int B,int C,int D,int E,int F,int G,int H){
float ALX = (C-A) ;
float ALY = (D-B) ;
float BLX = (G-E) ;
float BLY = (H-F) ;
float PAX = (float)(C+A) / 2;
float PAY = (float)(D+B) / 2;
float PBX = (float)(G+E) / 2;
float PBY = (float)(H+F) / 2;
float LABX = PAX-PBX>0?PAX-PBX:PBX-PAX;
float LABY = PAY-PBY>0?PAY-PBY:PBY-PAY;
float MAX_X = ALX<BLX?ALX:BLX;
float MAX_Y = ALY<BLY?ALY:BLY;
if( LABX >= (float)((ALX+BLX)/2) || LABY >=(float)((ALY+BLY)/2)) {return ALX*ALY+BLX*BLY;}
else{
if( LABX <= ((ALX>BLX?ALX/2:BLX/2)-2*(ALX>BLX?BLX/2:ALX/2)) && LABY <= ((ALY>BLY?ALY/2:BLY/2)-2*(ALY>BLY?BLY/2:ALY/2))){
return ALX>BLX?ALX*ALY:BLX*BLY;
}
else{
return ALX*ALY+BLX*BLY - ((ALX+BLX)/2-LABX> MAX_X?MAX_X:(ALX+BLX)/2-LABX) * ((ALY+BLY)/2-LABY > MAX_Y?MAX_Y:(ALY+BLY)/2-LABY);
}
}
}
int main(){
int m = computeArea(-2,-2,2,2,-3,-3,3,-1);
printf("%d\n",m);
return 0;
}