Compose.jl icon indicating copy to clipboard operation
Compose.jl copied to clipboard

Composing with an array of forms

Open Keno opened this issue 9 years ago • 3 comments

It seems that the following was intended to work:

u = 16
lines = [line([(0.5,0.6),((1+(i-1)/sqrt(u))*0.5w,0.7w)]) for i=1:sqrt(u)]
compose(context(),lines,linewidth(0.1mm),stroke("black"))

It fails with:

`compose` has no method matching compose(::Form{LinePrimitive}, ::Form{LinePrimitive}, ::Form{LinePrimitive}, ::Form{LinePrimitive})
while loading In[43], in expression starting on line 1

 in compose at /Users/kfischer/.julia/Compose/src/container.jl:253

The following works though:

compose(context(),lines...,linewidth(0.1mm),stroke("black"))

Keno avatar Sep 06 '14 18:09 Keno

This is pretty much by design. Since compose will interpret its arguments as a sort of S-expression, here it will try to make the first object in the array an internal and the rest it's children, but forms like Lines are always leaves in the tree.

I should have a more descriptive error than "no matching method" though.

dcjones avatar Sep 07 '14 18:09 dcjones

I am baffled here... What does ... mean here and how should it be used correctly? I am having similar problems. I can create circles with vector arguments as the examples, but not lines, and that is quite unconfortable.

kzapfe avatar Jun 25 '15 20:06 kzapfe

The ... is regular Julia syntax. For example f(xs...) is equivalent to f(xs[1], xs[2], xs[3]) if xs has three elements. See http://julia.readthedocs.org/en/latest/manual/functions/#varargs-functions.

There are two ways to draw multiple lines. As multiple line forms...

compose(context(), line([(0,0), (1,1)]), line([(0,1), (1,0)]), stroke("black"))

...or as a single vectorized line form

compose(context(), line([[(0,0), (1,1)], [(0,1), (1,0)]]), stroke("black"))

dcjones avatar Jun 25 '15 20:06 dcjones