恢复布尔多维数组 [英] Resume boolean multidimensional arrays
问题描述
问题是关于:
总结一个数组,得到矩形来总结这个数组,在例子中你可以看到3个矩形
[ 1,1 ,0, 1,1 ],
[ 1,1 ,0, 0, 1 ],
一个> Ini:0,0 To:{1,1}< br />
two> Ini:3,0 To:{4,0}< br />
三> Ini:4,1到:{4,1}< br />
很难解释...... >
我有一个多维数组的布尔值,表示已经改变的屏幕部分,我需要合并它们保持一个矩形,矩形发送几个可能,问题是,如何得到数组矩形的摘要....?
我认为这样的事情可能有效。
类型Point
{
int x,y
}
type Rectangle
{
Point upperLeft,lowerRight;
}
设S =在源数组中找到的矩形集
Let Result =空矩形列表
对于S $中的每个矩形A b $ b对于S中的每个矩形B不是A
设Tr =新矩形(
新点(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));
如果(A.Area + B.Area)/ Tr.Area> SomeThreshold那么//阈值可以是0.75,选择器越大
S.Remove(A)
S.Remove(B)
Result.Add(Tr)
对于S中的每个矩形(不是A或B)
如果我完全在Tr里面那么S.Remove (I)
结束
结束
结束
结束
抱歉伪我可能会在下班回家时尝试用C#来解决这个问题。
希望这会有所帮助,
Fredrik
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 ....?
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
这篇关于恢复布尔多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!