Re: Creating arcs in lua ipelet

Otfried Cheong <[email protected]>
Newsgroups gmane.comp.graphics.ipe.general
Organization Ipe Headquarters
Message-ID <[email protected]>
On 10/26/2010 10:25 PM, [cristo] wrote:
> I am trying to create an ipe.Arc in a lua ipelet using the following code:
>
> arc_shape = {}
>
> table.insert(arc_shape, { type="curve", closed=false })
> table.insert(arc_shape, { type="arc", arc=ipe.Arc(m, points[j],
> points[i]) })
> table.insert(arcs, ipe.Path(model.attributes, arc_shape))
> [...]
>
> The line mentioned in the error is in which ipe.Path is created. Does
> anyone can see where am I wrong?

Quite a few things, actually.  Note that in Lua, tables contain elements 
indexed by integers 1,2,3,... and elements indexed by a key (like 
"type", "closed", "arc") at the same time.

The following is a working example:

m = ipe.Matrix()
p = ipe.Vector(0,1)
q = ipe.Vector(1,0)

arc = { type="arc", arc=ipe.Arc(m, p, q), p, q }
subpath = { type="curve", closed=false, arc }
shape = { subpath }
path = ipe.Path({}, shape)

Observe that "shape" is a table that contains one element (because there 
is only one subpath).  This subpath is a table that has two elements 
with keys, and one element at index 1 (namely the arc).
The arc has two elements with keys "type" and "arc", but must also have 
the two endpoints as elements at index 1 and index 2.

Cheers,
  Otfried
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.