public void SnapPoint(ref Point snapPosition, out double snapAngle)
        {
            snapAngle = 0;

            PointCollection points = line.Points;

            if (points.Count < 2)
            {
                return;
            }

            Point  bestSnapPoint    = new Point(Double.NaN, Double.NaN);
            double bestSnapLengthSq = double.PositiveInfinity;

            Point lastPoint = points[0];

            for (int i = 1; i < points.Count; i++)
            {
                Point curPoint = points[i];
                AnchorPoint.SnapToLineSegment(lastPoint, curPoint, snapPosition, ref bestSnapLengthSq, ref bestSnapPoint, ref snapAngle);
                lastPoint = curPoint;
            }

            snapPosition = bestSnapPoint;
        }
Exemplo n.º 2
0
        private void snapToPolygon(PointCollection points, Point origin, ref double bestSnapLengthSq, ref Point bestSnapPoint, ref double snapAngle)
        {
            var cv = CanvasView.GetCanvasView(this);

            if (cv == null)
            {
                return;
            }

            Vector thisOffset = cv.ElementFromControl(this).GetPositionAttributes() - new Point(0, 0);

            for (int i = 0; i < points.Count; i++)
            {
                Point from = points[i] + thisOffset;
                Point to   = points[(i + 1) % points.Count] + thisOffset;
                AnchorPoint.SnapToLineSegment(from, to, origin, ref bestSnapLengthSq, ref bestSnapPoint, ref snapAngle);
            }
        }
Exemplo n.º 3
0
        public void SnapPoint(ref Point snapPosition, out double snapAngle)
        {
            snapAngle = 0;

            var cv = CanvasView.GetCanvasView(this);

            if (cv == null)
            {
                return;
            }

            Point pos = cv.ElementFromControl(this).Position;

            // An array of line segments, each line segment represented as four double values.
            double[] shape =
            {
                pos.X,               pos.Y,
                pos.X,               pos.Y + ActualHeight,

                pos.X,               pos.Y + ActualHeight,
                pos.X + ActualWidth, pos.Y + ActualHeight,

                pos.X + ActualWidth, pos.Y + ActualHeight,
                pos.X + ActualWidth, pos.Y,

                pos.X + ActualWidth, pos.Y,
                pos.X,               pos.Y,
            };

            Point  bestSnapPoint    = new Point(double.NaN, double.NaN);
            double bestSnapLengthSq = double.PositiveInfinity;

            for (int i = 0; i < shape.Length; i += 4)
            {
                Point from = new Point(shape[i], shape[i + 1]);
                Point to   = new Point(shape[i + 2], shape[i + 3]);

                AnchorPoint.SnapToLineSegment(from, to, snapPosition, ref bestSnapLengthSq, ref bestSnapPoint, ref snapAngle);
            }

            snapPosition = bestSnapPoint;
        }