DiagramEdge.UpdateAnchor C# (CSharp) Method

UpdateAnchor() public method

public UpdateAnchor ( DiagramContext, context ) : void
context DiagramContext,
return void
    public void UpdateAnchor(DiagramContext context)
    {
        //
        Rect sourceRect = sourceAnchor.GetNode (context).rect;
        Rect targetRect = targetAnchor.GetNode (context).rect;

        Vector2 pointA = new Vector2 (sourceRect.x + sourceRect.width / 2, sourceRect.y + sourceRect.height / 2);
        Vector2 pointB = new Vector2 (targetRect.x + targetRect.width / 2, targetRect.y + targetRect.height / 2);

        bool source = false;
        bool target = false;
        if (sourceAnchor.relative) {
            //
        } else {
            if (sourceAnchor.relativePosition == EdgeAnchorHandle.CENTER) {
                sourceAnchor.position = GetAnchorPos (pointB, sourceRect, pointA);
            } else {
                //if (!((sourceAnchor.relativePosition.x == 1.0f || sourceAnchor.relativePosition.x == 0.0f) && (sourceAnchor.relativePosition.y == 1.0f || sourceAnchor.relativePosition.y == 0.0f))) {
                    source = true;
                //} else {
                //	float tempX = sourceRect.x + sourceRect.width * sourceAnchor.relativePosition.x;
                //	float tempY = sourceRect.y + sourceRect.height * sourceAnchor.relativePosition.y;
                //	sourceAnchor.position.x = tempX;
                //	sourceAnchor.position.y = tempY;
                //}
            }
        }

        if (targetAnchor.relative) {
            //
        } else {
            if (targetAnchor.relativePosition == EdgeAnchorHandle.CENTER) {
                targetAnchor.position = GetAnchorPos (pointA, targetRect, pointB);
            } else {
                //if (!((targetAnchor.relativePosition.x == 1.0f || targetAnchor.relativePosition.x == 0.0f) && (targetAnchor.relativePosition.y == 1.0f || targetAnchor.relativePosition.y == 0.0f))) {
                    target = true;
                //} else {
                //	targetAnchor.position.x = targetRect.x + targetRect.width * targetAnchor.relativePosition.x;
                //	targetAnchor.position.y = targetRect.y + targetRect.height * targetAnchor.relativePosition.y;
                //}
            }
        }

        Log(" source anchor = " + sourceAnchor.relativePosition);
        Log(" target anchor = " + targetAnchor.relativePosition);
        if (source || target) {
            if (source && target) {
                pointA = new Vector2 (sourceRect.x + sourceRect.width * sourceAnchor.relativePosition.x, sourceRect.y + sourceRect.height * sourceAnchor.relativePosition.y);
                pointB = new Vector2 (targetRect.x + targetRect.width * targetAnchor.relativePosition.x, targetRect.y + targetRect.height * targetAnchor.relativePosition.y);
            } else if (source && !target) {
                pointA = new Vector2 (sourceRect.x + sourceRect.width * sourceAnchor.relativePosition.x, sourceRect.y + sourceRect.height * sourceAnchor.relativePosition.y);
            } else if (!source && target) {
                pointB = new Vector2 (targetRect.x + targetRect.width * targetAnchor.relativePosition.x, targetRect.y + targetRect.height * targetAnchor.relativePosition.y);
            }
            if (source && target) {
                sourceAnchor.position = GetAnchorPos (pointB, sourceRect, pointA);
                targetAnchor.position = GetAnchorPos (pointA, targetRect, pointB);
            } else if (source && !target) {
                Log(" source ");
                sourceAnchor.position = GetAnchorPos (pointB, sourceRect, pointA);
            } else if (!source && target) {
                Log(" target ");
                targetAnchor.position = GetAnchorPos (pointA, targetRect, pointB);
            }
        }
        if(!sourceRect.Contains(pointA)){
            LogError(" source Error pointA ! ");
        }
        if(!sourceRect.Contains(sourceAnchor.position)){
            LogError(" source Error ! ");
        }
        if(!targetRect.Contains(targetAnchor.position)){
            LogError(" target Error ! ");
        }

        Log(" source anchor = " + sourceAnchor.position + "  sourceRect = "  + sourceRect);
        Log("  pointA = " + pointA + " " + sourceRect.Contains(pointA));
        Log(" target anchor = " + targetAnchor.position + "  targetRect = "  + targetRect);
        Log("  pointB = " + pointB + " " + targetRect.Contains(pointB));
    }