ControlCorner CornerOfRect(CGRect rect, CGPoint point) { var closestDistance = nfloat.MaxValue; var closestCorner = ControlCorner.None; Tuple <ControlCorner, CGPoint> [] corners = { Tuple(ControlCorner.TopLeft, rect.CornerTopLeft()), Tuple(ControlCorner.TopRight, rect.CornerTopRight()), Tuple(ControlCorner.BottomLeft, rect.CornerBottomLeft()), Tuple(ControlCorner.BottomRight, rect.CornerBottomRight()) }; // corner, cornerPoint foreach (var tpl in corners) { var corner = tpl.Item1; var cornerPoint = tpl.Item2; var dX = point.X - cornerPoint.X; var dY = point.Y - cornerPoint.Y; var distance = NMath.Sqrt((dX * dX) + (dY * dY)); if (distance < closestDistance) { closestDistance = distance; closestCorner = corner; } } if (closestDistance > regionOfInterestCornerTouchThreshold) { closestCorner = ControlCorner.None; } return(closestCorner); }
ControlCorner CornerOfRect (CGRect rect, CGPoint point) { var closestDistance = nfloat.MaxValue; var closestCorner = ControlCorner.None; Tuple<ControlCorner, CGPoint> [] corners = { Tuple (ControlCorner.TopLeft, rect.CornerTopLeft()), Tuple (ControlCorner.TopRight, rect.CornerTopRight ()), Tuple (ControlCorner.BottomLeft, rect.CornerBottomLeft ()), Tuple (ControlCorner.BottomRight, rect.CornerBottomRight()) }; // corner, cornerPoint foreach (var tpl in corners) { var corner = tpl.Item1; var cornerPoint = tpl.Item2; var dX = point.X - cornerPoint.X; var dY = point.Y - cornerPoint.Y; var distance = NMath.Sqrt ((dX * dX) + (dY * dY)); if (distance < closestDistance) { closestDistance = distance; closestCorner = corner; } } if (closestDistance > regionOfInterestCornerTouchThreshold) closestCorner = ControlCorner.None; return closestCorner; }