The Essentials of CAGD

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.
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...