コード例 #1
0
ファイル: MainForm.cs プロジェクト: amitprakash07/dx11
        private void PaintDiagramIncremental(Graphics g) {
            if (_graph != null) {

                g.Clear(BackColor);

                g.DrawLine(_sweepPen, splitPanel.Panel2.ClientRectangle.Left, _graph.SweepLine, splitPanel.Panel2.ClientRectangle.Right, _graph.SweepLine);

                var item = cbCircles.SelectedIndex;

                if (item == 1) {
                    var gp = new GraphicsPath();
                    foreach (var triangle in _graph.Triangles) {
                        var circle = new Circle(triangle.V1, triangle.V2, triangle.V3);
                        if (triangle.New) {
                            g.DrawEllipse(_newCirclePen, circle.GetRect());
                        } else {
                            gp.AddEllipse(circle.GetRect());
                        }
                    }
                    g.DrawPath(_circlePen, gp);
                } else if (item == 2) {
                    var gp = new GraphicsPath();
                    foreach (var triangle in _graph.Triangles) {
                        if (triangle.New) {
                            g.DrawPolygon(_newCirclePen, new[] { (PointF)triangle.V1, triangle.V2, triangle.V3 });
                        } else {
                            gp.AddPolygon(new[] { (PointF)triangle.V1, triangle.V2, triangle.V3 });
                        }
                    }
                    g.DrawPath(_circlePen, gp);
                }

                if (chkShowEdges.Checked) {
                    var gp = new GraphicsPath();

                    foreach (var segment in _graph.Segments) {
                        var start = segment.P1;
                        var end = segment.P2;
                        if (segment.New) {
                            g.DrawLine(_newEdgePen, start, end);
                        } else {
                            gp.AddLine(start, end);
                            gp.CloseFigure();
                        }
                    }
                    g.DrawPath(_edgePen, gp);
                }

                if (chkBeachline.Checked) {
                    
                    var gp = new GraphicsPath();
                    var beachLine = new Dictionary<int, float>();

                    foreach (var point in _graph.Sites.Except(_sitesToIgnore.ToList())) {
                        var drop = true;
                        for (int x = 0; x < g.VisibleClipBounds.Width; x++) {
                            var y = ParabolaY(point, _graph.SweepLine, x);
                            if (y > g.ClipBounds.Height) {
                                drop = false;
                                continue;

                            }
                            if (!beachLine.ContainsKey(x)) {
                                beachLine[x] = y;
                                drop = false;
                            } else if (beachLine[x] < y) {
                                beachLine[x] = y;
                                drop = false;
                            }
                        }
                        if (drop) {
                            _sitesToIgnore.Add(point);
                        }
                    }

                    for (int x = 0; x < beachLine.Count - 1; x++) {
                        gp.AddLine(x, beachLine[x], x + 1, beachLine[x + 1]);
                    }

                    g.DrawPath(_beachPen, gp);
                }


                if (chkShowVertices.Checked) {
                    var gp = new GraphicsPath();
                    foreach (var vertex in _graph.Vertices) {
                        var r = vertex.New ?
                            new RectangleF(vertex.X - 4, vertex.Y - 4, 8, 8)
                            : new RectangleF(vertex.X - 2, vertex.Y - 2, 4, 4)
                            ;
                        if (vertex.New) {
                            g.FillEllipse(_newVertBrush, r);
                        } else {
                            gp.AddEllipse(r);
                        }
                    }
                    g.DrawPath(new Pen(Color.Red), gp);
                }
                if (chkShowSites.Checked) {
                    var gp = new GraphicsPath();
                    foreach (var point in _graph.Sites) {
                        var r = point.New ? new RectangleF(point.X - 4, point.Y - 4, 8, 8) : new RectangleF(point.X - 2, point.Y - 2, 4, 4);
                        if (point.New) {
                            g.FillEllipse(_newSiteBrush, r);
                        } else {
                            gp.AddEllipse(r);
                        }
                    }
                    g.FillPath(_siteBrush, gp);
                }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: craigge/dx11
        private void PaintDiagramFull(Graphics g) {
            if (_graph != null) {

                g.Clear(BackColor);

                g.DrawLine(_sweepPen, splitPanel.Panel2.ClientRectangle.Left, _graph.SweepLine, splitPanel.Panel2.ClientRectangle.Right, _graph.SweepLine);

                var item = cbCircles.SelectedIndex;

                if (item == 1) {
                    var gp = new GraphicsPath();
                    foreach (var triangle in _graph.Triangles) {
                        var circle = new Circle(triangle.V1, triangle.V2, triangle.V3);
                        if (triangle.New) {
                            g.DrawEllipse(_newCirclePen, circle.GetRect());
                        } else {
                            gp.AddEllipse(circle.GetRect());
                        }
                    }
                    g.DrawPath(_circlePen, gp);
                } else if (item == 2) {
                    var gp = new GraphicsPath();
                    foreach (var triangle in _graph.Triangles) {
                        var circle = new Circle(triangle.V1, triangle.V2, triangle.V3);
                        if (triangle.New) {

                            g.DrawPolygon(_newCirclePen, new[] { (PointF)triangle.V1, triangle.V2, triangle.V3 });
                        } else {
                            gp.AddPolygon(new[] { (PointF)triangle.V1, triangle.V2, triangle.V3 });
                        }
                    }
                    g.DrawPath(_circlePen, gp);
                }
                if (chkShowEdges.Checked) {
                    var gp = new GraphicsPath();
                    foreach (var segment in _graph.Segments) {
                        var start = segment.P1;
                        var end = segment.P2;
                        if (segment.New) {
                            g.DrawLine(_newEdgePen, start, end);
                        } else {
                            gp.AddLine(start, end);
                            gp.CloseFigure();
                        }
                    }
                    g.DrawPath(_edgePen, gp);
                }


                if (chkShowVertices.Checked) {
                    var gp = new GraphicsPath();
                    foreach (var vertex in _graph.Vertices) {
                        var r = //vertex.New ? 
                            new RectangleF(vertex.X - 4, vertex.Y - 4, 8, 8)
                            //: new RectangleF(vertex.X - 2, vertex.Y - 2, 4, 4)
                            ;
                        if (vertex.New) {
                            g.FillEllipse(_newVertBrush, r);
                        } else {
                            gp.AddEllipse(r);
                        }
                    }
                    g.DrawPath(new Pen(Color.Red), gp);
                }
                if (chkShowSites.Checked) {
                    var gp = new GraphicsPath();
                    foreach (var point in _graph.Sites) {
                        var r = point.New ? new RectangleF(point.X - 4, point.Y - 4, 8, 8) : new RectangleF(point.X - 2, point.Y - 2, 4, 4);
                        if (point.New) {
                            g.FillEllipse(_newSiteBrush, r);
                        } else {
                            gp.AddEllipse(r);
                        }
                    }
                    g.FillPath(_siteBrush, gp);
                }
            }
        }