Angle Literals Too...

2 views
Skip to first unread message

Stephen Chin

unread,
Jan 1, 2011, 4:53:19 PM1/1/11
to visag...@googlegroups.com
I finished off the implementation of Angle literals, which was partially
done in the previous check-in.

Here is the changelist in case you are interested in reviewing the
changes (although remember most of the work was done in the previous
check-in):
http://code.google.com/p/visage/source/detail?r=0164367eb49f5f2c1efcfd85a2728a25b2ae705e

And here is a little bit about Angle literals:
Angle instances can be specified as degrees, radians, or turns. For
precise calculations, they are stored in the given unit type as a double
value.

Angles can be easily created using angle literals; for example, a 90
degree Angle instance can be defined in several ways:
Angle a = 90deg;
Angle a = .25turn;
Angle a = Angle.valueOf(Math.PI / 2, AngleUnit.RADIAN);</pre></code>

Angle instances are immutable, and are therefore replaced rather than
modified. To create a new Angle instance, either use a time literal, or
use the Angle.valueOf(value, unit) factory method.

Angles support operator overloading of all the usual suspects (+, -, *,
/, etc.) They also have a custom formatter to let you specify precision.

Happy New Year!

Cheers,
--
--Steve
blog: http://steveonjava.com/

Josh Marinacci

unread,
Jan 3, 2011, 7:46:25 PM1/3/11
to visag...@googlegroups.com
This is awesome stuff. How much is implemented in the parser and how much is a Java api? I may have to steal this for Leonardo, since it needs unit and angle support soon.

- Josh

Blasting forth in three part harmony!

Stephen Chin

unread,
Jan 6, 2011, 1:02:33 AM1/6/11
to visag...@googlegroups.com
The enum classes (LengthUnit, AngleUnit) are straight Java Enums and
ripe for the taking. The literal classes (Color, Length, and Angle) are
all implemented as Visage classes. Doing a straight conversion to Java
would not be hard at all, and would save you the trouble of doing a
clean room implementation of the color algorithms and length conversions
from scratch (which is what I had to do).

I also kept the license as New BSD to promote code sharing, so you are
free to take those classes and reuse/convert them for Leonardo. In fact
I encourage you to do so, because that makes the job of wrapping
Leonardo with Visage that much easier! :)

What you are a not getting is the literal syntax support. You would
need to use the Java constructors to create objects instead. For example:
Color.rgb(16, 16, 16)
instead of #0F0F0F
or
Length.valueOf(16, LengthUnit.CENTIMETERS)
rather than 16cm

Although this is the unique value proposition of Visage... we can add
to the language to make things simpler and more elegant than you can do
purely with Java APIs.

Here is a link to the right folder in the source tree to get you started:
http://code.google.com/p/visage/source/browse/#hg%2Fsrc%2Fshare%2Fclasses%2Fjavafx%2Flang

Cheers,
--Steve

Reply all
Reply to author
Forward
0 new messages