Home    Blog    Projects    About
« Bezzy DevBlog: The big idea behind fills Bezzy DevBlog: Best of the rest, Part 1 »

Bezzy DevBlog: Bounds on fills  (July 27th, 2008 at 4:33 pm)

In my last post, I said I’d talk about how I fixed a rather “fun glitch” which related to fill modes. Just to refresh your memory, it looked a little something like this:

If you read my last post you can probably figure out what’s going on here. The fill geometry I’m rendering is smaller than the path itself. Here’s a screenshot that makes this a bit more obvious:

This is possible because the programmer has the ability to scale the fill and position the fill origin wherever s/he would like. What I need to do is ensure that the entire path is always filled, regardless of the fill parameters. This means that the geometry needs to be big enough to go from the fill origin to every vertex that creates the path.

An obvious solution is to loop through each vertex (and control point for Bézier curves) finding the distance between the point and the fill origin. Keep track of the largest value and use that as the width of the fill. That works, but we can do a bit better.

Instead of doing a distance check with each vertex, why not do a distance check with each corner of the path? My optimized solution calculates the bounding box for each path on creation. When the path is rendered it simply checks the distance between the fill origin and each corner of the bounding box. The maximum distance becomes the size of the fill geometry. Simple optimization, but it takes us from O(n) efficiency to O(1).

Now that we know what the size of the geometry should be, what do we do with the extra space? I went with the easiest solution of just “clamping” the fill, which means it’ll use whatever colour is at the edge of the fill. In the future, I could make this a configurable setting, similar to OpenGL. This would make tiling possible by allowing the fills to repeat or mirror.

Posted in Bezzy.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Site and contents © Mobeen Fikree. Blog powered by Wordpress.