public void CalcTiles(Zones.TPolygon BoxRect, SizeF TileSize, double Gap) { Hashtable ht = new Hashtable(); double tmpH = BoxRect.Height + TileSize.Height * 2; double tmpW = BoxRect.Width + TileSize.Width * 2; List <Zones.TPolygon> TotalTiles = new List <Zones.TPolygon>(); if (Angle45.Checked) { double step_xy = Math.Sqrt(Math.Pow((double)TileSize.Width + Gap, 2.0) + Math.Pow((double)TileSize.Height + Gap, 2.0)); double y = 0;// TileSize.Height; while (y < tmpH) { double x = 0;// TileSize.Width; while (x < tmpW) { Zones.TPolygon pl; pl = GetPlitka45(new PointF((float)x, (float)y), TileSize); if (Zones.PolygonInPolygon(pl, BoxRect)) { TotalTiles.Add(pl); } pl = GetPlitka45(new PointF( (float)(x - step_xy / 2.0), (float)(y + step_xy / 2.0)), TileSize); if (Zones.PolygonInPolygon(pl, BoxRect)) { TotalTiles.Add(pl); } x += TileSize.Width * (double)Math.Sqrt(2) + Gap; } ; y += TileSize.Width * (double)Math.Sqrt(2) + Gap; } ; } ; if (Angle90.Checked) { double y = 0;// TileSize.Height; while (y < tmpH) { double x = 0;// TileSize.Width; while (x < tmpW) { Zones.TPolygon pl = GetPlitka90(new PointF((float)x, (float)y), TileSize); if (Zones.PolygonInPolygon(pl, BoxRect)) { TotalTiles.Add(pl); } x += TileSize.Width + Gap; } ; y += TileSize.Height + Gap; } ; } ; Bitmap b = null; Graphics g = null; if (!NoDraw.Checked) { b = new Bitmap((int)(BoxRect.Width + TileSize.Width * 2), (int)(BoxRect.Height + TileSize.Height * 2)); g = Graphics.FromImage(b); } ; int count_Black = 0; int count_Red = 0; int count_Green = 0; AreasCount ac_red = new AreasCount(); AreasCount ac_green = new AreasCount(); double DefaultTileArea = (new Zones.TPolygon(new Zones.TPoint(0, 0), TileSize)).Area; int tCo = 0; foreach (Zones.TPolygon CurrentTile in TotalTiles) { CurrentTile.Title = tCo++; Pen pen = new Pen(new SolidBrush(Color.Gray)); if (!NoDraw.Checked) { CurrentTile.Draw(g, pen, (int)TileSize.Width, (int)TileSize.Height); } Zones.TPolygon poly = CalcOutOfBoundsPoly(CurrentTile, BoxRect); if (poly != null) // выходит за границы { if (poly.Area <= (DefaultTileArea / 2.0)) // меньше половины плитки { ac_green[poly.Area]++; count_Green++; pen = new Pen(new SolidBrush(Color.Green)); poly.Title = CurrentTile.Title; if (!NoDraw.Checked) { poly.Draw(g, pen, (int)TileSize.Width, (int)TileSize.Height); } } else if (poly.Area >= (DefaultTileArea * 0.85)) // Плитка полностью входит площадь { count_Black++; pen = new Pen(new SolidBrush(Color.Black)); if (!NoDraw.Checked) { CurrentTile.Draw(g, pen, (int)TileSize.Width, (int)TileSize.Height); } } else // больше половины плитки { ac_red[poly.Area]++; count_Red++; pen = new Pen(new SolidBrush(Color.Red)); if (!NoDraw.Checked) { CurrentTile.Draw(g, pen, (int)TileSize.Width, (int)TileSize.Height); } }; } ; } ; SolidBrush br = new SolidBrush(Color.FromArgb(80, Color.Navy)); if (!NoDraw.Checked) { BoxRect.Draw(g, new Pen(new SolidBrush(Color.FromArgb(255, Color.Black))), (int)TileSize.Width, (int)TileSize.Height); pictureBox1.Image = b; pictureBox1.Image.Save(GetCurrentDir() + @"\Calced.bmp"); } ; textBox9.Text = "Черных: " + count_Black.ToString() + "\r\n"; textBox9.Text += " " + DefaultTileArea.ToString() + ": " + count_Black.ToString() + "\r\n"; textBox9.Text += "Красных: " + count_Red.ToString() + "\r\n"; foreach (double d in ac_red.Areas) { textBox9.Text += " " + d.ToString() + ": " + ac_red[d].ToString() + "\r\n"; } textBox9.Text += "Зеленых: " + count_Green.ToString() + "\r\n"; foreach (double d in ac_green.Areas) { textBox9.Text += " " + d.ToString() + ": " + ac_green[d].ToString() + "\r\n"; } }
public void CalcTiles(Zones.TPolygon BoxRect, SizeF TileSize, double Gap) { Hashtable ht = new Hashtable(); double tmpH = BoxRect.Height + TileSize.Height * 2; double tmpW = BoxRect.Width + TileSize.Width * 2; List <Zones.TPolygon> TotalTiles = new List <Zones.TPolygon>(); if (Angle45.Checked) { double step_xy = (TileSize.Width + Gap) * Math.Sqrt(2); double y = 0; while (y < tmpH) { double x = 0; while (x < tmpW) { Zones.TPolygon pl; pl = GetPlitka45(new PointF((float)x, (float)y), TileSize); if (Zones.PolygonInPolygon(pl, BoxRect)) { TotalTiles.Add(pl); } pl = GetPlitka45(new PointF( (float)(x - step_xy / 2.0), (float)(y + step_xy / 2.0)), TileSize); if (Zones.PolygonInPolygon(pl, BoxRect)) { TotalTiles.Add(pl); } x += step_xy; } ; y += step_xy; } ; } ; if (Angle90.Checked) { double y = 0;// wallPlan.Gap; while (y < tmpH) { double x = 0;//wallPlan.Gap; while (x < tmpW) { Zones.TPolygon pl = GetPlitka90(new PointF((float)x, (float)y), TileSize); if (Zones.PolygonInPolygon(pl, BoxRect)) { TotalTiles.Add(pl); } x += TileSize.Width + Gap; } ; y += TileSize.Height + Gap; } ; } ; Bitmap b = null; Graphics g = null; int scaleSize = 1; if (TileSize.Width >= 100) { if (gOneTwo.Checked) { scaleSize = 2; } if (gOneThree.Checked) { scaleSize = 3; } if (gOneFour.Checked) { scaleSize = 4; } if (gOneFive.Checked) { scaleSize = 5; } if (gOneTen.Checked) { scaleSize = 10; } } ; if (makeImage.Checked) { b = new Bitmap((int)((BoxRect.Width + TileSize.Width * 2) / scaleSize), (int)((BoxRect.Height + TileSize.Height * 2) / scaleSize)); g = Graphics.FromImage(b); Zones.TPolygon pBox = new Zones.TPolygon(new Zones.TPoint(0 - TileSize.Width, 0 - +TileSize.Height), new SizeF((float)(BoxRect.Width + TileSize.Width * 2), (float)(BoxRect.Height + TileSize.Height * 2))); g.FillRectangle(new SolidBrush(Color.FromArgb(50, Color.Silver)), new Rectangle(0, 0, b.Width, b.Height)); PointF[] pts = new PointF[BoxRect.Dots.Length]; for (int i = 0; i < pts.Length; i++) { pts[i] = new PointF((float)((BoxRect.Dots[i].X + TileSize.Width) / scaleSize), (float)((BoxRect.Dots[i].Y + TileSize.Height) / scaleSize)); } g.FillPolygon(new SolidBrush(Color.White), pts); } ; Area1Storage ac_black = new Area1Storage(); Area1Storage ac_red = new Area1Storage(); Area1Storage ac_green = new Area1Storage(); double DefaultTileArea = (new Zones.TPolygon(new Zones.TPoint(0, 0), TileSize)).Area; int tCo = 0; foreach (Zones.TPolygon CurrentTile in TotalTiles) { TileIdentity tid = new TileIdentity(new Pen(new SolidBrush(Color.Gray)), ++tCo); CurrentTile.ID = tid; if (makeImage.Checked) { CurrentTile.Draw(g, tid.pen, (int)TileSize.Width, (int)TileSize.Height, scaleSize); } Zones.TPolygon poly = CalcOutOfBoundsPoly(CurrentTile, BoxRect, ClipperLib.ClipType.ctIntersection)[0]; if (poly != null) // выходит за границы { if (poly.Area <= (DefaultTileArea / 2.0)) // меньше половины плитки { ac_green.Add(poly.Area, ((TileIdentity)CurrentTile.ID).ID); tid.pen = new Pen(new SolidBrush(Color.Green)); } else if (poly.Area >= (DefaultTileArea * 0.85)) // Плитка полностью входит площадь { ac_black.Add(DefaultTileArea, ((TileIdentity)CurrentTile.ID).ID); tid.pen = new Pen(new SolidBrush(Color.Black)); } else // больше половины плитки { ac_red.Add(poly.Area, ((TileIdentity)CurrentTile.ID).ID); tid.pen = new Pen(new SolidBrush(Color.Red)); }; } ; } ; LoadWallPlan(); StatusList.Text += "\r\n"; StatusList.Text += "Черных: " + ac_black.TilesCount.ToString() + "\r\n"; foreach (double d in ac_black.Areas) { StatusList.Text += " " + d.ToString() + ": " + ac_black.Get(d).Length.ToString() + "\r\n"; } StatusList.Text += "Красных: " + ac_red.TilesCount.ToString() + "\r\n"; foreach (double d in ac_red.Areas) { StatusList.Text += " " + d.ToString() + ": " + ac_red.Get(d).Length.ToString() + "\r\n"; } StatusList.Text += "Зеленых: " + ac_green.TilesCount.ToString() + "\r\n"; foreach (double d in ac_green.Areas) { StatusList.Text += " " + d.ToString() + ": " + ac_green.Get(d).Length.ToString() + "\r\n"; } StatusList.Text += "------------\r\nВсего: " + TotalTiles.Count.ToString() + "\r\n\r\n"; // CALC MERGE Area1Storage ac_all = new Area1Storage(); foreach (double d in ac_red.Areas) { ac_all.Add(d, ac_red.Get(d)); } foreach (double d in ac_green.Areas) { ac_all.Add(d, ac_green.Get(d)); } Area2AreaStorage a2c = new Area2AreaStorage(); while (ac_all.Areas.Length > 0) { double val1 = ac_all.Areas[0]; double val2 = 0; int tile1 = ac_all.Get(val1)[0]; int tile2 = 0; double max1 = val1 + val2; ac_all.Remove(val1, tile1); for (int i = 0; i < ac_all.Areas.Length; i++) { double tmp_max = val1 + ac_all.Areas[i]; if ((tmp_max > max1) && (tmp_max < DefaultTileArea)) { max1 = tmp_max; val2 = ac_all.Areas[i]; } ; } ; if (val2 > 0) { tile2 = ac_all.Get(val2)[0]; ac_all.Remove(val2, tile2); } ; a2c.Add(val1, val2, tile1, tile2); } ; if (makeImage.Checked) { if (drawWalls.Checked) { BoxRect.Draw(g, new Pen(new SolidBrush(Color.FromArgb(150, Color.Navy)), 1), (int)TileSize.Width, (int)TileSize.Height, scaleSize); } int btc = 0; foreach (double d in ac_black.Areas) { foreach (int id in ac_black.Get(d)) { foreach (Zones.TPolygon CurrentTile in TotalTiles) { if (((TileIdentity)CurrentTile.ID).ID == id) { CurrentTile.Title = (++btc).ToString(); if (tileEnum.Checked) { CurrentTile.DrawTitle(g, ((TileIdentity)CurrentTile.ID).pen, (int)TileSize.Width, (int)TileSize.Height, scaleSize, wallPlan.Angle); } } } } } ; foreach (Area2AreaStorage.TileTwinStorage a12 in a2c.Areas) { foreach (int[] ids in a12.TileTwins) { btc++; foreach (Zones.TPolygon CurrentTile in TotalTiles) { if ((((TileIdentity)CurrentTile.ID).ID == ids[0]) || (((TileIdentity)CurrentTile.ID).ID == ids[1])) { CurrentTile.Title = btc.ToString(); CurrentTile.Fill(g, new Pen(new SolidBrush(Color.FromArgb(25, (((TileIdentity)CurrentTile.ID).pen.Color)))), (int)TileSize.Width, (int)TileSize.Height, scaleSize); if (tileEnum.Checked) { CurrentTile.DrawTitle(g, ((TileIdentity)CurrentTile.ID).pen, (int)TileSize.Width, (int)TileSize.Height, scaleSize, wallPlan.Angle); } } } ; } } ; pictureBox1.Image = b; } ; int ttl = 0; foreach (Area2AreaStorage.TileTwinStorage a12 in a2c.Areas) { ttl += a12.TileTwins.Count; } StatusList.Text += "\r\n"; StatusList.Text += "С компоновкой: " + ac_black.TilesCount.ToString() + " + " + ttl.ToString() + " = " + (ac_black.TilesCount + ttl).ToString() + "\r\n"; foreach (double d in ac_black.Areas) { StatusList.Text += " " + d.ToString() + ": " + ac_black.Get(d).Length.ToString() + "\r\n"; } foreach (Area2AreaStorage.TileTwinStorage a12 in a2c.Areas) { StatusList.Text += " " + a12.area1.ToString() + "+" + a12.area2.ToString() + ": " + a12.TileTwins.Count.ToString() + "\r\n"; } // SQUARE StatusList.Text += "\r\n"; StatusList.Text += "Площадь контура: " + BoxRect.Area.ToString() + " мм2\r\n"; Zones.TPolygon tilp = new Zones.TPolygon(new Zones.TPoint(0, 0), new SizeF((float)(wallPlan.TileWidth + Gap), (float)(wallPlan.TileHeight + Gap))); StatusList.Text += "Площадь плитки: " + tilp.Area.ToString() + " мм2\r\n"; int tilesSquare = (int)Math.Truncate(BoxRect.Area / tilp.Area + 1); StatusList.Text += "Плиток по площади: " + tilesSquare.ToString() + "\r\n"; }