Exemplo n.º 1
0
 public bool Contains(DTSweepConstraint e)
 {
     return(Contains(e.P) && Contains(e.Q));
 }
Exemplo n.º 2
0
		public void AddEdge(DTSweepConstraint e)
		{
			if (this.Edges == null)
			{
				this.Edges = new List<DTSweepConstraint>();
			}
			this.Edges.Add(e);
		}
Exemplo n.º 3
0
 public void MarkConstrainedEdge(DTSweepConstraint edge)
 {
     MarkConstrainedEdge(edge.P, edge.Q);
 }
Exemplo n.º 4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            ITriangulatable t = DisplayObjects[mDisplayIndex];

            Text = "poly2tri test: " + t.FileName;

            float xmin = (float)t.MinX;
            float xmax = (float)t.MaxX;
            float ymin = (float)t.MinY;
            float ymax = (float)t.MaxY;

            var fx = e.Graphics;

            {
                Font textFont = new Font("Times New Roman", 12);
                System.Drawing.Brush textBrush = System.Drawing.Brushes.Black;
                fx.DrawString("space = Pause/Unpause", textFont, textBrush, new PointF(10.0f, 10.0f));
                fx.DrawString("left/right arrow (while paused) = prev/next example", textFont, textBrush, new PointF(10.0f, 30.0f));
                fx.DrawString("mouse wheel = zoom in/out", textFont, textBrush, new PointF(10.0f, 50.0f));
                fx.DrawString("drag = pan", textFont, textBrush, new PointF(10.0f, 70.0f));
                fx.DrawString("double-click = reset zoom/pan", textFont, textBrush, new PointF(10.0f, 90.0f));
            }

            if (mbPaused)
            {
                Font textFont = new Font("Times New Roman", 24);
                System.Drawing.Brush textBrush = System.Drawing.Brushes.Black;
                fx.DrawString("Paused", textFont, textBrush, new PointF((ClientSize.Width / 2.0f) - 20.0f, 10.0f));
            }

            if (xmin < xmax && ymin < ymax)
            {
                float   w            = xmax - xmin;
                float   h            = ymax - ymin;
                Point2D ctr          = new Point2D((double)ClientSize.Width / 2.0, (double)ClientSize.Height / 2.0);
                Point2D screenScaler = new Point2D((double)ClientSize.Width / (double)w, (double)ClientSize.Height / (double)h);
                Point2D zoomPoint    = new Point2D(-mZoomPoint.X, mZoomPoint.Y);
                zoomPoint.RotateDegrees(t.DisplayRotate);
                zoomPoint.Scale(1.0 / screenScaler.X, 1.0 / screenScaler.Y);
                float zoom = mZoomLevel * (float)Math.Min(screenScaler.X, screenScaler.Y);

                fx.TranslateTransform(ctr.Xf, ctr.Yf);
                fx.RotateTransform(t.DisplayRotate);
                fx.ScaleTransform(zoom, -zoom);
                fx.TranslateTransform((-(xmax + xmin) / 2.0f) - zoomPoint.Xf, (-(ymax + ymin) / 2.0f) - zoomPoint.Yf);

                var penConstrained = new Pen(Color.Red, 1.0f / zoom);
                //var penDelaunay = new Pen(Color.Blue, 1.0f / zoom);
                var penNormal     = new Pen(Color.Silver, 1.0f / zoom);
                var penErrorCase1 = new Pen(Color.Purple, 1.0f / zoom);
                var penErrorCase2 = new Pen(Color.Cyan, 1.0f / zoom);
                foreach (var tri in t.Triangles)
                {
                    PointF[] pts = new PointF[]
                    {
                        new PointF(tri.Points[0].Xf, tri.Points[0].Yf),
                        new PointF(tri.Points[1].Xf, tri.Points[1].Yf),
                        new PointF(tri.Points[2].Xf, tri.Points[2].Yf),
                    };
                    for (int i = 0; i < 3; ++i)
                    {
                        if (t.DisplayFlipX)
                        {
                            pts[i].X = xmax - (pts[i].X - xmin);
                        }
                        if (t.DisplayFlipY)
                        {
                            pts[i].Y = ymax - (pts[i].Y - ymin);
                        }
                    }
                    for (int i = 0; i < 3; ++i)
                    {
                        var curPen              = penNormal;
                        DTSweepConstraint edge  = null;
                        bool isConstrained      = tri.GetConstrainedEdgeCCW(tri.Points[i]);
                        bool hasConstrainedEdge = tri.GetEdgeCCW(tri.Points[i], out edge);
                        if (isConstrained || hasConstrainedEdge)
                        {
                            if (isConstrained && hasConstrainedEdge)
                            {
                                curPen = penConstrained;
                            }
                            else if (isConstrained && !hasConstrainedEdge)
                            {
                                // this will happen when edges are split and is expected
                                //curPen = penErrorCase1;
                                curPen = penConstrained;
                            }
                            else
                            {
                                curPen = penErrorCase2;
                            }
                        }
                        //else if (tri.GetDelaunayEdgeCCW(tri.Points[i]))
                        //{
                        //    curPen = penDelaunay;
                        //}
                        fx.DrawLine(curPen, pts[i], pts[(i + 1) % 3]);
                    }
                }
                fx.ResetTransform();

                {
                    Point2D imageMouseCoord = new Point2D(mMouseImageCoord.X, (double)ClientSize.Height - mMouseImageCoord.Y);
                    imageMouseCoord.Subtract(ctr);
                    imageMouseCoord.RotateDegrees(t.DisplayRotate);
                    imageMouseCoord.Scale(1.0 / mZoomLevel);
                    imageMouseCoord.Scale(1.0 / screenScaler.X, 1.0 / screenScaler.Y);
                    imageMouseCoord.Translate((w / 2.0) + zoomPoint.X, (h / 2.0) + zoomPoint.Y);
                    if (t.DisplayFlipX)
                    {
                        imageMouseCoord.X = (double)xmax - (imageMouseCoord.X - (double)xmin);
                    }
                    if (t.DisplayFlipY)
                    {
                        imageMouseCoord.Y = (double)ymax - (imageMouseCoord.Y - (double)ymin);
                    }

                    Font textFont = new Font("Times New Roman", 12);
                    System.Drawing.Brush textBrush = System.Drawing.Brushes.Black;
                    fx.DrawString("Image X: " + imageMouseCoord.X.ToString(), textFont, textBrush, new PointF(20.0f, ClientSize.Height - 40.0f));
                    fx.DrawString("Image Y: " + imageMouseCoord.Y.ToString(), textFont, textBrush, new PointF(20.0f, ClientSize.Height - 20.0f));
                    fx.DrawString("ZoomPoint X: " + zoomPoint.X.ToString(), textFont, textBrush, new PointF(300.0f, ClientSize.Height - 40.0f));
                    fx.DrawString("ZoomPoint Y: " + zoomPoint.Y.ToString(), textFont, textBrush, new PointF(300.0f, ClientSize.Height - 20.0f));
                    fx.DrawString("ZoomLevel: " + mZoomLevel.ToString(), textFont, textBrush, new PointF(ClientSize.Width - 150.0f, ClientSize.Height - 20.0f));

                    //fx.DrawString("MX: " + mMouseImageCoord.X.ToString(), textFont, textBrush, new PointF(600.0f, ClientSize.Height - 40.0f));
                    //fx.DrawString("MY: " + mMouseImageCoord.Y.ToString(), textFont, textBrush, new PointF(600.0f, ClientSize.Height - 20.0f));
                }
            }

            fx.DrawImage(ExampleData.Logo256x256, ClientSize.Width - kImageWidth - 10, 10, kImageWidth, kImageWidth);

            base.OnPaint(e);
        }