私は外側の矩形と内側の矩形を持っています。交差する四角形を切り取った後、残りの四角形を返すにはどうすればよいですか?残りの外接矩形をRectangle.Intersectionから探します。
-2
A
答えて
0
これはRegion
classを使用することです表現する自然な方法、のようなもの:
var result = new Region(outer);
result.Exclude(inner);
あなたが本当にRectangle
構造体のリストが必要な場合、あなたはGetRegionScans
を使用してRectangleF
秒への変換を見ることができます恒等行列を使用してRectangle
にCeiling
またはFloor
を使用して変換します。
0
私は交差するものを除いてリストを返すこの関数を作成しました。
private IEnumerable<Rectangle> GetExternalRectangles(Rectangle surface, Rectangle test)
{
var result = new List<Rectangle>();
if (!test.IntersectsWith(surface)) return new List<Rectangle> { surface };
#region Top and Bottom
if (test.Top>surface.Top && test.Bottom < surface.Bottom) // test inside surface vertically
{
result.Add(new Rectangle(surface.Location, new Size(surface.Width, test.Top - surface.Top)));
result.Add(new Rectangle(new Point(surface.Left,test.Bottom), new Size(surface.Width, surface.Bottom-test.Bottom)));
}
if (test.Top > surface.Top && test.Bottom > surface.Bottom) // test inside surface vertically, overflow bottom
{
result.Add(new Rectangle(surface.Location, new Size(surface.Width, test.Top - surface.Top)));
//result.Add(new Rectangle(new Point(surface.Left,test.Bottom), new Size(surface.Width, surface.Bottom-test.Bottom)));
}
if (test.Top < surface.Top && test.Bottom < surface.Bottom) // test inside surface vertically, overflow top
{
//result.Add(new Rectangle(surface.Location, new Size(surface.Width, test.Top - surface.Top)));
result.Add(new Rectangle(new Point(surface.Left, test.Bottom), new Size(surface.Width, surface.Bottom - test.Bottom)));
}
#endregion
#region Lateral
if (test.Left > surface.Left && test.Right < surface.Right) // test inside surface horizontally
{
result.Add(new Rectangle(new Point(surface.Left,Math.Max(surface.Top,test.Top)), new Size(test.Left-surface.Left, Math.Min(surface.Bottom, test.Bottom)- Math.Max(surface.Top, test.Top))));
result.Add(new Rectangle(new Point(test.Right, Math.Max(surface.Top, test.Top)), new Size(surface.Right - test.Right, Math.Min(surface.Bottom, test.Bottom) - Math.Max(surface.Top, test.Top))));
}
if (test.Left > surface.Left && test.Right > surface.Right) // test inside surface horizontally, overflow right
{
result.Add(new Rectangle(new Point(surface.Left, Math.Max(surface.Top, test.Top)), new Size(test.Left - surface.Left, Math.Min(surface.Bottom, test.Bottom) - Math.Max(surface.Top, test.Top))));
//result.Add(new Rectangle(new Point(test.Right, Math.Max(surface.Top, test.Top)), new Size(surface.Right - test.Right, Math.Min(surface.Bottom, test.Bottom) - Math.Max(surface.Top, test.Top))));
}
if (test.Left < surface.Left && test.Right < surface.Right) // test inside surface horizontally, overflow left
{
//result.Add(new Rectangle(new Point(surface.Left, Math.Max(surface.Top, test.Top)), new Size(test.Left - surface.Left, Math.Min(surface.Bottom, test.Bottom) - Math.Max(surface.Top, test.Top))));
result.Add(new Rectangle(new Point(test.Right, Math.Max(surface.Top, test.Top)), new Size(surface.Right - test.Right, Math.Min(surface.Bottom, test.Bottom) - Math.Max(surface.Top, test.Top))));
}
#endregion
return result;
}
関連する問題
- 1. C#塗りつぶし矩形は空白を残す
- 2. 外接矩形内のすべてのテキストを取得
- 3. 中央矩形から最も離れた矩形を取得
- 4. 矩形が別の矩形に近いかどうかをチェックします。
- 5. 矩形の値にアクセスしますか?
- 6. マップから矩形を削除する
- 7. 矩形の検索矩形の配列からのポイントを含む
- 8. JavaFX- MouseEvents形状を円形から矩形に変換する
- 9. 2つの矩形がある場合、重なり領域を表す別の矩形を返します。
- 10. 配列からの矩形の交差
- 11. 矩形のエッジをカーブします
- 12. 矩形の残りの部分を2つの部分に分割して、2つの新しい矩形がより「squarish」になるようにするには、サブ矩形を付けます。
- 13. 矩形ペイントメソッド(MIDP)の塗りつぶし
- 14. Python OpenCV - 輪郭点の集合から最大の矩形を外挿する。
- 15. UIViewの境界矩形をフレーム矩形よりも大きくすることができますか?
- 16. 複数の色のD3.js矩形を塗りつぶしたり、複数の矩形に分割する
- 17. SVGの矩形要素に小さな隙間が残る
- 18. AWTの描画矩形が矩形のちらつきを引き起こしています
- 19. JPanelに矩形がありません
- 20. 矩形のリストが与えられたら、他の矩形に完全に含まれるすべての矩形を見つける方法は?
- 21. 矩形内の矩形のサイズを計算する
- 22. SDL DisplayFormatは矩形を表します
- 23. 矩形内の矩形を制限する
- 24. 矩形のマウスリスナー
- 25. カーソルをブロックまたは矩形から行に変更しますか?
- 26. イメージROIをEMGU CV ...の矩形以外の形状に設定していますか?
- 27. 隣接する矩形の境界を計算する
- 28. 形状分析は、他の形状から矩形を区別する
- 29. Androidは矩形の片側からの入力のみを許可します
- 30. バインドされた矩形からそれに含まれる回転矩形の座標への変換座標