// ---------------------------------------------------------------------- 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); }
// ---------------------------------------------------------------------- // 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))); }
// ---------------------------------------------------------------------- public bool IsPortOnRectEdge(Rect r, iCS_EdgeEnum edge) { return(IsPositionOnRectEdge(GlobalPosition, r, edge)); }
// ---------------------------------------------------------------------- public bool IsPortOnNodeEdge(iCS_EditorObject node, iCS_EdgeEnum edge) { return(IsPortOnRectEdge(node.GlobalRect, edge)); }
// ---------------------------------------------------------------------- // Updates the port edge information from the port type. public void UpdatePortEdge(Vector2 localPosition) { Edge = GetClosestEdge(localPosition); }
// ---------------------------------------------------------------------- // 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)); }