public static bool Comparsion(Tor a, Tor b) // в этой функции я отдельно рассматривал каждый из восьми случаев соотношения длинн и ширин двух выбранных прямоугольников { if (a.x1 - a.x2 <= b.x1 - b.x2) // Ширина первого не больше ширины второго { if (a.y1 - a.y2 <= b.y1 - b.y2) // { return((((a.y1 >= b.y2) & (a.y1 <= b.y1)) | ((a.y2 >= b.y2) & (a.y2 <= b.y1))) & (((a.x1 >= b.x2) & (a.x1 <= b.x1)) | ((a.x2 >= b.x2) & (a.x2 <= b.x1)))); } else// { return((((b.y1 >= a.y2) & (b.y1 <= a.y1)) | ((b.y2 >= a.y2) & (b.y2 <= a.y1))) & (((a.x1 >= b.x2) & (a.x1 <= b.x1)) | ((a.x2 >= b.x2) & (a.x2 <= b.x1)))); } } else { if (a.y1 - a.y2 <= b.y1 - b.y2) { return((((a.y1 >= b.y2) & (a.y1 <= b.y1)) | ((a.y2 >= b.y2) & (a.y2 <= b.y1))) & (((b.x1 >= a.x2) & (b.x1 <= a.x1)) | ((b.x2 >= a.x2) & (b.x2 <= a.x1)))); } else { return((((b.y1 >= a.y2) & (b.y1 <= a.y1)) | ((b.y2 >= a.y2) & (b.y2 <= a.y1))) & (((b.x1 >= a.x2) & (b.x1 <= a.x1)) | ((b.x2 >= a.x2) & (b.x2 <= a.x1)))); } } }
public static bool Comparsion(Tor a, Tor b) { if (a.x1 > b.x1) { if (a.y1 > b.y1) { return((b.x1 > a.x2) & (b.y1 > a.y2)); } if (a.y1 < b.y1) { return((b.x1 > a.x2) & (a.y1 > b.y2)); } else { return(b.x1 > a.x2); } } else { if (a.y1 > b.y1) { return((a.x1 > b.x2) & (((a.y1 > b.y1) & (b.y1 > a.y2)))); } if (a.y1 < b.y1) { return((a.x1 > b.x2) & (a.y1 > b.y2)); } else { return(a.x1 > b.x2); } } }
private void Form1_Load_1(object sender, EventArgs e) { dataGridView1.RowHeadersWidth = 50; dataGridView1.ScrollBars = ScrollBars.Both; dataGridView1.ColumnHeadersHeight = 40; dataGridView1.ColumnCount = width; dataGridView1.RowCount = ListBay.Capacity; label1.Text = "Общее кол-во " + Convert.ToString(ListBay.Capacity); for (int j = 0; j <= ListBay.Capacity - 1; ++j) { dataGridView1[0, j].Value = ListBay[j].x1; dataGridView1[1, j].Value = ListBay[j].x2; dataGridView1[2, j].Value = ListBay[j].y1; dataGridView1[3, j].Value = ListBay[j].y2; } List <Tor> ListAfter = Tor.ChoosingTriangles(ListBay, out height1); dataGridView2.RowHeadersWidth = 50; dataGridView2.ScrollBars = ScrollBars.Both; dataGridView2.ColumnHeadersHeight = 40; dataGridView2.ColumnCount = width; dataGridView2.RowCount = height1; label2.Text = "Кол-во непересекающихся " + Convert.ToString(height1); for (int j = 0; j <= ListBay.Capacity - 1; ++j) { dataGridView2[0, j].Value = ListAfter[j].x1; dataGridView2[1, j].Value = ListAfter[j].x2; dataGridView2[2, j].Value = ListAfter[j].y1; dataGridView2[3, j].Value = ListAfter[j].y2; } }