Ejemplo n.º 1
0
        private void LineTo(Vector p)
        {
            //Console.WriteLine("LineTo: " + p);

            if (IntersectingPolygon == null)
            {
                IntersectingPolygon = new PolygonModel();
            }

            if (!GeomMath.AlmostEqual(currentStartPoint, p))
            {
                IntersectingPolygon.Lines.Add(new LineModel {
                    StartPoint = new Vector {
                        X = currentStartPoint.X, Y = currentStartPoint.Y
                    },
                    EndPoint = new Vector {
                        X = p.X, Y = p.Y
                    }
                });
                currentStartPoint = new Vector {
                    X = p.X, Y = p.Y
                };
                //currentStartPoint = p; // point becomes start of next line
            }
        }
Ejemplo n.º 2
0
        public void AddPolygonLine(int xi1, int yi1, int xi2, int yi2,
                                   double xv1, double yv1, double xv2, double yv2)
        {
            if (ActivePolygon == null)
            {
                ActivePolygon = new PolygonModel();
            }

            double xp1 = xi1 * Config.XIncrement + Config.XStart;
            double yp1 = yi1 * Config.YIncrement + Config.YStart;
            double xp2 = xi2 * Config.XIncrement + Config.XStart;
            double yp2 = yi2 * Config.YIncrement + Config.YStart;

            var line = new Line();

            line.Stroke          = new SolidColorBrush(Colors.Red);
            line.StrokeThickness = 3;
            line.Fill            = new SolidColorBrush(Colors.Red);
            line.X1 = xp1;
            line.Y1 = yp1;
            line.X2 = xp2;
            line.Y2 = yp2;

            ActivePolygon.Lines.Add(new LineModel
            {
                StartPoint = new Vector {
                    X = xv1, Y = yv1, Alternates = new CanvasPoint {
                        DotIndexLeft = xi1, DotIndexTop = yi1
                    }
                },
                EndPoint = new Vector {
                    X = xv2, Y = yv2, Alternates = new CanvasPoint {
                        DotIndexLeft = xi2, DotIndexTop = yi2
                    }
                }
            });

            var cc = new CanvasComponent();

            cc.AddUiElement(line);

            line.Tag = ActivePolygon.Lines[ActivePolygon.Lines.Count - 1];

            polygonLinesInProgress.Add(cc);

            GetInputLayer().AddComponent(cc);

            // if we're at least completing a triangle...
            if (ActivePolygon.Lines.Count > 2)
            {
                // if endpoint of current line matches start point of first line, we're connecting
                // back to start of polygon
                if (GeomMath.AlmostEqual(new Vector {
                    X = xv2, Y = yv2
                }, ActivePolygon.Lines[0].StartPoint))
                {
                    CompletePolygon();
                }
            }
        }
Ejemplo n.º 3
0
        public bool AlmostEqual(DelaunayTriangle t2)
        {
            bool side1 = GeomMath.AlmostEqual(V1, t2.V1) || GeomMath.AlmostEqual(V1, t2.V2) || GeomMath.AlmostEqual(V1, t2.V3);
            bool side2 = GeomMath.AlmostEqual(V2, t2.V1) || GeomMath.AlmostEqual(V2, t2.V2) || GeomMath.AlmostEqual(V2, t2.V3);
            bool side3 = GeomMath.AlmostEqual(V3, t2.V1) || GeomMath.AlmostEqual(V3, t2.V2) || GeomMath.AlmostEqual(V3, t2.V3);

            return(side1 && side2 && side3);
        }
Ejemplo n.º 4
0
 public bool HasVertex(Vector v)
 {
     return(GeomMath.AlmostEqual(V1, v) || GeomMath.AlmostEqual(V2, v) || GeomMath.AlmostEqual(V3, v));
 }
Ejemplo n.º 5
0
 public bool AlmostEquals(DelaunayEdge de)
 {
     return((GeomMath.AlmostEqual(VStart, de.VStart) && GeomMath.AlmostEqual(VEnd, de.VEnd)) ||
            (GeomMath.AlmostEqual(VStart, de.VEnd) && GeomMath.AlmostEqual(VEnd, de.VStart)));
 }