Seva Alekseyev
Seva Alekseyev

Reputation: 61341

Canvas clipping rect - right/bottom edge inclusive?

on Android, there's a Canvas class that represents a drawing surface. It has a clipping rect. Question - are the rect's right and bottom borders inclusive or exclusive? In other words - if the rect is (0, 0)-(10, 10), will the Canvas allow drawing in pixels at coordinates 10?

Upvotes: 5

Views: 1684

Answers (1)

Michael Scheper
Michael Scheper

Reputation: 7038

According to another StackOverflow question, right and bottom are exclusive, but top and left are inclusive.
As I say in my answer there (which I suppose is really a comment), this is consistent with other Java API, and has other benefits.

So, no, you won't be able to draw at ordinate 10. But it does mean that your Rect is a 10×10 pixel square.

Also, calculations are simpler, like:

int width = rect.right - rect.left;
int height = rect.bottom - rect.top;

Just for example, I know we have .getWidth() and .getHeight() methods.

Upvotes: 4

Related Questions