Razor Storm
Razor Storm

Reputation: 12326

How to get the inscribed rectangle in a canvas clip

In android canvas, I've defined a clipping area with many shapes (a rectangle and 2 circles). I want to get the inscribed rectangle defined by the clipping area.

Canvas has a method called getClipBounds() which gives me the circumscribed rectangle, how do I get the inscribed rectangle instead?

enter image description here

Edit: Here's some info on how the original shape is made:

  1. First add a clip for the big circle with Region.Op.INTERSECT
  2. Then add a clip for a vertical rectangle with Region.Op.INTERSECT
  3. Then add a clip for a smaller circle with Region.Op.DIFFERENCE

Upvotes: 4

Views: 502

Answers (1)

GraphicsMuncher
GraphicsMuncher

Reputation: 4641

This can be determined mathematically if you know the radius & center of both circles.

Find two the intersection points of circles with the getClipBounds() rectangle. -The the second highest intersection point between the red circle and the getClipBounds() rectangle holds the upper y coordinate of the rectangle. -The high intersection point between the white circle and the getClipBounds() rectangle holds the lower y coordinate of the rectangle. -The x bounds are already given by the getClipBounds() rectangle.

You can construct your three shapes from there.

Upvotes: 1

Related Questions