Problem adding IntersectionPoint

Nov 11, 2010 at 8:22 PM

Hi Kirill,

I studied your sample and now I think I know a lot more about the sequence of building complex shapes, like a rectangle.  I took your advice and created a macro to create a rectangle and used SquareCreator as an example.  I wish I could tell you that I got it working 100% without problem, but, I fell short at one of the steps.  Here is the code I came up with and it almost works, but, I can't seem to correctly add an IntersectionPoint.  I built a class called RectangleCreator.  Can you see what I am leaving out?  I think your original advice lead me to learn so much more about LG.  Thanks!

Best regards,

using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using System.Diagnostics;

namespace DynamicGeometry
    public class RectangleCreator : ShapeCreator
        protected override IEnumerable<IFigure> CreateFigures()
            var p1 = FoundDependencies[0] as IPoint;
            var p2 = FoundDependencies[1] as IPoint;

            var side0 = Factory.CreateSegment(Drawing, p1, p2);
            var perpendicular = Factory.CreatePerpendicularLine(Drawing, new IFigure[] { side0, p1 });
            var pointonfigure = Factory.CreatePointOnFigure(Drawing, perpendicular, new Point());           
            var parallel1 = Factory.CreateParallelLine(Drawing, new IFigure[] { perpendicular, p2 });
            var parallel2 = Factory.CreateParallelLine(Drawing, new IFigure[] { side0, pointonfigure });
            //Kirill, problems start when intersection is added.            
            var intersection = Factory.CreateIntersectionPoint(Drawing, parallel1, parallel2, IntersectionAlgorithms.IntersectLineAndLine(parallel1, parallel2));

            var side1 = Factory.CreateSegment(Drawing, p2, intersection);

            var side2 = Factory.CreateSegment(Drawing, intersection, pointonfigure);

            var side3 = Factory.CreateSegment(Drawing, pointonfigure, p1);

            var polygon = Factory.CreatePolygon(Drawing, new IFigure[] { p1, p2, intersection, pointonfigure });

            #region for debugging purposes

            //perpendicular.Name = "perpendicular";
            //parallel1.Name = "parallel1";
            //parallel2.Name = "parallel2";
            //side0.Name = "side0";
            //pointonfigure.Name = "POF";
            //intersection.Name = "I";

            //PointLabel plA = Factory.CreatePointLabel(Drawing, new IFigure[] {p1});
            //plA.ShowName = true;
            //PointLabel plB = Factory.CreatePointLabel(Drawing, new IFigure[] { p2 });
            //plB.ShowName = true;
            //PointLabel plPOF = Factory.CreatePointLabel(Drawing, new IFigure[] { pointonfigure });
            //plPOF.ShowName = true;
            //PointLabel plI = Factory.CreatePointLabel(Drawing, new IFigure[] { intersection });
            //plI.ShowName = true;
            #endregion //for debugging purposes

            var added = new IFigure[]

            perpendicular.Visible = false;
            parallel1.Visible = false;
            parallel2.Visible = false;

            foreach (var item in added)
                yield return item;

        protected override DependencyList InitExpectedDependencies()
            return DependencyList.PointPoint;

        public override string Name
            get { return "Rectangle"; }

        public override FrameworkElement CreateIcon()
            double a = 0.2, b = 0.6, c = 0.8;
            return IconBuilder.BuildIcon()
                    new SolidColorBrush(Color.FromArgb(255, 128, 255, 128)),
                    new SolidColorBrush(Colors.Black),
                    new Point(a, a),
                    new Point(b, a),
                    new Point(b, c),
                    new Point(a, c))
                .Line(a, a, b, a)
                .Line(b, a, b, c)
                .Line(b, c, a, c)
                .Line(a, c, a, a)
                .DependentPoint(a, a)
                .DependentPoint(b, a)
                .Point(b, c)
                .Point(a, c)

        public override string HintText
                return "Create a rectangle";
Nov 12, 2010 at 7:25 AM


your code is correct. It revealed a bug in my code, which I've just fixed. Get the latest version of the source code (bug fix is in FigureCreator.cs) and you should be good.

Hope this helps,


Nov 12, 2010 at 2:23 PM


All I can say is "wooo - hooo"!!!! Yes!  ... Got it :-)

I hope all is well,