コード例 #1
0
        // ----------------------------------------------------------------------
        public static bool IsPositionOnRectEdge(Vector2 pos, Rect r, iCS_EdgeEnum edge)
        {
            float maxDistance = iCS_EditorConfig.PortDiameter;
            float distance    = 2f * maxDistance;
            float leftX       = r.xMin;
            float rightX      = r.xMax;
            float topY        = r.yMin;
            float bottomY     = r.yMax;

            switch (edge)
            {
            case iCS_EdgeEnum.Top:
                distance = Math3D.DistanceFromHorizontalLineSegment(pos, leftX, rightX, topY);
                break;

            case iCS_EdgeEnum.Bottom:
                distance = Math3D.DistanceFromHorizontalLineSegment(pos, leftX, rightX, bottomY);
                break;

            case iCS_EdgeEnum.Left:
                distance = Math3D.DistanceFromVerticalLineSegment(pos, topY, bottomY, leftX);
                break;

            case iCS_EdgeEnum.Right:
                distance = Math3D.DistanceFromVerticalLineSegment(pos, topY, bottomY, rightX);
                break;
            }
            return(distance <= maxDistance);
        }
コード例 #2
0
        // ----------------------------------------------------------------------
        // Returns true if the distance to parent is less then twice the port size.
        public bool IsNearParentEdge(iCS_EditorObject port, iCS_EdgeEnum edge = iCS_EdgeEnum.None)
        {
            var parent = port.ParentNode;
            var pos    = port.GlobalPosition;

            return(parent.IsPositionOnEdge(pos, (edge != iCS_EdgeEnum.None ? edge : port.Edge)));
        }
コード例 #3
0
 // ----------------------------------------------------------------------
 public bool IsPortOnRectEdge(Rect r, iCS_EdgeEnum edge)
 {
     return(IsPositionOnRectEdge(GlobalPosition, r, edge));
 }
コード例 #4
0
 // ----------------------------------------------------------------------
 public bool IsPortOnNodeEdge(iCS_EditorObject node, iCS_EdgeEnum edge)
 {
     return(IsPortOnRectEdge(node.GlobalRect, edge));
 }
コード例 #5
0
 // ----------------------------------------------------------------------
 // Updates the port edge information from the port type.
 public void UpdatePortEdge(Vector2 localPosition)
 {
     Edge = GetClosestEdge(localPosition);
 }
コード例 #6
0
 // ----------------------------------------------------------------------
 // Return true if the position is on the edge of the node.
 public bool IsPositionOnEdge(Vector2 position, iCS_EdgeEnum edge)
 {
     return(IsPositionOnRectEdge(position, GlobalRect, edge));
 }