Example #1
0
        public override void Recalculate()
        {
            var first  = this.Dependencies.Polygon(0);
            var second = this.Dependencies.Polygon(1);

            var newIntersections = Intersect(first, second);

            if (AreEqual(intersections, newIntersections))
            {
                return;
            }

            intersections = newIntersections;

            ClearChildren();

            foreach (var intersection in newIntersections)
            {
                var vertices = new List <PointBase>(intersection.Length);

                foreach (var vertex in intersection)
                {
                    var point = new PointBase();
                    point.MoveToCore(vertex);
                    point.Dependencies.Add(this);
                    vertices.Add(point);
                    AddChild(point);
                    Drawing.StyleManager.SetStyleIfAvailable(point, "DependentPointStyle");
                }

                for (int i = 0; i < intersection.Length; i++)
                {
                    var side = new Segment();
                    if (i == 0)
                    {
                        side.Dependencies.Add(vertices[intersection.Length - 1], vertices[0]);
                    }
                    else
                    {
                        side.Dependencies.Add(vertices[i - 1], vertices[i]);
                    }

                    AddChild(side);
                    Drawing.StyleManager.SetStyleIfAvailable(side, "OtherLine");
                }

                var polygon = new Polygon();
                polygon.Dependencies.AddRange(vertices);
                AddChild(polygon);
                Drawing.StyleManager.SetStyleIfAvailable(polygon, "OtherShape");
            }

            UpdateVisual();
        }
Example #2
0
        private void AddVertex()
        {
            var vertex = new PointBase();

            vertex.Drawing = Drawing;
            vertices.Add(vertex);
            Children.Add(vertex);
            if (Drawing != null)
            {
                vertex.OnAddingToCanvas(Drawing.Canvas);
            }
        }
Example #3
0
        void AddFigurePoint(IniFile.Section section, PointBase point, int index)
        {
            var pointSection1 = sectionLookup["Point" + section["Points" + index.ToString()]];

            point.Name = pointSection1["Name"];
            point.X    = pointSection1.ReadDouble("X");
            point.Y    = pointSection1.ReadDouble("Y");
            SetPointStyle(pointSection1, point);
            var pointIndex = GetPointIndex(section, index);

            points[pointIndex] = point;
        }
Example #4
0
        protected void AddVertex()
        {
            var vertex = new PointBase();

            vertex.Dependencies.Add(this);
            vertex.RegisterWithDependencies();
            vertex.Drawing = Drawing;
            vertices.Add(vertex);
            Children.Add(vertex);
            if (Drawing != null)
            {
                vertex.OnAddingToCanvas(Drawing.Canvas);
            }

            Drawing.StyleManager.SetStyleIfAvailable(vertex, "DependentPointStyle");
        }
Example #5
0
        public Expression ResolveTwoPoints(string twoPoints)
        {
            var drawing = Binder.Drawing;

            if (drawing == null)
            {
                return(null);
            }

            var    names         = drawing.Figures.Where(f => f is PointBase).Select(f => f.Name).ToArray();
            string longestPrefix = "";
            string longestSuffix = "";

            foreach (var name in names)
            {
                if (twoPoints.StartsWith(name, StringComparison.OrdinalIgnoreCase) && name.Length > longestPrefix.Length)
                {
                    longestPrefix = name;
                }
                if (twoPoints.EndsWith(name, StringComparison.OrdinalIgnoreCase) && name.Length > longestSuffix.Length)
                {
                    longestSuffix = name;
                }
            }

            if (longestPrefix.Length + longestSuffix.Length == twoPoints.Length)
            {
                PointBase point1 = drawing.Figures[longestPrefix] as PointBase;
                PointBase point2 = drawing.Figures[longestSuffix] as PointBase;

                if (point1 == null)
                {
                    Status.AddFigureIsNotAPointError(longestPrefix);
                    return(null);
                }
                if (point2 == null)
                {
                    Status.AddFigureIsNotAPointError(longestSuffix);
                    return(null);
                }
                if (!Binder.FigureAllowed(point1))
                {
                    Status.AddDependencyCycleError(longestPrefix);
                    return(null);
                }
                if (!Binder.FigureAllowed(point2))
                {
                    Status.AddDependencyCycleError(longestSuffix);
                    return(null);
                }

                ConstantExpression p1       = Expression.Constant(point1);
                ConstantExpression p2       = Expression.Constant(point2);
                MethodInfo         distance = typeof(Math).GetMethod("Distance",
                                                                     new[] { typeof(PointBase), typeof(PointBase) });
                MethodCallExpression result = Expression.Call(null, distance, p1, p2);
                Status.Dependencies.Add(point1);
                Status.Dependencies.Add(point2);
                return(result);
            }

            return(null);
        }
Example #6
0
 private void AddVertex()
 {
     var vertex = new PointBase();
     vertex.Drawing = Drawing;
     vertices.Add(vertex);
     Children.Add(vertex);
     if (Drawing != null)
     {
         vertex.OnAddingToCanvas(Drawing.Canvas);
     }
 }