Nov 97 - Tips

Volume Number: 13 (1997)
Issue Number: 11
Column Tag: Tips & Tidbits

by Steve Sisak

Here is an easy technique for determining if a point lies within a given graphic object of arbitrary complexity: simply draw the object into an offscreen bitmap, then check if the desired pixel has been changed. In more detail, the steps are:

• Create an offscreen black-and-white bitmap, one pixel high by 16 pixels wide (actually it only needs to be one pixel wide, but QuickDraw insists that you allocate an even number of bytes).
• Erase this bitmap to white.
• Draw the shape into the bitmap in solid black.
• Test the desired pixel to see if it has been set to black.

Here is some actual code that shows you how to hit test a polygon in this way. First, an auxiliary routine to aid the setup of an offscreen black-and-white GrafPort (since GWorlds are overkill for this purpose):

```PROCEDURE SetBitsTo
(
VAR TheBits : BitMap
);
(* sets the portBits of the current grafPort, also
changing the portRect, clipRgn, visRgn to match
the bounds of the bitmap. *)

VAR
CurPort : GrafPtr;

BEGIN
SetPortBits(TheBits);
MovePortTo(0, 0);
SetOrigin(TheBits.bounds.left, TheBits.bounds.top);
PortSize
(
TheBits.bounds.right - TheBits.bounds.left,
TheBits.bounds.bottom - TheBits.bounds.top
);
GetPort(CurPort);
ClipRect(CurPort^.portRect);
CopyRgn(CurPort^.clipRgn, CurPort^.visRgn)
END SetBitsTo;

Then, the actual routine that hit tests a point against a polygon:

PROCEDURE PtInPoly
(
pt : Point;
poly : PolyHandle
) : BOOLEAN;
(* is the specified point within the given polygon. *)

VAR
PreviousPort : GrafPtr;
TempPort : GrafPort;
TempBits : BitMap;
TempBitsWord : ShortCard; (* a 1-by-16 offscreen bitmap *)

BEGIN
GetPort(PreviousPort);
TempBits.bounds.top := pt.v;
TempBits.bounds.bottom := pt.v + 1;
TempBits.bounds.left := pt.h - 15;
(* so desired pixel is in bit 0 *)
TempBits.bounds.right := pt.h + 1;
TempBits.rowBytes := 2;
TempBitsWord := 0; (* set all pixels to white *)
SetBitsTo(TempBits);
PaintPoly(poly); (* draw polygon in black *)
SetPort(PreviousPort);
RETURN
ODD(TempBitsWord)
END PtInPoly;```

It shouldn't be hard to see how to adapt the basic idea to other sorts of graphic objects, or even to other graphics architectures besides QuickDraw.

Lawrence D'Oliveiro
ldo@geek-central.gen.nz

Community Search:
MacTech Search:

Software Updates via MacUpdate

iFinance 4.3.7 - Comprehensively manage...
iFinance allows you to keep track of your income and spending -- from your lunchbreak coffee to your new car -- in the most convenient and fastest way. Clearly arranged transaction lists of all your... Read more
Microsoft Office 2016 16.9 - Popular pro...
Microsoft Office 2016 - Unmistakably Office, designed for Mac. The new versions of Word, Excel, PowerPoint, Outlook and OneNote provide the best of both worlds for Mac users - the familiar Office... Read more
Pinegrow 4.2 - Mockup and design webpage...
Pinegrow (was Pinegrow Web Designer) is desktop app that lets you mockup and design webpages faster with multi-page editing, CSS and LESS styling, and smart components for Bootstrap, Foundation,... Read more
Little Snitch 4.0.5 - Alerts you about o...
Little Snitch gives you control over your private outgoing data. Track background activity As soon as your computer connects to the Internet, applications often have permission to send any... Read more
Microsoft OneNote 16.9 - Free digital no...
OneNote is your very own digital notebook. With OneNote, you can capture that flash of genius, that moment of inspiration, or that list of errands that's too important to forget. Whether you're at... Read more
1Password is a password manager that uniquely brings you both security and convenience. It is the only program that provides anti-phishing protection and goes beyond password management by adding Web... Read more
File Juicer 4.66 - \$18.00
File Juicer is a drag-and-drop can opener and data archaeologist. Its specialty is to find and extract images, video, audio, or text from files which are hard to open in other ways. In computer... Read more
DEVONthink Pro 2.9.17 - Knowledge base,...
Save 10% with our exclusive coupon code: MACUPDATE10 DEVONthink Pro is your essential assistant for today's world, where almost everything is digital. From shopping receipts to important research... Read more
GraphicConverter 10.5.4 - \$39.95
GraphicConverter is an all-purpose image-editing program that can import 200 different graphic-based formats, edit the image, and export it to any of 80 available file formats. The high-end editing... Read more
SoftRAID 5.6.4 - High-quality RAID manag...
SoftRAID allows you to create and manage disk arrays to increase performance and reliability. SoftRAID allows the user to create and manage RAID 4 and 5 volumes, RAID 1+0, and RAID 1 (Mirror) and... Read more

Latest Forum Discussions

The 7 best games that came out for iPhon...
Well, it's that time of the week. You know what I mean. You know exactly what I mean. It's the time of the week when we take a look at the best games that have landed on the App Store over the past seven days. And there are some real doozies here... | Read more »
Popular MMO Strategy game Lords Mobile i...
Delve into the crowded halls of the Play Store and you’ll find mobile fantasy strategy MMOs-a-plenty. One that’s kicking off the new year in style however is IGG’s Lords Mobile, which has beaten out the fierce competition to receive Google Play’s... | Read more »
Blocky Racing is a funky and fresh new k...
Blocky Racing has zoomed onto the App Store and Google Play this week, bringing with it plenty of classic kart racing shenanigans that will take you straight back to your childhood. If you’ve found yourself hooked on games like Mario Kart or Crash... | Read more »
Cytus II (Games)
Cytus II 1.0.1 Device: iOS Universal Category: Games Price: \$1.99, Version: 1.0.1 (iTunes) Description: "Cytus II" is a music rhythm game created by Rayark Games. It's our fourth rhythm game title, following the footsteps of three... | Read more »
JYDGE (Games)
JYDGE 1.0.0 Device: iOS Universal Category: Games Price: \$4.99, Version: 1.0.0 (iTunes) Description: Build your JYDGE. Enter Edenbyrg. Get out alive. JYDGE is a lawful but awful roguehate top-down shooter where you get to build your... | Read more »
Tako Bubble guide - Tips and Tricks to S...
Tako Bubble is a pretty simple and fun puzzler, but the game can get downright devious with its puzzle design. If you insist on not paying for the game and want to manage your lives appropriately, check out these tips so you can avoid getting... | Read more »
Everything about Hero Academy 2 - The co...
It's fair to say we've spent a good deal of time on Hero Academy 2. So much so, that we think we're probably in a really good place to give you some advice about how to get the most out of the game. And in this guide, that's exactly what you're... | Read more »
Everything about Hero Academy 2: Part 3...
In the third part of our Hero Academy 2 guide we're going to take a look at the different modes you can play in the game. We'll explain what you need to do in each of them, and tell you why it's important that you do. [Read more] | Read more »
Everything about Hero Academy 2: Part 2...
In this second part of our guide to Hero Academy 2, we're going to have a look at the different card types that you're going to be using in the game. We'll split them up into different sections too, to make sure you're getting the most information... | Read more »
Everything about Hero Academy 2: Part 1...
So you've started playing Hero Academy 2, and you're feeling a little bit lost. Don't worry, we've got your back. So we've come up with a series of guides that are going to help you get to grips with everything that's going on in the game. [Read... | Read more »

Price Scanner via MacPrices.net

How to find the lowest prices on 2017 Apple M...
Apple has Certified Refurbished 13″ and 15″ 2017 MacBook Pros available for \$200 to \$420 off the cost of new models. Apple’s refurbished prices are the lowest available for each model from any... Read more
The lowest prices anywhere on Apple 12″ MacBo...
Apple has Certified Refurbished 2017 12″ Retina MacBooks available for \$200-\$240 off the cost of new models. Apple will include a standard one-year warranty with each MacBook, and shipping is free.... Read more
Apple now offering a full line of Certified R...
Apple is now offering Certified Refurbished 2017 10″ and 12″ iPad Pros for \$100-\$190 off MSRP, depending on the model. An Apple one-year warranty is included with each model, and shipping is free: –... Read more
27″ iMacs on sale for \$100-\$130 off MSRP, pay...
B&H Photo has 27″ iMacs on sale for \$100-\$130 off MSRP. Shipping is free, and B&H charges sales tax for NY & NJ residents only: – 27″ 3.8GHz iMac (MNED2LL/A): \$2199 \$100 off MSRP – 27″ 3.... Read more
2.8GHz Mac mini on sale for \$899, \$100 off MS...
B&H Photo has the 2.8GHz Mac mini (model number MGEQ2LL/A) on sale for \$899 including free shipping plus NY & NJ sales tax only. Their price is \$100 off MSRP. Read more
Apple offers Certified Refurbished iPad minis...
Apple has Certified Refurbished 128GB iPad minis available today for \$339 including free shipping. Apple’s standard one-year warranty is included. Their price is \$60 off MSRP. Read more
Amazon offers 13″ 256GB MacBook Air for \$1049...
Amazon has the 13″ 1.8GHz/256B #Apple #MacBook Air on sale today for \$150 off MSRP including free shipping: – 13″ 1.8GHz/256GB MacBook Air (MQD42LL/A): \$1049.99, \$150 off MSRP Read more
9.7-inch 2017 WiFi iPads on sale starting at...
B&H Photo has 9.7″ 2017 WiFi #Apple #iPads on sale for \$30 off MSRP for a limited time. Shipping is free, and pay sales tax in NY & NJ only: – 32GB iPad WiFi: \$299, \$30 off – 128GB iPad WiFi... Read more
Wednesday deal: 13″ MacBook Pros for \$100-\$15...
B&H Photo has 13″ #Apple #MacBook Pros on sale for up to \$100-\$150 off MSRP. Shipping is free, and B&H charges sales tax for NY & NJ residents only: – 13-inch 2.3GHz/128GB Space Gray... Read more
Apple now offering Certified Refurbished 2017...
Apple has Certified Refurbished 9.7″ WiFi iPads available for \$50-\$80 off the cost of new models. An Apple one-year warranty is included with each iPad, and shipping is free: – 9″ 32GB WiFi iPad: \$... Read more

Jobs Board

*Apple* Store Leader - Retail District Manag...
Job Description: Job Summary As more and more people discover Apple , they visit our retail stores seeking ways to incorporate our products into their lives. It's Read more
Sr. Experience Designer, Today at *Apple* -...
# Sr. Experience Designer, Today at Apple Job Number: 56495251 Santa Clara Valley, California, United States Posted: 18-Jan-2018 Weekly Hours: 40.00 **Job Summary** Read more
Security Applications Engineer, *Apple* Ret...
# Security Applications Engineer, Apple Retail Job Number: 113237456 Santa Clara Valley, California, United States Posted: 17-Jan-2018 Weekly Hours: 40.00 **Job Read more
*Apple* Solutions Consultant - Apple (United...
# Apple Solutions Consultant Job Number: 113384559 Brandon, Florida, United States Posted: 10-Jan-2018 Weekly Hours: 40.00 **Job Summary** Are you passionate about Read more
Art Director, *Apple* Music + Beats1 Market...
# Art Director, Apple Music + Beats1 Marketing Design Job Number: 113258081 Santa Clara Valley, California, United States Posted: 05-Jan-2018 Weekly Hours: 40.00 Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.