afielden@cbnewsb.cb.att.com (andrew.j.fielden) (03/28/91)
I'm writing an xview program that uses Xlib graphics primitives. I have found
a problem when trying to use Regions. What I am trying to do is detect whether
one region is contained within another region. I wrote a small program to
illustrate the problem.
I create a region with co-ordinates (5,5),(80,5),(80,80),(5,80) - call this
region b.
Now I try to determine if the following regions are contained within the above
region :-
region a = (10,20),(30,20),(70,70),(50,70)
region A = (10,20),(30,20),(70,50),(50,50)
So what I do is calculate the intersection of the regions
(region [aA] and region b)
If region a is contained in region b, then this intersected region should be
exactly equal to region a.
Problem is, this method works for region 'a', but does not work for region 'A' !
I am a newcomer to X-Windows, so maybe I am overlooking something, but I would
appreciate any help anyone could offer.
Thanks in advance
Andrew.
============================== CUT =======================================
#include "/usr/openwin/include/X11/Intrinsic.h"
#include "/usr/openwin/include/X11/Xutil.h"
main()
{
XPoint pt_a[4], pt_b[4];
Region region_a, region_b, region_c;
/* (doesn't work) */
pt_a[0].x = 10; pt_a[0].y = 20;
pt_a[1].x = 30; pt_a[1].y = 20;
pt_a[2].x = 70; pt_a[2].y = 70;
pt_a[3].x = 50; pt_a[3].y = 70;
/* (works) */
/*
pt_a[0].x = 10; pt_a[0].y = 20;
pt_a[1].x = 30; pt_a[1].y = 20;
pt_a[2].x = 70; pt_a[2].y = 50;
pt_a[3].x = 50; pt_a[3].y = 50;
*/
pt_b[0].x = 5; pt_b[0].y = 5;
pt_b[1].x = 80; pt_b[1].y = 5;
pt_b[2].x = 80; pt_b[2].y = 80;
pt_b[3].x = 5; pt_b[3].y = 80;
region_a = XPolygonRegion(pt_a, 4, EvenOddRule);
region_b = XPolygonRegion(pt_b, 4, EvenOddRule);
region_c = XCreateRegion();
XIntersectRegion(region_b, region_a, region_c);
if (XEqualRegion(region_a, region_c))
printf("region a is in region b\n");
else
printf("region a is NOT in region b\n");
}
--
Andrew Fielden. AT&T Network Systems UK.
afielden@hvmpa.att.com