@Test public void overlapAreaTest(){ rectangle=new OverlapRectangle(); int result=rectangle.computeArea(0,0,0,0,-1,-1,1,1); Assertions.assertEquals(4,result); }
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int areaSum = (C-A)*(D-B) + (G-E)*(H-F); if(E>=C || A>=G || B>=H || F>=D){ return areaSum; } int bX = Math.max(A, E); int bY = Math.max(B, F); int tX = Math.min(C, G); int tY = Math.min(D, H); int areaIntersect = (tX-bX)*(tY-bY); return areaSum - areaIntersect; }
OverlapRectangle { public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int areaSum = (C-A)*(D-B) + (G-E)*(H-F); if(E>=C || A>=G || B>=H || F>=D){ return areaSum; } int bX = Math.max(A, E); int bY = Math.max(B, F); int tX = Math.min(C, G); int tY = Math.min(D, H); int areaIntersect = (tX-bX)*(tY-bY); return areaSum - areaIntersect; } }
OverlapRectangle { public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int areaSum = (C-A)*(D-B) + (G-E)*(H-F); if(E>=C || A>=G || B>=H || F>=D){ return areaSum; } int bX = Math.max(A, E); int bY = Math.max(B, F); int tX = Math.min(C, G); int tY = Math.min(D, H); int areaIntersect = (tX-bX)*(tY-bY); return areaSum - areaIntersect; }  }
OverlapRectangle { public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int areaSum = (C-A)*(D-B) + (G-E)*(H-F); if(E>=C || A>=G || B>=H || F>=D){ return areaSum; } int bX = Math.max(A, E); int bY = Math.max(B, F); int tX = Math.min(C, G); int tY = Math.min(D, H); int areaIntersect = (tX-bX)*(tY-bY); return areaSum - areaIntersect; }  int computeArea(int A, int B,
                           int C, int D,
                           int E, int F,
                           int G, int H); }
OverlapRectangle { public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int areaSum = (C-A)*(D-B) + (G-E)*(H-F); if(E>=C || A>=G || B>=H || F>=D){ return areaSum; } int bX = Math.max(A, E); int bY = Math.max(B, F); int tX = Math.min(C, G); int tY = Math.min(D, H); int areaIntersect = (tX-bX)*(tY-bY); return areaSum - areaIntersect; }  int computeArea(int A, int B,
                           int C, int D,
                           int E, int F,
                           int G, int H);  }