Re: Representing Units of Measure
Posted: Sep 27, 2005 1:49 PM
Well it is done. The latest HeronScript now supports postfix type casts, and basic line drawing primitives.
> Partly conceded. There is an accumulated error, but it
> would likely be "hidden" in the sense that the widget's
> size would never disagree with itself.
You are right.
> And, since I was complaining about rounding errors on the
> order of 1/288 in. (from simple manufacturing margins of
> error/tolerances), it's pretty hard to defend my original
> post's elitism.
Nothing wrong with being elitist. I want to produce something of very high quality.
> This makes sense, although I understood the question to be
> about when different units were used in defining the size
> or placement of a widget.
What I failed to communicate is that I want to be able to write:
window_variable.move_to(25 percent, 25 percent)
window_variable.line_rel(12 pixels, 42 cm)
But to disallow:
12 pixels + 24 percent
My rationale, jumbled as it may be, is that 12 pixels + 42 cm is an expression with an indeterminate type. In order to allow the expression of a path with different types, I decided to create a polymorphic type "_unit" which accepts any one of the seven graphical unit types. This way only one definition of "line_to", "move_to", "line_rel", "move_rel" is needed.
The reason for this approach is that something like cm or percent is only meaningful when given a device context (like a screen or bitmap or printer). So only when you actually draw it, can you convert it to some kind of universal type. One of my requirements is that I want to be able to store paths as variables, independant of the context. This way when the context changes (for instance when the window is resized) I can simply go back and redraw the path.
In the HeronScript implementation every window has a "path" which represents a series of vector commands. What is cool about this approach, is that I can convert it to another format (XML, SVG, Bitmap, Metafile) very easily, or zoom in, or rotate or whatever, while still using the same core set of drawing operations.