[cairo] Qahirah: A High-Level Cairo API Binding For Python 3

Lawrence D'Oliveiro ldo at geek-central.gen.nz
Wed Mar 11 16:09:11 PDT 2015

On Wed, 11 Mar 2015 10:02:28 +0100, Olaf Schmidt wrote:

> Am 11.03.2015 um 08:33 schrieb Lawrence D'Oliveiro:
>> I see a number of limitations. You hard code the size of the
>> pattern, rather than deriving it from the size of the design
>> elements.
> As I see it, the temp-surfaces you create (to render your Wing-Shape-
> Patterns on) are roughly the same size finally (87x150).

So your version ends up full of hard-coded numbers. Which you had to
get from the formulas in my version!

Besides, I think my version has fewer statements than yours. Remember

        .set_matrix(Matrix.scale(pattern_res) * Matrix.translate(- path_bounds.topleft))
        # need enough copies to cover neighbouring spots under all possible pattern parameters
        .append_path(shape.transform(Matrix.translate(tips[2] - tips[1])))
        .append_path(shape.transform(Matrix.translate(tips[0] - tips[1])))
        .append_path(shape.transform(Matrix.translate((+ pattern_dimensions.x, 0))))
        .append_path(shape.transform(Matrix.translate((- pattern_dimensions.x, 0))))
        .append_path(shape.transform(Matrix.translate(tips[1] - tips[2])))
        .append_path(shape.transform(Matrix.translate(tips[1] - tips[0])))

is technically one Python statement.

>> Then I see things like
>>    For j = 0 To 3: For i = 0 To 3 + j
>> So you have to make 22 separate copies of the pattern in order to
>> ensure there are no gaps. A bit excessive, don’t you think?
> I've just played it safe there...

In other words, you are taking a brute-force approach, rather than
trying to understand the maths to get it right.

>> My code is more general than yours.
> But feel free to come up with an example, where my implementation
> would choke (in your opinion).

Just adding more curve instances is easier in my code: you don’t have
to calculate the new layout, since the script will automatically
adjust to new row and column numbers.

>>> - is more near the cairo-base-API (and thus nearly 1:1 portable to
>>> C)
>> Which is something I thought I made clear I was trying to get away
>> from.
> Not sure what you're trying to "get away from", when working near the
> cairo-API causes smaller, easier to understand code (for most of us).

If you don’t accept the goals of Qahirah, why are you bothering with it?

More information about the cairo mailing list