Untitled

 avatar
unknown
plain_text
2 years ago
2.5 kB
5
Indexable
public class ViewModel
{
    public bool IsRectangleTouchingOuterCircle(Rect rectangleBounds, double circularProgressBarRadius, Point circularProgressBarCenter)
    {
        Point rectangleTopLeft = new Point(rectangleBounds.Left, rectangleBounds.Top);
        Point rectangleTopRight = new Point(rectangleBounds.Right, rectangleBounds.Top);
        Point rectangleBottomLeft = new Point(rectangleBounds.Left, rectangleBounds.Bottom);
        Point rectangleBottomRight = new Point(rectangleBounds.Right, rectangleBounds.Bottom);

        double distanceToTopLeft = CalculateDistance(rectangleTopLeft, circularProgressBarCenter);
        double distanceToTopRight = CalculateDistance(rectangleTopRight, circularProgressBarCenter);
        double distanceToBottomLeft = CalculateDistance(rectangleBottomLeft, circularProgressBarCenter);
        double distanceToBottomRight = CalculateDistance(rectangleBottomRight, circularProgressBarCenter);

        double tolerance = 1.0; // Adjust this tolerance as needed

        return IsApproximatelyEqual(distanceToTopLeft, circularProgressBarRadius, tolerance) ||
               IsApproximatelyEqual(distanceToTopRight, circularProgressBarRadius, tolerance) ||
               IsApproximatelyEqual(distanceToBottomLeft, circularProgressBarRadius, tolerance) ||
               IsApproximatelyEqual(distanceToBottomRight, circularProgressBarRadius, tolerance);
    }

    private double CalculateDistance(Point point1, Point point2)
    {
        double dx = point1.X - point2.X;
        double dy = point1.Y - point2.Y;
        return Math.Sqrt(dx * dx + dy * dy);
    }

    private bool IsApproximatelyEqual(double value1, double value2, double tolerance)
    {
        return Math.Abs(value1 - value2) <= tolerance;
    }
}



// Example usage
ViewModel viewModel = new ViewModel();

Rect rectangleBounds = new Rect(rectangleLeft, rectangleTop, rectangleWidth, rectangleHeight); // Rectangle bounds
double currentCircularProgressBarRadius = ...; // Current radius of the circular progress bar
Point currentCircularProgressBarCenter = ...; // Current center point of the circular progress bar

bool isTouchingOuterCircle = viewModel.IsRectangleTouchingOuterCircle(rectangleBounds, currentCircularProgressBarRadius, currentCircularProgressBarCenter);

if (isTouchingOuterCircle)
{
    // Rectangle is touching the outer circle of the circular progress bar
}
else
{
    // Rectangle is not touching the outer circle of the circular progress bar
}
Editor is loading...