🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Ted Cohn Sun, 07 Apr 1985 22:52
Calculating Region Areas
#958
Author: Ted Cohn
Date: Sun, 07 Apr 1985 22:52
44 lines
2429 bytes
A simple process-by-illimination technique can be used to find the area of a
given region (i.e., the number of pixels the region contains).  I remember
someone posting their interpretation of the region structure a few months ago,
but I lost it.  Since I don't know the internal structure of a region, the
QuickDraw routine PTINRGN can be use repeatedly.  Of course, we do know that:

TYPE Region = RECORD
		rgnSize:  INTEGER;
		rgnBBox:  Rect;
		{Optional region definition data}
	      END;

The region is, at most, as big as the enclosing rectangle, rgnBBox.  Therefore,
the area must be the sum of those pixels that fall within the region where
PtInRgn(point,region) is true.  Or, conversely, the area is also equal to the
differnce of the area of rgnBBox and the sum of pixels not in the region where
PtInRgn(point,region) is false.  A simple Pascal function is as follows: 

Function AreaRgn(theRgn: RgnHandle): LongInt;
var h, v, x1, x2, y1, y2: INTEGER;
    thePoint: point;
begin
    x1:=theRgn.rgnBBox.left;
    x2:=theRgn.rgnBBox.right;
    y1:=theRgn.rgnBBox.top;
    y2:=theRgn.rgnBBox.bottom;
    AreaRgn:=(x2-x1)*(y2-y1);		{Find maximum area}
    if theRgn.rgnSize > 10 then		{If more to region, iterate}
	for h:=x1 to x2-1 do		{One less than x2 so not to overcount}
	    for v:=y1 to y2-1 do	{One less than y2 so not to overcount}
	    begin
		SetPt(thePoint, h, v);	{A Pascal frustration}
		if not PtInRgn(thePoint,theRgn) then AreaRgn:=AreaRgn-1;
	    end;
end;

If anyone finds a slicker way of finding region areas, I would love to hear
about it!  Perhaps knowing the internal structure (already decyphered?) might
lend a hand.  Of course, what applications might this function have?
Finding approximate areas of regions on maps in MacPaint maybe?  Who knows.

- Ted Cohn
cohn@ucbvax.BERKELEY.ARPA
"I'd rather be driving a Macintosh"
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads