You are looking at historical revision 19026 of this page. It may differ significantly from its current revision.

Graphics Gems


A collection of selected algorithms from the Graphics Gems book series. So far the only one implemented is Bezier curve fitting (from the first book).


Shawn Rutledge


/man/4/Unit srfi-4


The code examples from the book are subject to the following EULA:

The Graphics Gems code is copyright-protected. In other words, you cannot claim the text of the code as your own and resell it. Using the code is permitted in any program, product, or library, non-commercial or commercial. Giving credit is not required, though is a nice gesture. The code comes as-is, and if there are any flaws or problems with any Gems code, nobody involved with Gems - authors, editors, publishers, or webmasters - are to be held responsible. Basically, don't be a jerk, and remember that anything free comes with no guarantee.

Currently the egg does not link with that code: it's possible, and it was implemented that way at first, but now the fit-bezier function has been translated to Scheme. Nevertheless, this egg is released under the BSD license since it's approximately the same.


As of version 1.0, fit-bezier is implemented and working.

Data types

In the Graphics Gems example code, a Point is a struct containing x and y as doubles; so a sequence of points would be an array of these structs. However it's possible to cast such an array as simply an array of doubles, and that form is more useful for sending output to graphics APIs such as OpenGL and Quartz. So for this egg a point sequence is an f64vector. Likewise a Bezier curve is represented as an f64vector in which the first 8 numbers are a complete curve segment, then the following curve segment is assumed to have its start point at the previous segment's end point, and therefore it is not repeated. So the first segment has 8 coordinates and the following ones have only 6.

Exported functions

Takes an f64vector of point coordinates and a tolerance; returns an f64vector with Bezier control points. It will create as many curve segments as necessary to fit the original polyline within the given tolerance.