The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.


I'm writing a simple CAD app (Cartesia) in VB/C# 2005 for my kids to fiddle with some geometry and math concepts.  I've had no problem drawing lines and textures, transformations and most other features but I'm completely stumped (well, almost) about how to select existing objects.

I've tried applying simple intersection techniques using the formula(s) for the shapes and it works to an extent but doesn't feel right.

Plenty of searches doesn't come up with much at all.

Any experts out there willing to throw a bone?  I'm even accepting wrong answers at this point.

Brad Siemens Send private email
Thursday, April 03, 2008
The CAD programs I'm familiar with usually use some combination of a radius around the endpoints (if any) of a shape, and a perpendicular distance to the outline.

So, if you've got a square, any click within a certain distance of any of the vertexes or the sides selects the square.

If multiple shapes are "hit", you pick the top-most. If the user clicks again in the same area, you select the next one down, and so on.

The radius of selection is usually configurable, and is usually different for endpoints and line segments.

Some examples for AutoCAD here:
Mark Bessey Send private email
Thursday, April 03, 2008
google "hit testing" if you haven't already.

Also, I don't know if it's still done this way these days, but CAD programs like AutoCAD used to keep a display list (separate from the actual drawing data) of vectors (straight lines) representing all of the drawing entities (so a circle in the drawing would be a bunch of vectors in the display list). Selection could then be done by intersecting the vectors in the display list with a box representing the cursor or selection recetangle.

You migh also consider a higher level graphics API like WPF.
Chris Altmann
Thursday, April 03, 2008

Turns out I'm an idiot!  Who knew?

I found an article as soon as I changed 'Hit Test' To 'Cad "Hit Testing"' Thank you!

Triangulating vectors from the definition points to the cursor appears to work well at first blush...  We'll see.

Thanks again!
Brad Siemens Send private email
Thursday, April 03, 2008
I have also seen it called picking.
Thursday, April 03, 2008
A crazy idea is to have a Width x Height array of all the pixels drawn ... with object references.. Isn't memory cheap?
Totally Agreeing
Friday, April 04, 2008
Check out Eric Sink's WPF series at and his sawdust project at - some pretty cool stuff!

Good luck!
Friday, April 04, 2008

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz