[cairo] Specifying Angles

Lawrence D'Oliveiro ldo at geek-central.gen.nz
Wed Mar 25 13:15:58 PDT 2015

First of all, there is no question radians are the right unit to use
for angle calculations. However, they are not the most convenient unit
for users to specify and examine angles. (How much of an angle is

Because my Cairo binding is in Python, you can use the standard Python
math.degrees and math.radians conversion functions. But I decided this
wasn’t convenient enough. So I also provide a couple of constants,
“deg” and “circle”. Multiplying a number of degrees by “deg” converts
it to radians (and dividing converts the other way), while multiplying
and dividing by “circle” similarly converts to/from units of a whole
circle (2π radians).

Thus, the following angle specifications are all equivalent:

    math.pi / 2
    90 * deg
    circle / 4

And converting an angle to degrees or circles can also be easily done:

    >>> Vector(0, 1).angle()
    >>> Vector(0, 1).angle() / deg
    >>> Vector(0, 1).angle() / circle

More information about the cairo mailing list