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

Friday, March 16, 2007

The Random Walk

Like a photon in the Sun, sometimes my programming follows a random path toward completion. My work becomes parenthetical, where I start one thing, which leads to a change to something else, which then leads to some inspiration to fix it for the better, which reminds me of something I always wanted to do, which in turn leads me further away from the task I began, and so on. My great fear is that I'll get caught up so far away from where I started that I won't be able to find my way back, or even if I do, I'll have lost the inspiration that was driving the original project. Yet somehow I always find my way back and I always rediscover the inspiration, although is some cases it was years later! But most importantly, I have learned to trust these detours, because I have never followed one that I would later regret; in every instance they have made SkyTools better.

Recently I started on the last major piece of SkyTools 3 that had yet to be written. It's what I call a Context Viewer. This is a chart window that is attached to the Interactive Atlas, as a sort of pop up. This window will display an eyepiece view for the selected telescope and eyepiece combination. An indicator appears on the Atlas that you can drag around to position the eyepiece view. It will also support cameras. Building this window might seem like a big project, but in fact I can borrow code from elsewhere (primarily the new Thumbnail viewer--but I'll save that one for another time). It's really just a matter of copying and pasting code and then making some modifications, something I find simple, yet tedious.

One morning I got to work and simply couldn't bring myself to continue on it. This happens from time to time, and I know I'll spend the rest of the day staring out the Window or posting to Usenet if I don't give in and find something more appealing to do.

I'd been copying a code snippet from the Chart Controls dialog when I had one of those crazy ideas. Could we just get rid of that dialog entirely? I had a look: sure enough, the only controls that were not already on the charts were the coordinate system and map projection used by the Interactive Atlas. I realized they could be moved to the tool bar. The scenario selection is also stored there, and I briefly considered removing it, but decided to move it to the tool bar as well.

Moving these little-used controls to the tool bar was one of those small changes that was at the same time rather dramatic, and I was pleased by the result. Now more prominent, I think they will get much more use. It seemed like this would also be a good opportunity to add the galactic coordinate system as planned. Of course, once I had the selection labeled "Galactic Coordinates" in the Combo Box, I needed to actually add this coordinate transform to the mapping code! While doing that I realized that I should also have galactic coordinates as a grid selection. While adding them to the grid I remembered a question someone asked on a forum about software that could display what was below the horizon. I had the sudden realization that I should split the horizon coordinate mode into two modes; one that displays simple horizon coordinates (and extends below the horizon) and one that simulates the sky with extinction, refraction, etc. So I did that. But I also needed to make changes in the horizon line... and of course I promised to add a meridian and ecliptic, and I should probably plot more "cardinal points" such as the Galactic Poles and Galactic center.

Somewhere in there I discovered that in the simulation horizon mode my new shaded sky no longer matched up with the horizon as drawn. So off I went to my new sky shading module. It took a full day to straighten that out!

And what was I supposed to be working on again?

Next time: how all this led to a breakthrough in object trail labels!