Vector2 GetAnchorPos(Vector2 pointA, Rect wr2, Vector2 pointB)
{
//DiagramUtil.ExpandRect(wr2 , 10 , 10 ) ;
Vector2 arrowPos = new Vector2 ();
float left = wr2.x;
float right = wr2.x + wr2.width;
float top = wr2.y;
float bottom = wr2.y + wr2.height;
Vector2 topLeft = new Vector2 (wr2.x, wr2.y);
Vector2 topRight = new Vector2 (wr2.x + wr2.width, wr2.y);
Vector2 bottomLeft = new Vector2 (wr2.x, wr2.y + wr2.height);
Vector2 bottomRight = new Vector2 (wr2.x + wr2.width, wr2.y + wr2.height);
float ans1 = calcPosition (topLeft, bottomRight, pointA);
float ans2 = calcPosition (bottomLeft, topRight, pointA);
if (0 <= ans1 && 0 <= ans2) {
//Log("bottom");
float w1 = Mathf.Abs (pointB.y - pointA.y);
float w2 = Mathf.Abs (pointB.y - bottom);
float h1 = pointB.x - pointA.x;
float h2 = h1 * w2 / w1;
arrowPos.y = bottom;
arrowPos.x = pointB.x - h2;
} else if (0 > ans1 && 0 <= ans2) {
//Log("right");
float w1 = Mathf.Abs (pointB.x - pointA.x);
float w2 = Mathf.Abs (pointB.x - right);
float h1 = pointB.y - pointA.y;
float h2 = h1 * w2 / w1;
arrowPos.x = right;
arrowPos.y = pointB.y - h2;
} else if (0 <= ans1 && 0 > ans2) {
//Log("left");
float w1 = Mathf.Abs (pointB.x - pointA.x);
float w2 = Mathf.Abs (pointB.x - left);
float h1 = pointB.y - pointA.y;
float h2 = h1 * w2 / w1;
arrowPos.x = left;
arrowPos.y = pointB.y - h2;
} else if (0 > ans1 && 0 > ans2) {
//Log("top");
float w1 = Mathf.Abs (pointB.y - pointA.y);
float w2 = Mathf.Abs (pointB.y - top);
float h1 = pointB.x - pointA.x;
float h2 = h1 * w2 / w1;
arrowPos.y = top;
arrowPos.x = pointB.x - h2;
}
return arrowPos;
}