public Point GetConnectionPoint(IAnchor anchor, INode node, Point location) { var outerFrame = node.OuterFrame; switch (_connectionMethod) { case ConnectionMethodKind.Intersect: { var nextLoc = anchor.Kind == ConnectionAnchorKind.Source? FirstRef.Next.EdgePoint: LastRef.Prev.EdgePoint; var line = new Line(location, nextLoc); if (outerFrame.IntersectsWith(line)) { return(outerFrame.GetIntersectionPoint(line)); } else { /// 交わってなければ仕方がないのでNearestを返しておく return(outerFrame.GetNearestPoint(line.Start)); } } case ConnectionMethodKind.UpperSideMidpoint: { var bounds = node.Bounds; var center = RectUtil.GetCenter(bounds); return(anchor.Kind == ConnectionAnchorKind.Source ? outerFrame.GetNearestPoint(new Point(center.X, bounds.Top)): outerFrame.GetNearestPoint(new Point(center.X, bounds.Bottom))); } case ConnectionMethodKind.LowerSideMidpoint: { var bounds = node.Bounds; var center = RectUtil.GetCenter(bounds); return(anchor.Kind == ConnectionAnchorKind.Source ? outerFrame.GetNearestPoint(new Point(center.X, bounds.Bottom)): outerFrame.GetNearestPoint(new Point(center.X, bounds.Top))); } case ConnectionMethodKind.LeftSideMidpoint: { var bounds = node.Bounds; var center = RectUtil.GetCenter(bounds); return(anchor.Kind == ConnectionAnchorKind.Source ? outerFrame.GetNearestPoint(new Point(bounds.Left, center.Y)): outerFrame.GetNearestPoint(new Point(bounds.Right, center.Y))); } case ConnectionMethodKind.RightSideMidpoint: { var bounds = node.Bounds; var center = RectUtil.GetCenter(bounds); return(anchor.Kind == ConnectionAnchorKind.Source ? outerFrame.GetNearestPoint(new Point(bounds.Right, center.Y)): outerFrame.GetNearestPoint(new Point(bounds.Left, center.Y))); } case ConnectionMethodKind.SideMidpointOfOpposite: { var oppositeLoc = anchor.Kind == ConnectionAnchorKind.Source? LastRef.EdgePoint: FirstRef.EdgePoint; var bounds = node.Bounds; var dir = RectUtil.GetDirectionStraightlyFromCenter(bounds, oppositeLoc); var center = RectUtil.GetCenter(bounds); if (EnumUtil.HasAllFlags((int)dir, (int)Mkamo.Common.DataType.Directions.Left)) { return(outerFrame.GetNearestPoint(new Point(bounds.Left, center.Y))); } else if (EnumUtil.HasAllFlags((int)dir, (int)Mkamo.Common.DataType.Directions.Right)) { return(outerFrame.GetNearestPoint(new Point(bounds.Right, center.Y))); } else if (EnumUtil.HasAllFlags((int)dir, (int)Mkamo.Common.DataType.Directions.Up)) { return(outerFrame.GetNearestPoint(new Point(center.X, bounds.Top))); } else { /// } else if (EnumUtil.HasFlag((int) dir, (int) Mkamo.Common.DataType.Directions.Left)) { return(outerFrame.GetNearestPoint(new Point(center.X, bounds.Bottom))); } } case ConnectionMethodKind.SideMidpointOfNearest: { //var nearestLoc = outerFrame.GetNearestPoint(location); var bounds = node.Bounds; //var dir = RectUtil.GetDirectionStraightlyFromCenter(bounds, nearestLoc); var dir = RectUtil.GetNearestLineDirection(bounds, location); var center = RectUtil.GetCenter(bounds); if (EnumUtil.HasAllFlags((int)dir, (int)Mkamo.Common.DataType.Directions.Left)) { return(outerFrame.GetNearestPoint(new Point(bounds.Left, center.Y))); } else if (EnumUtil.HasAllFlags((int)dir, (int)Mkamo.Common.DataType.Directions.Right)) { return(outerFrame.GetNearestPoint(new Point(bounds.Right, center.Y))); } else if (EnumUtil.HasAllFlags((int)dir, (int)Mkamo.Common.DataType.Directions.Up)) { return(outerFrame.GetNearestPoint(new Point(center.X, bounds.Top))); } else { /// } else if (EnumUtil.HasFlag((int) dir, (int) Mkamo.Common.DataType.Directions.Left)) { return(outerFrame.GetNearestPoint(new Point(center.X, bounds.Bottom))); } } case ConnectionMethodKind.Nearest: return(outerFrame.GetNearestPoint(location)); case ConnectionMethodKind.Center: // todo: ちゃんと実装 // とりあえずこれでもCentralRouterが設定されていればすぐルーティングされるので問題なく動く return(outerFrame.GetNearestPoint(location)); case ConnectionMethodKind.Comment: if (anchor.Kind == ConnectionAnchorKind.Source) { var leftMiddle = new Point(node.Left, node.Top + node.Height / 2); return(outerFrame.GetNearestPoint(leftMiddle)); //return outerFrame.GetNearestPoint(location); } else { var pt = node.GetConnectionPoint(_targetConnectionOption); if (pt.HasValue) { return(pt.Value); } else { return(outerFrame.GetNearestPoint(location)); } } default: return(outerFrame.GetNearestPoint(location)); } }