public Bitmap DrawIt(IFigure figure, Pen pen) { _tmpBitmap = (Bitmap)_mainBitmap.Clone(); _graphics = Graphics.FromImage(_tmpBitmap); //графикс рисует на временном битмапе figure.Painter.DrawFigure(pen, _graphics, figure.GetPoints()); if (figure.IsFilled == true) { figure.Filler.FillFigure(pen, _graphics, figure.GetPoints()); } return(_tmpBitmap); }
/// <summary> Проверка на коллизию </summary> public bool CheckCollision(IFigure figureA, IFigure figureB) { // нашли пересечение отрезков List <string> linesA = new List <string>() { }; for (int i = 0; i < figureA.GetPoints().Count - 1; i++) { linesA.Add(figureA.GetPoints()[i].X + "," + figureA.GetPoints()[i].Y + ";" + figureA.GetPoints()[i + 1].X + "," + figureA.GetPoints()[i + 1].Y + ";"); } List <string> linesB = new List <string>() { }; for (int i = 0; i < figureB.GetPoints().Count - 1; i++) { linesB.Add(figureB.GetPoints()[i].X + "," + figureB.GetPoints()[i].Y + ";" + figureB.GetPoints()[i + 1].X + "," + figureB.GetPoints()[i + 1].Y + ";"); } bool collision = false; linesA.ForEach(_A => { linesB.ForEach(_B => { PointF startA = new PointF(int.Parse(_A.Split(';')[0].Split(',')[0]), int.Parse(_A.Split(';')[0].Split(',')[1])); PointF endA = new PointF(int.Parse(_A.Split(';')[1].Split(',')[0]), int.Parse(_A.Split(';')[1].Split(',')[1])); PointF startB = new PointF(int.Parse(_B.Split(';')[0].Split(',')[0]), int.Parse(_B.Split(';')[0].Split(',')[1])); PointF endB = new PointF(int.Parse(_B.Split(';')[1].Split(',')[0]), int.Parse(_B.Split(';')[1].Split(',')[1])); if (CheckCollisionLines(startA, endA, startB, endB)) { collision = true; } }); }); if (collision) { return(true); } return(false); }
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (_mD) { _tmpbmp.Dispose(); _tmpbmp = (Bitmap)_bitmap.Clone(); _graphics = Graphics.FromImage(_tmpbmp); _crntFigure.Draw(_graphics, _pen, _crntFigure.GetPoints(new Point[] { _prev, e.Location }, checkBox1.Checked)); pictureBox1.Image = _tmpbmp; } }