Tuesday, March 20, 2007

A Trail of Two Labels

I took some time off over the weekend for a family hike on one of the new trails opened up by New Mexico Rails to trails. It was relaxing.

So I have a confession to make: I've never been happy with the coordinate grid labels. I've recently been working on improving the grid lines and adding new meridian and ecliptic lines. And right there, just below where I was working, loomed that pesky grid label code. I couldn't help myself, I just had to see if I could finally make it better.

Digging in this code brought back memories. I know I made numerous improvements for SkyTools 2, but what came flooding back was when I originally wrote it. I clearly recall a long walk with my wife, a friend, and her dogs. It was a pleasant late-spring afternoon at San Diego's Lake Murray, not far from where SkyTools was born. While my wife and friend talked I spent the whole time trying to wrap my head around how I wanted to tackle coordinate grids and their labels. As the Sun set and the sky darkened, Comet Hale-Bopp was visible in the clear western sky.

As much as that is a pleasant memory, I hate this code! It does not draw labels that look as nice as I want. I considered for a bit, trying to figure out how to make it better. I wasn't sure what to do, but one thing seemed clear: rotating the labels in concert with the grid would be a big step in the right direction.

Labels rotated to arbitrary angles... Ever notice SkyTools doesn't do that? There are a couple of reasons, but primarily this is due to the use of my "smart label" module, which keeps labels from overwriting each other. This module is built on the idea that the labels are defined by simple rectangles aligned with the screen. But I'd had enough of that. I didn't know how, but I figured there had to be a way to add rotated rectangles to the smart label code. So I created a new kind of label that could be rotated to any angle and simply had faith that this smart label problem could be solved.

Still stuck on how I wanted to do the grid labels, I turned to the other
labels that cried out for arbitrary rotation: the object trails. Before you know it I had nice little trail labels, all lined up. Well, actually, they didn't line up that well. There was some variation in the angle for each label, which made them look rather messy. I tried a couple of things, and then I realized that I should simply force all the labels to have the same angle until they rotated more than, say, 10% from each other. And there you had it: nice neat labels all lined up!

But what about making them "smart" so they won't overlap? It
took me the better part of a day, and I had to try three different approaches, but I finally came up with a hack (umm... I mean clever algorithm) that made it work. Whew!

This all may sound trivial, but it is the little things that in the end make all the difference. Oh, and the grid labels came out nice too. Rotating the label to match the grid makes it much more clear which label goes where. That and a little TLC has them looking much better!

I'm off to the stellar database again for another go-round. I need to finish up the updating of the cross reference databases. And it turns out there are stars showing up in Scutum that aren't really there...

No comments: