예제 #1
0
        // ========================================
        // method
        // ========================================
        public override void Relocate(IFigure hostFigure)
        {
            _figure.Size = _figureSize;
            var middle = PointUtil.MiddlePoint(
                _request.PrevEdgePointRef.EdgePoint,
                _request.PrevEdgePointRef.Next.EdgePoint
                );

            _figure.Location = new Point(
                middle.X - _figureSize.Width / 2,
                middle.Y - _figureSize.Height / 2
                );
        }
예제 #2
0
        /// <summary>
        /// srcLocが原点で右方向に線が出ているように平行移動,回転して折れ点を計算.
        /// </summary>
        private Point[] FacedDirection(
            Point srcLoc, Point tgtLoc,
            Point srcTopLeft, Point srcBottomRight, Point tgtTopLeft, Point tgtBottomRight,
            Single angle
            )
        {
            var delta = new Size(-srcLoc.X, -srcLoc.Y);

            /// srcLocが原点になるように平行移動してから回転
            var trTgtLoc = ForwardTransform(tgtLoc, delta, angle);

            var trSrcTopLeft     = ForwardTransform(srcTopLeft, delta, angle);
            var trSrcBottomRight = ForwardTransform(srcBottomRight, delta, angle);

            var trTgtTopLeft     = ForwardTransform(tgtTopLeft, delta, angle);
            var trTgtBottomRight = ForwardTransform(tgtBottomRight, delta, angle);

            /// 平行移動・回転後のSourceとTargetのBoundsの各値
            var trSrcLeft   = trSrcTopLeft.X;
            var trSrcTop    = trSrcTopLeft.Y;
            var trSrcRight  = trSrcBottomRight.X;
            var trSrcBottom = trSrcBottomRight.Y;
            var trTgtLeft   = trTgtTopLeft.X;
            var trTgtTop    = trTgtTopLeft.Y;
            var trTgtRight  = trTgtBottomRight.X;
            var trTgtBottom = trTgtBottomRight.Y;

            var midLoc = PointUtil.MiddlePoint(Point.Empty, trTgtLoc);

            var ret = default(Point[]);

            if (trTgtLoc.X >= DefaultLength)
            {
                /// 両方connectedでなければ必ずこの条件
                ret = new [] {
                    new Point(midLoc.X, 0),
                    new Point(midLoc.X, trTgtLoc.Y),
                };
            }
            else
            {
                var y = default(int);
                if (trTgtTop > trSrcBottom)
                {
                    y = (trTgtTop + trSrcBottom) / 2;
                }
                else if (trTgtBottom < trSrcTop)
                {
                    y = (trSrcTop + trTgtBottom) / 2;
                }
                else
                {
                    var top = Math.Min(trSrcTop, trTgtTop);
                    var btm = Math.Max(trSrcBottom, trTgtBottom);

                    /// 原点(元srcLoc)とtopの距離 + trTgtLocとtopの距離
                    var distanceToTop = Math.Abs(0 - top) + Math.Abs(trTgtLoc.Y - top);
                    /// 原点(元srcLoc)とbtmの距離 + trTgtLocとbtmの距離
                    var distanceToBtm = Math.Abs(btm - 0) + Math.Abs(btm - trTgtLoc.Y);

                    if (distanceToTop < distanceToBtm)
                    {
                        y = top - DefaultLength;
                    }
                    else
                    {
                        y = btm + DefaultLength;
                    }
                }
                ret = new[] {
                    new Point(DefaultLength, 0),
                    new Point(DefaultLength, y),
                    new Point(trTgtLoc.X - DefaultLength, y),
                    new Point(trTgtLoc.X - DefaultLength, trTgtLoc.Y),
                };
            }

            for (int i = 0, len = ret.Length; i < len; ++i)
            {
                ret[i] = ReverseTransform(ret[i], -angle, (Size)srcLoc);
            }
            return(ret);
        }