The Essentials of CAGD

Chapter 14: Hunting Geometry Bugs

When you code up any of the concepts in this book, chances are that your program doesn't work right away for example, we produced Figure 14.1 in an early attempt for one of the figures in the book. Here are some hints on how to fix some common errors.


Figure 14.1: A bug in a program.

Equality check: A typical error that inexperienced programmers will almost invariably produce will look like this:

if (x == y) return;

What is bad about this? We assume that x and y are reals, i.e., represented as float or double. Inside a larger program, they will both be the result of some computation. Then one can almost guarantee that they will never be equal! Keep in mind that in order for two reals to be equal, all digits must be equal. But computation produces roundoff, and so it is more than likely that the last digits will differ.

The safest way out of this problem is to employ a tolerance tol. Then the above would look like this:

if (fabs(x - y) < tol) return;

The value of tol depends on the application at hand and may critically influence your computations. Without any knowledge about an application, tol=1. OE-6 should work.

In the same way, it is also not safe to check for numbers being positive or negative: if ( x < 0) should be replaced by if x < ?tol.

Test case size: More...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Bug Tracking Software
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.