user3885473
user3885473

Reputation: 11

Android Java: Region Subtraction

Is it possible to subtract one Region object and subtract it from another?

E.g. I have a two Regions, region1 (green) and region2 (red):

Image

How would I create a region3 that is only the part of region1 that is not also part of region2 (only green and NOT red)?

Upvotes: 1

Views: 116

Answers (1)

TWiStErRob
TWiStErRob

Reputation: 46490

    Region r1;
    Region r2;
    Region r3 = new Region(r1); // make a copy to not change r1
    r3.op(r2, Op.DIFFERENCE); // r3 = r1-r2

If you're not bothered about changing r1, obviously you can skip the copy.

Upvotes: 2

Related Questions