Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.80/5 (3 votes)
See more:
The question is about:

As summarized an array, getting rectangles to summarize this array, in the example you can see 3 rectangles
[1,1,0,1,1],
[1,1,0,0,1],

one  > Ini: 0,0 To: {1,1}<br />
two  > Ini: 3,0 To: {4,0}<br />
three> Ini: 4,1 to: {4,1}<br />


its difficult to explain...

I have one multidimensional array of booleans that represent portions of the screen that have changed, I need to merge them keeping a rectangle, rectangles to send few possible, the question is, how to get the summary of the rectangles of the array ....?
Posted
Updated 11-Nov-13 2:20am
v5
Comments
Kamran Ayati 11-Nov-13 2:57am    
i dont know your question meaning?
Abhinav S 11-Nov-13 2:59am    
Your question is not clear?
Sergey Alexandrovich Kryukov 11-Nov-13 3:03am    
I guess it was really difficult to explain it, so difficult that you actually failed to explain anything: I did not understand it at all.
More importantly, this is not a question at all.
—SA
Fredrik Bornander 11-Nov-13 3:41am    
Is your problem finding the different rectangles in the source array or is it (as you say) to "merge" them?

In the above example you've found rectangles
(0,0)-(1,1)
(3,0)-(4,0)
(4,1)-(4,1)
is there a reason as to why you picked those three over
(0,0)-(1,1)
(3,0)-(3,0)
(4,0)-(4,1)?
BillWoodruff 11-Nov-13 6:39am    
That's the kind of helpful comment I wish I saw more of here.

1 solution

I think something like this might work.
type Point
{ 
 int x,y
}

type Rectangle
{
  Point upperLeft, lowerRight;
}

Let S = the set of rectangles found in source array
Let Result = Empty list of rectangles

For every rectangle A in S
 For every rectangle B in S that is Not A
    Let Tr = new Rectangle(
      new Point(Min(A.upperleft.x, B.upperleft.X), Min(A.upperleft.Y, B.upperleft.Y)),
      new Point(Min(A.Lowerright.x, B.Lowerright.X), Min(A.Lowerright.Y, B.Lowerright.Y));
    
  If (A.Area + B.Area) / Tr.Area > SomeThreshold Then // The threshold can be something like 0.75 the bigger the picker
    S.Remove(A)
    S.Remove(B)
    Result.Add(Tr)
    For every rectangle I in S (that is not A or B)
      If I is completely inside Tr Then S.Remove(I)
    End
  End
 End
End 


Sorry about the pseudo code, I might try to know this up in C# when I get home from work.

Hope this helps,
Fredrik
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900